stm8的bootloader

来源:互联网 发布:sql删除重复的数据 编辑:程序博客网 时间:2024/06/10 19:43

Stm8的bootloader介绍

本次应用笔记是专门为STM8的固件和系统设计者提供,他们需要实现一个内应用编程(In-application programming, IPA)特征的产品,以stm8微处理器作为研发的。Stm8是一个8位微控制器家族,并以一个flash memory 去存储用户的程序代码或者固件。(for storing the user program codeor firmware.)在为控制其被移植到最终产品上后,IAP 使得控制器可以就地更新固件。这么更新固件的有优点是微控制器能一直保持在产品里面,不用取出芯片特意给它烧录程序。更新固件的时候也不用调停机器(产品)的运行工作。(在线烧录,通过IIC,SPI,uart)。

IAP是对发布新固件版本非常有用的。在产品生命周期内,它很容易去增加产品的新功能特征和维护产品的问题故障解决。

使用user-boootloader firmware 源码提供了一个实现IAP适用于STM8例子。使用这源码作为一个实现在你的stm8的应用程序的IAP参考。Bootloader主要包含以下几个特征:

Bootloader 被一个外部脚激活(jumper on PCB)。

Flash block(flash 块编程)programming 通过执行ram代码管理。

读写特性(RWW)

高级c语言水平使用

减少代码的大小(优化代码)

支持多种通信方式接口(SPI,IIC,uart)

串口代码与st flash 加载的证明的软件相兼容

1.操作原理        

在实际中,IAP要求bootloader是实现stm8固件能和外部的主机端(如PC)通过一种合适的通信接口相互通信。一个新的代码可以通过该方式被下载到微控制器。然后微控制器编程这个代码到它的flash memory。

当一个微控制器已经焊接到它的最终产品上和需要去升级其固件的时候,这种操作是很有用的。

 

Bootloader是代码的一部分,在微控制器复位后,它马上执行和等待一个激活信号。如果激活则进入bootloader 模式;如果激活失败(超时没激活,或者 jumper on the pin 不存在),bootloader则直接跳转到用户应用程序代码地址执行应用程序。

Bootloader模式,微控制器和外部主机通信通过一个串行通信接口(uart,spi,IIC,can)使用

一些命令集。

Write to flash

Erase flash

Verify flash

Additionaloperations such as read memory and execute code from a given address

(jump to givenaddress).

2.STM8的built-rom-bootloader例子

以stm8s208xxbootloader为例(UM0560: STM8 bootloader)。

Thebuilt-in ROM-bootloader is located in a dedicated part of the memory called theBootROM. The ROM-bootloader code is fixed (not rewritable) and is specific foreach device. The communication interface supported depends on the peripheralspresent in the given STM8 device and whether they are implemented in theROM-bootloader. For example, some devices support firmware download throughUART/LIN and CAN, some devices support only UART, and others only SPI.Information concerning the supported interfaces can be found in the relevantdevice datasheet.

Activationof the built-in ROM-bootloader is made by programming the BL[7:0] option bytedescribed in the option byte section of the device datasheet. The bootROMbootloader 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 isinactive, the bootrom bootloader jumps to the user reset address (0x8000).

 

In the case of bootloaderactivation, the chosen communication interface is initialized. A timeout countis then activated (i.e. 1 second). If, during this timeout, nothing is receivedfrom the given communication interface (UART, SPI, I2C) the bootloader jumps to the userapplication reset address.

If the user-bootloader receive avalid activating token byte from the communication interface before the timeoutelapses, it then enters memory management mode to perform the followingoperations:

1.Initialize the Flash programming routines by copyingthe programming functions to RAM.

2. Wait in a loop for a valid command to be received fromthe master

3. Compute the received command (read, write, erase,version)

4. If a Go command is received, the user-bootloader jumpsto the address given in the command.

All commands have a specified format and must be followedby both the user-bootloader and the master. The command specification handlesall possibilities and covers error management.

 

以上由于时间比叫紧,就没有直接翻译过来了,不过基本意思都很简单。下面我将上传一下其英文版的资料和bootloader案例的源码。链接如下:

http://download.csdn.net/download/lidefu1000810218/10047929


原创粉丝点击