ST AN2792 Application note

AN2792

Application note

STM8A easy programmer

1 Introduction

This application note describes the easy programmer which is a low cost solution allowing the content of the STM8A Flash program memory to be updated when the chip is already soldered on the application board. The easy programmer works by calling the functions of the bootloader, an IAP application embedded in the system memory of the device (the ROM memory). Through the bootloader firmware, the device memory can be erased and programmed using one of the standard communication interfaces present on the particular device. The easy programmer interfaces the bootloader using a serial port (USART protocol) with the application board for the upload.

Section 2 of this document gives a brief introduction to the STM8A bootloader. Section 3, Section 4, and Section 5 describe the easy programmer procedure and its software and hardware requirements.

For further information on the STM8A family features, pinout, electrical characteristics, mechanical data and ordering information, please refer to the STM8A128 Kbyte and STM8A 32 Kbyte datasheets. For more details on the bootloader, please refer to the bootloader user manual (UM0500). All documents are available on st.com.

This document, its associated firmware, and other such application notes are written to accompany the STM8S firmware library which is available on st.com.

November 2008

Rev 1

1/12

www.st.com

Contents

AN2792

 

 

Contents

1

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 1

2

Bootloader description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 3

 

2.1

Bootloader flowchart description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

 

2.2

Peripheral settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

3

Transferring the .s19 file to the easy programmer . . . . . . . . . . . . . . . . .

7

4

Transfering the .s19 file to the STM8A application board . . . . . . . . . . .

8

5

Software and hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

 

5.1

Batch file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

 

5.2

Application software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

 

5.3

Easy programmer board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

 

5.4

Application hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

6

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

2/12

AN2792

Bootloader description

 

 

2 Bootloader description

The bootloader code is stored in the internal boot ROM memory. Its main task is to download the application program into the internal memories through the USART, LINUART, SPI, or CAN peripherals.

The main features of the bootloader are:

Polling the serial interface (USART and LINUART are both configured as a normal UART, SPI or CAN) to check which peripheral is used

Programming code, data, option bytes and/or the vector table at the address(es) received from the host.

The STM8A reset vector is located at the beginning of the boot ROM (6000h), while the other vectors are in the Flash program memory starting at address 8004h.

The device jumps inside the boot ROM area and after checking certain address locations (see Table 1: Initial checking on page 6), it jumps to the reset vector in the Flash program memory (8000h).

2.1Bootloader flowchart description

The bootloader activation flowchart is shown in Figure 1 on page 4. The basic steps are described below.

3/12

ST AN2792 Application note

Bootloader description

AN2792

 

 

Figure 1. Bootloader activation flowchart

ROM reset (6000h)

1

Disable all interrupt sources

 

 

2

 

3rd condition verified

Checks according

to

1st condition verified

 

 

 

Table 1

 

 

2nd condition verified

 

 

Yes (memory read out protected)

 

 

3

 

 

 

Is ROP active?

 

 

No (memory not read out protected)

Yes

 

 

4

No

Is an external clock present?

 

 

 

 

4

Initializes CAN at

125 kbps

Configure HSI and initialize RX-LINUART pin (PD6) and

RX-USART pin (PDA) in GPIO mofe (pull-up state). 5

Configure SPI in slave mode

 

 

 

6

 

 

 

 

Received a byte/message! = SYNCHR

Wait for SYNCHR

Timeout (1 s)

 

 

6

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SYNCHR

SYNCHR received

 

 

7

 

 

 

 

 

 

failed

Send ACK byte and disable unused

 

 

 

 

6

 

 

peripherals. Execute RASS KEYs

 

 

 

 

Is Flash virgin?

Yes

 

 

 

 

 

 

 

 

8

 

No

6

 

 

Wait for a command

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Recover the registers

 

 

 

 

reset status

 

 

 

Command received

 

 

 

GET cmd

RM cmd

EM cmd

WM cmd

SD cmd

 

GO cmd

GET cmd

RM cmd

EM cmd

WM cmd

SD cmd

GO cmd

routine

routine

routine

routine

routine

routine

Remove EM and WM routines from the RAM

Flash reset (8000h)

Jump to host address

ai15000b

1.See flowchart description below for explanation of points 1 to 8.

2.Dotted routines are loaded in RAM by the host. They are removed by the go command before jumping to the Flash program memory to execute an application.

4/12

Loading...
+ 8 hidden pages