This application note is intended for STM8 firmware and system designers who need to
implement an in-application programming (IAP) feature in the product they are developing
with the STM8 microcontroller.
The STM8 is an 8-bit microcontroller family with a Flash memory for storing the user
program code or firmware. IAP makes it possible to update the firmware ‘in situ’, after the
microcontroller has been embedded in the final product. The advantage is that the
microcontroller board can stay inside its product enclosure. No mechanical intervention is
needed to make the update.
IAP is extremely useful for distributing new firmware versions. It makes it easy to add new
product features and correct problems throughout the product life cycle.
The user-bootloader firmware source code provided with this application note shows an
example of how to implement IAP for the STM8 microcontroller. Use this code as a
reference when integrating IAP in your STM8 application.
●Bootloader activated by external pin (jumper on PCB)
●Flash block programing by executable RAM code management
●Read while write (RWW) feature
●High level C-language usage
●Reduced size of the code (optimized code)
●Support for multiple communication interfaces (SPI , I
●UART code compatible with ST Flash loader demonstrator software
In practice, IAP requires a bootloader implemented in the STM8 firmware that can
communicate with an external master (such as a PC) via a suitable communication
interface. The new code can be downloaded into the microcontroller through this interface.
The microcontroller then programs this code into its Flash memory.
IAP can also be used to update the content of the internal data EEPROM memory, and the
internal RAM memory.
This operation is usefull when a microcontroler is already soldered in its final application and
needs a firmware update.
Figure 1 shows a typical bootloader application.
Figure 1.Typical bootloader application
The bootloader is that part of the code which runs immediately after a microcontroller reset
and which waits for an activation signal (for example, from grounding a specific pin or
receiving a token from a communication interface). If activation is successful the code enters
bootloader mode. If activation fails (for example due to a timeout or the jumper on the pin not
being present) the bootloader jumps directly to the user application code.
In bootloader mode, the microcontroller communicates with the external master device
through one of the serial communication interfaces available in it(UART, SPI, I
2
C, CAN)
using a set of commands. These commands are usually:
●Write to Flash
●Erase Flash
●Verif y Flash
●Additional operations such as read memory and execute code from a given address
(jump to given address).
The ST proprietary bootloader can be used. It is embedded in the ROM memory of STM8
devices with a program memory greater than 8 Kbytes. In this case, no code development is
needed. To use the proprietary bootloader, enable it via the option bytes.
Alternatively, develop a customized bootloader using, for example, a serial communication
interface that is not supported in ST versions or in devices where the ST bootloader is not
present. Such a bootloader should be stored in the user boot code area (UBC) in the
microcontroller. This guarantees protection against unintentional write operations.
Doc ID 14153 Rev 25/25
STM8 devices with built-in ROM-bootloaderAN2659
X
X&&
X
"OOT2/-
&LASHPROGRAMMEMORY
X&&&
AI
2 STM8 devices with built-in ROM-bootloader
Most STM8 devices have an internal bootROM memory which contains an ST proprietary
bootloader. Consequently, they already have a built in IAP implementation (see UM0560:
STM8 bootloader).
2.1 Implementation details
The built-in ROM-bootloader is located in a dedicated part of the memory called the
BootROM. The ROM-bootloader code is fixed (not rewritable) and is specific for each
device. The communication interface supported depends on the peripherals present in the
given STM8 device and whether they are implemented in the ROM-bootloader. For example,
some devices support firmware download through UART/LIN and CAN, some devices
support only UART, and others only SPI. Information concerning the supported interfaces
can be found in the relevant device datasheet.
Activation of the built-in ROM-bootloader is made by programming the BL[7:0] option byte
described in the option byte section of the device datasheet. The bootROM bootloader
checks this option byte and if it is enabled, it runs its own code (it waits for the host to send
commands/data). If the BL[7:0] option byte is inactive, the bootrom bootloader jumps to the
user reset address (0x8000).
Figure 2.Example of STM8S208xx bootloader
6/25Doc ID 14153 Rev 2
AN2659STM8 devices with built-in ROM-bootloader
2.2 Adapting IAP master side to ROM-bootloader protocol
To be able to download firmware into the device, the host and bootloader must communicate
through the same protocol. This bootloader protocol for STM8 devices is specified in the
STM8 bootloader (UM0560) user manuals available from http://www.st.com. The same
protocol is used in the firmware example provided with this application note. The UM0560
user manual describes all bootloader protocol properties including used interfaces,
timeouts, command formats, packet formats, and error management.
Doc ID 14153 Rev 27/25
User-bootloader for STM8 devicesAN2659
)NTERRUPTVECTORTABLE
5SERBOOTLOADER
5"#PROTECTEDAREA
X
X
X
AI
3 User-bootloader for STM8 devices
For STM8 microcontrollers which do not include a built-in bootloader or whichuse a
communication protocol (I
2
C) not yet supported in the built-in bootloader, user-bootloader
firmware can be added and customized at the beginning of the Flash memory.
Figure 3.
Example of user-bootloader implementation in the Flash memory
For this purpose, an example of a user-bootloader firmware is provided with this application
note. This package is divided into three main subdirectories, each one dedicated to one
STM8 family member (STM8A, STM8L, and STM8S). Each directory is composed of the
following components:
●Sources: containing the firmware source code
●Includes: containing the firmware header file (main.h). This file can be edited to
configure your user-bootloader (see Section 3.2: Configuring the user-bootloader
firmware example).
●Flash_loader_demonstrator_files: contain all map files to add in the Flashloader
demonstrator install directory to be compatible with the user-bootloader.
●STVD: containing a prebuilt project for STVD using a Cosmic or raisonance compiler
Figure 4 shows an example of the the user-bootloader firmware.
8/25Doc ID 14153 Rev 2
Loading...
+ 17 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.