CD00171488_UM0462_STM32AndSTM8FlashLoaderDemonstrator

合集下载

STM8S 和 STM32 MCU 一致的 8-32 位产品线实现轻松移植

STM8S 和 STM32 MCU 一致的 8-32 位产品线实现轻松移植

3.1 复位 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 时钟 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
● 寄存器大小:8 位与 16 或 32 位
图 1 给出了数字外设的简化表示。
图 1.
数字外设的内部结构
ഄഔ੠᭄᥂ᘏ㒓 $0%$670
ᘏ㒓᥹ষ ੠ᆘᄬ఼
,3‫ݙ‬Ḍ
,2
DL
外设可分成两个主要部分。首先,内核包含状态机、计数器以及任意种类的组合逻辑或顺序 逻辑,它们是执行不需要处理器的任务(如低级通信层、模拟后端管理或时序驱动的功能) 时所必需的。如有必要,可通过 MCU 端口将内核与外界连接。外部连接可能包含一些 I/O 或复杂总线。其次,应用程序通过与内部总线连接的寄存器来初始化和控制外设,该内部总 线与其它 MCU 资源共用。在 8 位微控制器中,处理器直接写入和读取寄存器,而在 32 位 产品中,寄存器读写操作通常通过总线桥来完成。然而,两个系列的主要区别在于外设必须 遵循的内部总线规范。这解释了 STM8S 和 STM32 器件能够共用外设的原因:它们基于相 同的内核,而且仅针对两种不同的总线接口定制。ARM 处理器和外设符合 AMBA 总线规 范,采用 32 位数据总线,而 STM8S 器件使用更为简单但有效的 8 位总线标准。从功能角 度看,它们仅在以下方面存在差异:
2

STM32选型手册-

STM32选型手册-

4(16/16/16) 1(4/4/6) 2 2 1 3+2 OTG 2 ● 1
2/(16) 1(2) 51 LQFP64
STM32F105RC 72 256K 64K
4(16/16/16) 1(4/4/6) 2 3 2 3+2 OTG 2
2
2/(16) 1(2) 51 LQFP64
STM32F107RC 72 256K 64K STM32F105V8 72 64K 20K
11211 22311
2/(10) 2/(10)
37 LQFP48 37 LQFP48
STM32F103CB 72 128K 20K
3(12/12/12) 1(4/4/6)
22311
2/(10)
37 LQFP48
STM32F103R4 72 16K 6K
2(8/8/8) 1(4/4/6)
11211
2/(16)
STM32F103RD 72 384K 64K
4(16/16/16) 2(8/8/12) 2 3 2 3+2 1 1
2 1 3/(16) 1(2) 51 LQFP64/WLCSP64
STM32F103RE 72 512K 64K
4(16/16/16) 2(8/8/12) 2 3 2 3+2 1 1
2 1 3/(16) 1(2) 51 LQFP64/WLCSP64
2/(10)
26 VFQFPN36
STM32F103C4 72 16K 6K
2(8/8/8) 1(4/4/6)
11211
2/(10)
37 LQFP48
48脚
STM32F103C6 STM32F103C8
72 72

STM8和STM32嵌入式软件解决方案

STM8和STM32嵌入式软件解决方案

F4
Y Y Y Y Y Y Y Y Y Y Y Y
L1 W
Y Y Y Y Y N Y Y Y Y Y Y N N N N N N N N N N N N
1/ eCos is an open source kernel, a subset of eCosPro. eCosPro comes with TCP/IP stack, FAT, jFFS2, RAM and ROM FS 2/ uCLinux is open source, but this company proposes some ports on STM32. It requires some additional boards that they sell. uCLinux can be much more than just a Kernel
9
• Compliant with standards
• ANSI-C source code • Misra and ST coding rules • ARM-CMSIS compliant for STM32
• A real help for developers
• Comes with a multitude of examples demonstrating usage
STM8 – Hardware dependent layer
Provider
ST ST
8
Solution name
Class B guidelines Standard peripheral library
Model
Source Source
Cost
Free Free
Availability S

STM8开发板原理图

STM8开发板原理图

D1 LED1
D2 LED2
按键3
C14 GND 104
第四版原理图
PC3 OSI J1 4 3 2 1 VDD SWIM GND RST C2 22 16M Y1 GND C3 22 OSO
PC4
PD2
B
仿真器接口
SWIM
HSE
LED
KEY
FLASH
B
J2 VDD R1 1032 NRST J4 C4 104 GND VDD S4 3 2 1 CON3 5VIN
PD7/TLI/T1_C4 PD6/UART1_RX PD5/UART1_TX PD4/BEEP/T2_C1 PD3/T2_C2/ADC_ETR PD2/T2_C3 PD1/SWIM PD0/_T1_BKIN PC7/SPI_MISO PC6/SPI_MOSI PC5/SPI_SCK PC4/T1_C4/CCO PC3/T1_C3 PC2/T1_C2 PC1/T1_C1/UART1_CK PE5/SPI_NSS
跳线
C10 104 GND
MINIUSB接口 XI Y2 XO
电源选择跳线
蜂鸣器
LS1
VDD
R3 103
多用途液晶接口
光敏电阻
Q1 PNP
OLED直接插/段码液晶电路板上靠右侧插
GND Title
D
双跳线
USB转TTL
1 2 3
蜂鸣器
4
ADC
5
B Date: File:
32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17
PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0 PC7 PC6 PC5 PC4 PC3 PC2 PC1 PE5

STM8和STM32产品选型手册

STM8和STM32产品选型手册

Content1STM32 – 32-bit microcontroller families (3)STM32 F0 series - ARM Cortex™-M0 Entry-level MCUs (3)STM32 F1 series - ARM Cortex™-M3 Mainstream MCUs (12)STM32 F2 series - ARM Cortex™-M3 High-performance MCUs (17)STM32 F3 series - ARM Cortex™-M4 Mixed-signal MCUswith DSP and FPU (5)STM32 F4 series - ARM Cortex™-M4 High-performance MCUswith DSP and FPU (7)STM32 L1 series - ARM Cortex™-M3 Ultra-low-power MCUs (20)STM32W series - ARM Cortex™-M3 Wireless MCUs (23)STM8 – 8-bit microcontroller families (24)STM8S series – Mainstream MCUs (24)STM8AF series – Mainstream Automotive MCUs (27)STM8AL series – Ultra-low-power Automotive MCUs (29)STM8L series – Ultra-low-power MCUs (30)2STM32 – 32-bit microcontroller families STM32 F0 SERIES - ARM CORTEX™-M0 ENTRY-LEVEL MCUS3STM32 F0 SERIES - ARM CORTEX™-M0 ENTRY-LEVEL MCUSNote:* Available in mass market Week03/201445- Supply voltage 2.0 to 3.6 V for all devices or 1.8 V +/-8% dedicated sales type - WLCSP66 package available in 1.8 V +/-8% dedicated sales type only67891. HS requires an external PHY connected to ULPI interface2. Crypto/hash processor on STM32F417, STM32F415, STM32F437, STM32F4393. Marked in the table (3+2) means 3 USART and 2 UART. All UARTs have LIN master/slave function. All USARTs have IrDA, ISO 7816, modem control and LIN master/slave functions.4. 1.7 V requires external reset circuitry and the device operates in the 0 to 70 °C temperature range1. Marked in the table (3+2) means 3 USART and 2 UART. All UARTs have LIN master/slave function. All USARTs have IrDA, ISO 7816, modem control and LIN master/slave functions.1. HS requires an external PHY connected to ULPI interface2. Crypto/hash processor on STM32F217 and STM32F2153. Marked in the table (3+2) means 3 USART and 2 UART. All UARTs have LIN master/slave function. All USARTs have IrDA, ISO 7816, modem control and LIN master/slave functions.‑ Touch‑sensing FW library available for all STM32L15x and STM32L16x devices ‑ Operating temperature is ‑ 40 to +85 °C for all STM32L1 devicesSTM32W SERIES - ARM CORTEX™-M3 WIRELESS MCUS1. On demand onlySTM8AL SERIES – ULTRA-LOW-POWER AUTOMOTIVE MCUS‑ All STM8AL part numbers have DMA with 4 channels except STM8AL301. Up to 2 Kbytes of EEPROMADC :Analog-to-digital converter ART :Auto-reload timerATAPI :AT attachment packet interface AWU :Auto wake-up from haltBLPD :Byte level protocol decoder BOD :Brown-out detectorCAN :Controller area networkCAPCOM :Capture compareCSS :Clock security systemDALI :Digital addressable lighting interface DDC :Data display channelDiSEqC :Digital satellite equipment control DMA :Direct memory accessDSC :Dual supply controlDTC :Data transfer coprocessor ETM :Embedded trace macrocell EMI :External memory interface HDLC :High-level data link control IAP :In-application programming IC/OC :Input capture/output compare ICP :programmingIR :InfraredIrDA :Infrared data associationISP :In-situ programmingI²C :Inter-integrated circuitAbbreviations and packages LCD :Liquid crystal display LIN :Local interconnect network LVD :Low voltage detection MAC :Multiply accumulator MC :Motor control MFT :Multifunction timer MMC :MultiMediaCard NMI :Non-maskable interrupt OSG :Oscillator safeguard PCA :Programmable counter array PDR :Power-down reset PHW :Programmable halt wake-up PEC :Peripheral event controller PLD :Programmable logic device PLL :Phase locked loop POR :Power-on reset PVD :Programmable voltage detector PVR :Programmable voltage regulator PWM :Pulse width modulation ROP :Readout protection RTC :Real-time clock timer SC :Smartcard SCI :Serial communication interface SCR :Smartcard reader SDIO :Secure digital input output ABBREVIATIONSPACKAGES DIP :Dual in-line package LCC :Leaded chip carrier PDIP Shrink :Shrink Plastic Dual In-line Package PQFP :SO :Small outline LQFP :PBGA :Plastic ball grid array DFN :QFN :SPI :Serial peripheral interface SSC :Single-cycle switching support SSP :Synchronous serial port TBU :Time base unit TLI :Top level interrupt UART :Universal asynchronous receiver transmitter USART :Universal sync/async receiver transmitter USB :Universal Serial Bus WDG :Watchdog timer WWDG :Window watchdog timer© STMicroelectronics - November 2013 - Printed in China - All rights reserved。

STM32_STM8CAN波特率设置计算器

STM32_STM8CAN波特率设置计算器

STM32_STM8CAN波特率设置计算器CAN总线的波特率是由总线速度和传输协议决定的。

对于STM32和STM8微控制器,可以使用以下公式来计算CAN总线的波特率:BS1 = (tbs1 - 1) (tbs1的范围为[1,16])BS2 = (tbs2 - 1) (tbs2的范围为[1,8])时间量化器单位时间为(1 + tbs1 + tbs2)个时间单元以下是一个使用Python编写的STM32和STM8 CAN波特率设置计算器的示例代码:```pythonimport mathBS1 = tbs1 - 1BS2 = tbs2 - 1quanta_per_bit = tbs1 + tbs2 + tbs3 + 1BRP=BRP-1while BRP > 0x3FF:quanta_per_bit *= 2BRP/=2return (int(BRP), quanta_per_bit, BS1, BS2)tbs1 = 9tbs2 = 4tbs3 = 4print("BRP:", result[0])print("Quanta per bit:", result[1])print("BS1:", result[2])print("BS2:", result[3])```在这个示例中,假设APB1时钟频率为36MHz,每个位时间为125个时钟周期,同步段为9个时间单元,时间段1为4个时间单元,时间段2为4个时间单元,CAN控制器的时钟频率为36MHz。

运行这个示例代码,将会得到以下的输出:BRP:11Quanta per bit: 20BS1:8BS2:3输出结果表示波特率分频器的分频系数BRP为11,每个位时间的时钟周期数为20个时钟周期,同步段时间为9个时间单元,时间段1时间为8个时间单元,时间段2时间为3个时间单元。

STM8 FLASH编程手册

STM8 FLASH编程手册

June 2011Doc ID 14614 Rev 31/27PM0051Programming manualHow to program STM8S and STM8A Flash program memory and data EEPROMIntroductionThis manual describes how to program Flash program memory and data EEPROM onSTM8 microcontrollers. It applies to access and performance line STM8S and medium and high density STM8A devices. It is intended to provide information to the programming tool manufacturers and to the customers who want to implement programming by themselves on their production line.The in-circuit programming (ICP) method is used to update the content of Flash program memory and data EEPROM while the user software is not running. It uses the Single wire interface module (SWIM) to communicate between the programming tool and the device.In contrast to the ICP method, in-application programming (IAP) can use anycommunication interface supported by the microcontroller (I/Os, SPI, USART , I 2C, USB, CAN...). IAP has been implemented for users who want their application software to update itself by re-programming the Flash program memory during program execution. The main advantage of IAP is its ability to re-program Flash program memory and data EEPROM when the chip has already been soldered on the application board and while the usersoftware is running. Nevertheless, part of the Flash program memory has to be previously programmed using ICP .Some devices also contain a bootloader embedded in a ROM memory. Through this firmware the device memory can be re-programmed using a standard communication interface. This programming method is not described in this document.For details on memory implementation and features, registers or stack top addresses, refer to the product datasheets.Related documents●STM8 SWIM communication protocol and debug module (UM0470)●STM8 bootloader user manual (UM0560)l●STM8S and STM8A microcontroller families reference manual (RM0016)●Basic in-application programming example using the STM8 I 2C and SPI peripherals (AN2737)●STM8 in-application programming example (AN2659)●Performance line datasheet (high density Flash program and data EEPROM)●Access line datasheets (low and medium density Flash program and data EEPROM)●STM8A datasheets (up to 32 Kbytes and up to 128Kbytes of Flash program memory)Contents PM0051Contents1Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.1Low density STM8S microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2Medium density STM8S microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3High density STM8S microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.4Medium density STM8A microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . 102.5High density STM8A microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Memory protection strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.1Readout protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.2User Boot Code area protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.3Unwanted memory access protection . . . . . . . . . . . . . . . . . . . . . . . . . . . 154Programming STM8 Flash microcontrollers . . . . . . . . . . . . . . . . . . . . . 164.1Unlocking the Memory Access Security System (MASS) . . . . . . . . . . . . 164.2Block programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.3Word programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.4Byte programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.5Programming the option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.5.1Summary of memory dedicated option bytes . . . . . . . . . . . . . . . . . . . . 224.5.2How to program the option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.6Memory access versus programming method . . . . . . . . . . . . . . . . . . . . . 234.6.1ICP methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.6.2IAP method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5Flash program memory and data EEPROM comparison . . . . . . . . . . . 25 6Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262/27Doc ID 14614 Rev 3PM0051List of tables List of tablesTable 1.Low density STM8S memory partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Table 2.Medium density STM8S memory partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Table 3.High density STM8S memory partition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Table 4.Medium density STM8A memory partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Table 5.High density STM8A memory partition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Table 6.Recommended minimum and maximum sizes of the UBC area . . . . . . . . . . . . . . . . . . . . 15 Table 7.MASS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 8.Memory access versus programming method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Table parison between STM8S and STM8A devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Table 10.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Doc ID 14614 Rev 33/27Glossary PM0051 1 GlossaryThis section gives a brief definition of acronyms and terms used in this document:●BlockA block is a set of bytes that can be programmed or erased in one single programmingoperation. Operations that are available on a block are fast programming, erase only,and standard programming (which includes an erase operation). Refer to Section2:Memory organization for details on block size according to the device.●BootloaderThe bootloader is an IAP application embedded in the system memory of the device. Itis used to erase and program the device using a standard serial communication port.The bootloader is not available on small devices, and is not described in the presentdocument. Refer to STM8 bootloader user manual (UM0500) for more details.●DriverA driver is a control program defined by the application developer. It is used to managethe allocation of system resources to start application programs. In this document twodrivers are described, ICP and IAP drivers.●In-application programming (IAP)IAP is the ability to re-program the Flash program memory and data EEPROM (DAT A)of a microcontroller while the device is already plugged-in to the application and theapplication is running.●In-circuit programming (ICP)ICP is the ability to program the Flash program memory and data EEPROM of amicrocontroller using the SWIM protocol while the device is plugged-in to theapplication.●In-circuit debugging (ICD)ICD is the ability to debug the user software using the SWIM protocol. The user has theability to connect the device to a debugger and insert breakpoints in his firmware.Debugging may be intrusive (application patched to allow debugging) or non intrusive(using a debug module).●Memory access security system (MASS) keysThe Memory access security system (MASS) consists of a memory write protectionlock designed to prevent unwanted memory modifications due to EMS or programcounter loss. To unlock the memory protection, one or more keys must be written in adedicated register and in a specific order. When the operation (write or erase) iscompleted, the MASS must be activated again to provide good memory security.4/27 Doc ID 14614 Rev 3PM0051Glossary●PageA page is a set of blocks. The number of blocks in a page may differ from one device toanother. Refer to Section2: Memory organization for details on page size according tothe device.A dedicated option byte can be used to configure by increments of one page the size ofthe user boot code. Refer to Section5: Flash program memory and data EEPROMcomparison for a description of available areas and option bytes according to thedevices.●Read-while-write (RWW)The RWW feature provides the ability for the software to perform write operation ondata EEPROM while reading and executing the program memory. Execution time istherefore optimized. The opposite operation is not allowed: the software cannot readdata memory while writing program memory.The RWW feature is not available on all STM8 devices. Refer to Table9 for informationon devices with RWW capability.●Single wire interface module (SWIM)The SWIM is a communication protocol managed by hardware in the STM8microcontrollers. The SWIM main purpose is to provide non intrusive debug capability.It can also be used to download programs into RAM and execute them. It can also write(registers or RAM) or read any part of the memory space and jump to any memoryaddress. The SWIM protocol is used for ICP. It is accessed by providing a specificsequence on the SWIM pin either during the reset phase or when the device is running(if allowed by the application).●System memoryThe STM8 system memory is a small ROM accessible when the user software isexecuted. It contains the bootloader. The system ROM and the bootloader are notavailable on all STM8 devices.●User boot code area (UBC)The user boot code area is a write-protected area which contains reset vector, interruptvectors, and IAP routine for the device to be able to recover from interrupted orerroneous IAP programming.●User modeThe user mode is the standard user software running mode in the STM8. It is enteredeither by performing a power-on-reset on the device or by issuing the SWIM SRSTcommand from a development tool.●WordA word is a set of 4 bytes and corresponds to the memory granularity.Doc ID 14614 Rev 35/27Memory organization PM00516/27 Doc ID 14614 Rev 32 Memory organizationThis section describes the memory organization corresponding to:●Access line and performance line STM8S microcontrollers ●Medium and high density STM8A microcontrollersSTM8S microcontrollers offer low density (8Kbytes), medium density (from 16 to32Kbytes) and high density (from 32 to 128Kbytes) Flash program memory, plus data EEPROM.STM8A microcontrollers feature medium density (from 8 to 32Kbytes) and high density (from 32 to 128Kbytes) Flash memory, plus data EEPROM.The memory organization differs from one STM8 family to another. Refer to Section 2.1, Section 2.2, Section 2.3, Section 2.4, and Section 2.3 for a description of the memory organization according to microcontroller family and memory density.A memory accelerator takes advantage of the parallel 4-byte storage, which corresponds to a word. The Flash program memory and data EEPROM can be erased and programmed at byte level, word level or block level. In word programming mode, 4 bytes can beprogrammed/erased during the same cycle, while in block programming mode, a whole block is programmed/erase during the same cycle. Refer to Section 2.1, Section 2.2, Section 2.3, Section 2.4, and Section 2.3 for information on block size according to the devices.2.1 Low density STM8S microcontrollersThe memory array is divided into two areas:●8Kbytes of Flash program memory organized in 128 pages or blocks of 64 bytes each. The Flash program memory is divided into 2 areas, the user boot code area (UBC), which size can be configured by option byte, and the main program memory area. The Flash program memory is mapped in the upper part of the STM8S addressing space and includes the reset and interrupt vectors.●640 bytes of data EEPROM (DATA) organized in 10 pages or blocks of 64bytes each. One block (64bytes) contains the option bytes of which 11 are used to configure the device hardware features. The options bytes can be programmed in user, IAP and ICP/SWIM modes.Refer to T able 1 for a detailed description of the memory partition for low density STM8S microcontrollers.PM0051Memory organizationDoc ID 14614 Rev 37/272.2 Medium density STM8S microcontrollersThe memory is divided into two arrays:●From 16 to 32Kbytes of Flash program memory organized in up to 64 pages of 4blocks of 128 bytes each. The Flash program memory is divided into 2 areas, the user boot code area (UBC), which size can be configured by option byte, and the mainprogram memory area. The Flash program memory is mapped in the upper part of the STM8S addressing space and includes the reset and interrupt vectors.●1Kbytes of data EEPROM (DATA) organized in up to 2 pages of 4 blocks of 128bytes each. One block (128 bytes) contains the option bytes of which 13 are used toconfigure the device hardware features. The options bytes can be programmed in user, IAP and ICP/SWIM modes.Refer to T able 2 for a detailed description of the memory partition for medium density STM8S microcontrollers.Table 1.Low density STM8S memory partitionAreaPage number (1 page=1 block)Block number (1 block=64bytes)Address Data EEPROM000x004000-0x00403F 110x004040-0x00407F 220x004080-0x0040BF (9)90x004240-0x00427F Option bytes -0 (one block only)0x004800-0x00483F Flash program memory000x008000-0x00803F 110x008040-0x00807F 220x008080-0x0080BF (127)1270x009FC0-0x009FFFMemory organization PM00518/27 Doc ID 14614 Rev 3Table 2.Medium density STM8S memory partition (1)AreaPage number (1 page=4 blocks)Block number (1 block=128bytes)Address Data EEPROM 000x004000-0x00407F 10x004080-0x0040FF 20x004100-0x00417F 30x004180-0x0041FF 14-70x004200-0x0043FF Option bytes -0 (one block only)0x004800-0x00487F Flash program memory00x008000-0x00807F 10x008080-0x0080FF 20x008100-0x00817F 30x008180-0x0081FF 14-70x008200-0x0083FF... (63)2520x00FE00-0x00FE7F 2530x00FE80-0x00FEFF 2540x00FF00-0x00FF7F 2550x00FF80-0x00FFFF1.The memory mapping is given for the devices featuring 32Kbytes of Flash program memory.PM0051Memory organizationDoc ID 14614 Rev 39/272.3 High density STM8S microcontrollersThe memory is divided into two arrays:●From 32 to 128Kbytes of Flash program memory organized in up to 256 pages of 4 blocks of 128 bytes each. The Flash program memory is divided into 2 areas, the user boot code area (UBC), which size can be configured by option byte, and the mainprogram memory area. The Flash program memory is mapped in the upper part of the STM8S addressing space and includes the reset and interrupt vectors.●From 1 to 2Kbytes of data EEPROM (DATA) organized in up to 4 pages of 4 blocks of 128bytes each. The size of the DATA area is fixed for a given microcontroller. One block (128bytes) contains the option bytes of which 15 are used to configure the device hardware features. The options bytes can be programmed in user, IAP and ICP/SWIM modes.Refer to T able 3 for a detailed description of the memory partition for high density STM8S microcontrollers.Table 3.High density STM8S memory partition (1)AreaPage number (1 page=4 blocks)Block number (1 block=128bytes)Address Data EEPROM00x004000-0x00407F 10x004080-0x0040FF 20x004100-0x00417F 30x004180-0x0041FF 1 4 to 70x004200-0x0043FF 28 to 110x004400-0x0045FF 312 to 150x004600-0x0047FF Option bytes-0 (one block only)0x004800-0x00487FMemory organization PM005110/27 Doc ID 14614 Rev 32.4 Medium density STM8A microcontrollersThe memory is divided into two arrays:●From 8 to 32Kbytes of Flash program memory organized in up to 64 pages of 4 blocks of 128 bytes each. The Flash program memory is divided into 2 areas, the user boot code area (UBC), which size can be configured by option byte, and the main program memory area. The Flash program memory is mapped in the upper part of the STM8A addressing space and includes the reset and interrupt vectors.●From 384 bytes to 1Kbytes of data EEPROM (DATA) organized in up to 2 pages of 4 blocks of 128bytes each. One block (128 bytes) contains the option bytes of which 13 are used to configure the device hardware features. The options bytes can be programmed in user, IAP and ICP/SWIM modes.Refer to T able 4 for a detailed description of the memory partition for medium density STM8A microcontrollers.Flash program memory00x008000-0x00807F 10x008080-0x0080FF 20x008100-0x00817F 30x008180-0x0081FF 14 to 70x00 8200-0x00 83FF 28 to 110x00 8400-0x00 85FF... (255)10200x00 27E00-0x00 27E7F 10210x00 27E80-0x00 27EFF 10220x00 27F00-0x00 27F7F 10230x00 27F80-0x00 27FFF1.The memory mapping is given for the devices featuring 128Kbytes of Flash program memory and 2Kbytes of dataEEPROM.Table 3.High density STM8S memory partition (1) (continued)AreaPage number (1 page=4 blocks)Block number (1 block=128bytes)AddressPM0051Memory organizationDoc ID 14614 Rev 311/27Table 4.Medium density STM8A memory partition (1)AreaPage number (1 page=4 blocks)Block number (1 block=128bytes)Address Data EEPROM 000x004000-0x00407F 10x004080-0x0040FF 20x004100-0x00417F 30x004180-0x0041FF 14-70x004200-0x0043FF Option bytes -0 (one block only)0x004800-0x00487F Flash program memory00x008000-0x00807F 10x008080-0x0080FF 20x008100-0x00817F 30x008180-0x0081FF 14-70x008200-0x0083FF... (63)2520x00FE00-0x00FE7F 2530x00FE80-0x00FEFF 2540x00FF00-0x00FF7F 2550x00FF80-0x00FFFF1.The memory mapping is given for the devices featuring 32Kbytes of Flash program memory.Memory organization PM005112/27 Doc ID 14614 Rev 32.5 High density STM8A microcontrollersThe memory is divided into two arrays:●From 32 to 128Kbytes of Flash program memory organized in up to 256 pages of 4 blocks of 128 bytes each. The Flash program memory is divided into 2 areas, the user boot code area (UBC), which size can be configured by option byte, and the mainprogram memory area. The Flash program memory is mapped in the upper part of the STM8A addressing space and includes the reset and interrupt vectors.●From 1 to 2Kbytes of data EEPROM (DATA) organized in up to 4 pages of 4 blocks of 128bytes each. The size of the DATA area is fixed for a given microcontroller. One block (128bytes) contains the option bytes of which 15 are used to configure the device hardware features. The options bytes can be programmed in user, IAP and ICP/SWIM modes.Refer to T able 5 for a detailed description of the memory partition for high density STM8A microcontrollers.Table 5.High density STM8A memory partition (1)AreaPage number (1 page=4 blocks)Block number (1 block=128bytes)Address Data EEPROM00x004000-0x00407F 10x004080-0x0040FF 20x004100-0x00417F 30x004180-0x0041FF 1 4 to 70x004200-0x0043FF 28 to 110x004400-0x0045FF 312 to 150x004600-0x0047FF Option bytes-0 (one block only)0x004800-0x00487FPM0051Memory organizationDoc ID 14614 Rev 313/27Flash program memory00x008000-0x00807F 10x008080-0x0080FF 20x008100-0x00817F 30x008180-0x0081FF 14 to 70x00 8200-0x00 83FF 28 to 110x00 8400-0x00 85FF... (255)10200x00 27E00-0x00 27E7F 10210x00 27E80-0x00 27EFF 10220x00 27F00-0x00 27F7F 10230x00 27F80-0x00 27FFF1.The memory mapping is given for the devices featuring 128Kbytes of Flash program memory and 2Kbytes of dataEEPROM.Table 5.High density STM8A memory partition (1) (continued)AreaPage number (1 page=4 blocks)Block number (1 block=128bytes)Address3 Memory protection strategyThe STM8 devices feature several mechanisms allowing to protect the content of the Flashprogram and data EEPROM areas:●Readout protectionThe software can prevent application code and data stored in the Flash programmemory and data EEPROM from being read and modified in ICP/SWIM mode. Thereadout protection is enabled and disabled by programming an option byte inICP/SWIM mode. Refer to Section3.1 for details.●User boot code area (UBC)In order to guaranty the capability to recover from an interrupted or erroneous IAPprogramming, all STM8 devices provide a write-protected area called user boot code(UBC). This area is a part of the Flash program memory which cannot be modified inuser mode (that is protected against modification by the user software). The content ofthe UBC area can be modified only in ICP/SWIM mode after clearing the UBC optionbyte.The size of the user boot code area can be configured through an option byte byincrements of one page.Refer to Section3.2 for details on user boot code area.●Unwanted memory access protectionAll STM8 devices offer unwanted memory access protection, which purpose is toprevent unintentional modification of program memory and data EEPROM (for exampledue to a firmware bug or EMC disturbance).This protection consists of authorizing write access to the memory only through aspecific software sequence which is unlikely to happen randomly or by mistake. Accessto Flash program and data EEPROM areas is enabled by writing MASS keys into keyregisters.Refer to Section3.3 for details on unwanted memory access protection.protection3.1 ReadoutThe readout protection is enabled by writing 0xAA in the ROP option byte. It is disabled byreprogramming the ROP option byte with any value except for 0xAA and resetting thedevice.The readout protection can only be disabled in ICP/SWIM mode.When the readout protection is selected, reading or modifying the Flash program memory inICP mode (using the SWIM interface) is forbidden. When available, the data EEPROMmemory is also protected against read and write access through ICP.Erasing the ROP option byte to disable the readout protection causes the Flash programmemory, the DATA area and the option bytes to be erased.Even though no protection can be considered as totally unbreakable, the readout protectionfeature provides a very high level of protection for general purpose microcontrollers. Ofcourse, a software that allows the user to dump the Flash program memory content makethis readout protection useless. Table8 describes possible accesses to each memory areasversus the different modes and readout protection settings.14/27 Doc ID 14614 Rev 3Doc ID 14614 Rev 315/273.2 User Boot Code area protectionWhatever the memory content, it is always possible to restart an ICP session after a critical error by applying a reset and restarting the SWIM communication.On the contrary, during IAP sessions, the programming software driver must always be write protected to be able to recover from any critical failure that might happen during programming (such as power failure).The pages where the IAP driver is implemented must be located in the write-protected boot code area (UBC). The application reset and interrupt vectors and the reset routine must also be stored in the UBC. These conditions allow the user software to manage the recovery from potential critical failure by applying a reset and restarting the IAP routine from the protected boot area.The UBC size is defined by the user boot code (UBC) area option byte. This option byte may slightly differ from one product to another. See the following table for the minimum and maximum size of the UBC area. Its maximum size is equal to the full memory size3.3 Unwanted memory access protectionThe unwanted memory access protection consists of writing two 8-bit keys in the right order into dedicated MASS key registers.Writing the correct sequence of keys in the program memory MASS key register(FLASH_PUKR) enables the programming of the program memory area excluding the UBC. If wrong keys are provided, a reset must to be generated to be able to reprogram the right keys.Once the write memory protection has been removed, it is possible to reactivate the protection of the area by resetting the PUL bit in FLASH_IAPSR.To enable write access to the data EEPROM area, another specific MASS key register (FLASH_DUKR) and a different key sequence must be used. Once the dataEEPROM/option byte area is unlocked, it is possible to reactivate the protection of the area by resetting the DUL bit in FLASH_IAPSR.If wrong keys have been provided to the FLASH_PUKR register, the device must be reset before performing a new key program sequence. However, when wrong keys are provided to the FLASH_DUKR register, new keys can be entered without the device being previously reset.In order to be as effective as possible, the application software must lock again theunwanted memory access protection as soon as the programming is completed. Otherwise, the protection level of the MASS is significantly reduced. To activate the MASS protection again, the user must reset the corresponding bits in the FLASH_IAPSR register (DUL bit for data EEPROM or PUL bit for Flash program memory).Table 6.Recommended minimum and maximum sizes of the UBC areaSTM8 microcontroller familyRecommended minimum sizeof the UBC areaMaximum size of the UBC areaLow density STM8S2 pages = 128bytes Full memory size Medium density STM8S and STM8A 2 pages = 1KbyteFull memory sizeHigh density STM8S and STM8A16/27 Doc ID 14614 Rev 3Note:1The mechanism to lock and unlock unwanted memory access protection is identical for option bytes and data EEPROM (see Ta ble 7: MASS ).2Before starting programming program memory or data EEPROM, the software must verify that the area is not write protected by checking that the PUL or DUL bit is effectively set.4 Programming STM8 Flash microcontrollersThis section describes how to program STM8 single-voltage Flash microcontrollers.4.1 Unlocking the Memory Access Security System (MASS)The memory must be unlocked before attempting to perform any erase or write operation. To unlock it, follow the procedure described in Section 3.3: Unwanted memory access protection , and Table 7.The software must poll the PUL and DUL bit, before attempting to write to program memory and data EEPROM, respectively.4.2 Block programmingBlock write operations allow to program an entire block in one shot, thus minimizing theprogramming time.There are three possible block programming modes: erase, write only (also called fast programming) and combined erase/write cycle (also called standard block programming).Table 7.MASSMicrocontrollerfamilyData EEPROM and option bytes Program memoryUnlock Lock Unlock Lock STM8S and STM8AWrite 0xAE then56h in FLASH_DUKR (0x00 5064)(1)(2)1.The OPT and NOPT bits of FLASH_CR2 and FLASH_NCR2 registers must be set/cleared to enableaccess to the option bytes.2.If wrong keys have been entered, another key programming sequence can be issued without resetting thedevice.Reset bit 3 (DUL) in FLASH_IAPSR (0x00 505F)Write 0x56 then0xAE in FLASH_PUKR (0x00 5062)(3)3.If wrong keys have been entered, the device must be reset, and a key program sequence issued.Reset bit 1 (PUL) in FLASH_IAPSR (0x00 505F)。

STM32和STM8产品介绍(2008年9月)

STM32和STM8产品介绍(2008年9月)
从2007年10月起,要求新的电器设备符合IEC60335规范 IEC60335, Class B规范涉及的方面:
机械方面,材料方面,电路板设计方面,电子元器件
STM32 全国巡回研讨会
STM32 产品及特性 2008年9月 18
/stm32
IEC60335-1 安全级别分类
在不同安全级别里,MCU的功能是有区别的。 A级
12位分辨率, 精确度达+/- 1.3LSB @ 25° 1微秒完成一次转换 各通道轮流扫描模式,在一个普通的通道上采用快速的交叉模式进行连续 的采样, 注入模式 定时器触发 模拟看门狗功能 DMA 传输数据 自我校准功能
数模转换, 2个转换电路模块
可配置为8位或者12位 or 12bit 单模式输出 可模拟噪声波形,三角波形输出 DMA数据传输 外部触发 双通道独立转换模式,或者作为单通道同时转换模式
6
13
5
12
4
3
11
2
1
10
9
CE-ATA
1
SDIOSDIO_CMD
2 3 4
SDIO_CK
5
6
SDIO_D0
7
SDIO_D1
8 9
SDIO_D2
10
11
SDIO_D3
12
SDIO_D4
13
SDIO_D5
14 15
SDIO_D6
16
17
SDIO_D7
18
STM32 全国巡回研讨会
STM32 产品及特性 2008年9月 15
LQFP100 (14x14mm)
LQFP144 (20x20mm)
STM32 全国巡回研讨会
STM32 产品及特性 2008年9月 17

02_AN2945 STM8S and STM32 MCUs a consistent 832-bit product line for painless migration

02_AN2945 STM8S and STM32 MCUs a consistent 832-bit product line for painless migration

AN2945Application note STM8S and STM32™ MCUs: a consistent 8/32-bit product linefor painless migrationIntroductionFollowing the market launch of the award winning STM32™ microcontroller,STMicroelectronics completes the renewal of its microcontroller product line with theannouncement of the STM8S family. Significant effort has been made to rationalize theMCU portfolio, in particular by capitalizing on common peripherals and software tools withthe aim to easing product migration.The cost, in terms of both time and money, of maintaining a development team to design ina new MCU family is a major criterion when selecting a microcontroller supplier. It istherefore an advantage to make this kind of non-recurring investment if it applies to a broadrange of MCUs. With an MCU product line ranging from 20 to 144 pins, and memory sizesfrom 2 to 512 Kbytes, the 8-bit STM8S and 32-bit STM32 families bring a lot of flexibilitywhen building a product portfolio. Should an 8-bit application run out of MIPS, there is anupgrade path to the STM32 family. Conversely, if you wish to cut costs on a 32-bit platform,it is relatively simple to switch to the STM8 family.This document presents the similarities and common features of the STM8S and STM32product lines, with a view of helping migration from one family to the other.July 2009Doc ID 15468 Rev 11/18Contents AN2945Contents1Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63System features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.1Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.2Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.4Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.5Low power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4Software library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172/18 Doc ID 15468AN2945List of tables List of tablesTable 1.STM8 and STM32: core comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Table 2.STM32 SPI register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Table 3.STM8 SPI register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Table 4.Peripherals shared between STM8 and STM32 devices . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Table 5.STM8S/STM32 clock source characteristics (indicative data) . . . . . . . . . . . . . . . . . . . . . . 11 Table 6.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Doc ID 154683/18List of figures AN2945 List of figuresFigure 1.Digital peripheral’s internal structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 2.SPI block diagrams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Figure 3.STM8S and STM32 reset circuitries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 4.STM8S code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Figure 5.STM32 code example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4/18 Doc ID 15468AN2945CoreDoc ID 154685/181 CoreThe STM8™ CPU is a proprietary architecture that maintains the legacy of the previous ST7 core while being a breakthrough in terms of 8-bit CPU efficiency and code density. The STM32 is built around the industry standard ARM ® Cortex™-M3 32-bit core and benefits from the complete ecosystem of development tools and software solutions associated with ARM processors. Although they may be perceived as radically different, these two processors indeed share many architectural similarities summarized in Table 1.Both are based on the Harvard architecture. They have 3-stage pipelined execution thatminimizes the execution time, a clock speed up to 24MHz for the STM8S and up to 72MHz for the STM32 family.They are devised to be highly energy efficient, with several low power modes, and they benefit from memory interfaces wider than the average instruction length (32- and 64-bit wide busses, respectively). This minimizes the number of accesses to the memory bus and thus the consumption related to address bus toggling and non-volatile memory read accesses. Interrupt tail chaining and the Halt/Sleep on exit modes also help avoiding unnecessary stack accesses.Finally, in terms of code density, both have excellent results, owing to the 8-bit CISC instruction set for the STM8S family and, to the 16-bit Thumb-2 mode introduced by the Cortex core for the STM32 family.This short comparison demonstrates that both processors are state-of-the-art in terms of micro-architectural features. The STM8 is at the level of legacy of 16-bit processors, and the Cortex-M3 meets the requirements of applications currently using 32-bit down to mid/high-end 16-bit MCUs. The combination of the STM8 and STM32 therefore establishes aperformance continuum, which is now also supported at tool levels by a third party offering a unified development platform for both product lines.Table 1.STM8 and STM32: core comparisonSTM8Cortex-M3Data path8-bit 32-bit Drhystone MIPS (0WS)0.29 DMIPS 1.22 DMIPS Architecture Harvard Harvard Pipeline Y es, three-stage Y es, three-stage Instruction setCISC RISC Program bus data width 32-bit32-bitPrefetch bufferY es, 2 × 32-bit, internal Y es, 2 × 64-bit, in memory interface Average instruction size 2 bytes2 bytesInterrupt type LatencyVectorized9 cycles, tail chaining supportedVectorized12 cycles, tail chaining supportedLow power modes Slow, Wait for Event or interrupts, Halt, Halt on exit Slow, Sleep (Wait for event or interrupt), Sleep on exit, Deep sleep Debug interface1-wire (SWIM)2-wires or legacy JTAGPeripherals AN2945 2 PeripheralsThe MCU peripherals (also called IPs) are another example of the ST MCU consistencyacross the 8- and 32-bit product lines: most of the basic IPs have been defined andstructured to be portable from one product family to the other. This was done by adaptingsimple, yet effective, 8-bit peripherals to the 32-bit world. It brings the benefits of cost- andpower-effective, easy to understand resources, which are complemented at system level bywider busses and a DMA controller when higher performance is needed. Once the workingprinciple of a peripheral is understood, it is applicable to both the STM8S and STM32families, thus speeding up transition between devices.Figure1 shows a simplified representation of a digital peripheral.The peripheral can be partitioned into two main blocks. First, a kernel that contains the statemachines, counters and any kind of combinatorial or sequential logic necessary to performtasks that do not need the processor, such as low-communication layers, analog front-endmanagement or timing-driven functions. If necessary, the kernel is connected to the externalworld via MCU ports. The external connection may consist of a few I/Os or complex busses.Second, the peripheral is initialized and controlled by the application through registersconnected to an internal bus shared with the other MCU resources. In 8-bit microcontrollers,the processor directly writes to and reads from registers, whereas in 32-bit products, registerread and write operations usually go through a bridge. The main difference between the twofamilies, however, lies in the internal bus specification the peripheral has to comply with.This explains why STM8S and STM32 devices are able to share peripherals: these arebased on the same kernel, and are only tailored to the two different bus interfaces. ARMprocessors and peripherals comply with the AMBA bus specification, with a 32-bit databus, 6/18 Doc ID 15468AN2945PeripheralsDoc ID 154687/18whereas STM8S devices use a simpler, yet efficient, 8-bit bus standard. From the functional point of view, they only differs by:●the register size: 8 vs. 16 or 32-bit●the maximum clock frequency that directly depends on the CPU operating speed ●the DMA that offloads the CPU from simple data management and increases the maximum data throughput●few product-specific functions, such as I/O port managementLet us consider the STM8S and STM32 SPI block diagrams shown in Figure 2. At firstglance, they look identical apart from a few differences in bits highlighted in red in Figure 2, for instance, at the level of the DMA.Now considering the register maps shown in Table 2 and Table 3, they are clearly based on the same design: apart from a few differentiating bits and the register sizes, registers and bits have similar names and locations in registers.Peripherals AN29458/18 Doc ID 15468Table 2.STM32 SPI register map and reset valuesOffsetRegister3130292827262524232221201918171615141312111098765432100x00SPI_CR1ReservedB I D I M O D EB I D I O EC R C E N C R C N E X TD F FR X O N L YS S MS S IL S B F I R S TS P EBR [2:0]M S T R C P O LC P H A Reset Value 00000000000000000x04SPI_CR2ReservedT X E I ER X N E I EE R R I ER e s e r v e d S S O ET X D M A E N R X D M A E N Reset Value 0000000x08SPI_SR ReservedB S YO V RM O D FC R C E R RU D RC H S ID ET X E R X N E Reset Value 000000100x0C SPI_DR Reserved DR[15:0]Reset Value 00000000000000000x10SPI_CRCPR Reserved CRCPOL Y[15:0]Reset Value 00000000000001110x14SPI_RXCRCR Reserved RxCRC[15:0]Reset Value 00000000000000000x18SPI_TXCRCR ReservedTxCRC[15:0]Reset Value 0000000000000x1C SPI_I2SCFGR ReservedI 2S M O DI 2S EI 2S C F GP C M S Y N C R e s e r v e dI 2S S T D C K P O LD A T LE N C H L E N Reset Value00000000000x20SPI_I2SPR ReservedM C K O EO D DI2SDIVReset Value001Table 3.STM8 SPI register map and reset valuesAddress offsetRegister name76543210x00SPI_CR1Reset value LSBFirst0SPE 0BR20BR10BR10MSTR 0CPOL 0CPHA 00x01SPI_CR2Reset value BDM 0BDOE 0CRCEN0CRCNEXT0Reserved0RXONL Y0SSM 0SSI 00x02SPI_ICR Reset value TXIE 0RXIE 0ERRIE 0WKIE 0Reserved0Reserved0Reserved0Reserved00x03SPI_SR Reset value BSY 0OVR 0MODF 0CRCERRWKUP 0ReservedTXE 1RXNE 00x04SPI_DR Reset value MSB 0-0-0-0-0-0-0LSB 00x05SPI_CRCPR Reset value MSB 0-0-0-0-0-1-1LSB 10x06SPI_RXCRCR Reset value MSB 0-0-0-0-0-0-0LSB 00x07SPI_TXCRCR Reset valueMSB 0-0-0-0-0-0-0LSB 0AN2945Peripherals Table4 lists the common peripherals, highlighting the coherency between products atregister, bit and feature level.Table 4.Peripherals shared between STM8 and STM32 devicesPeripheral namesSTM32STM8Independent watchdog (IWDG)Window watchdog (WWDG)Serial peripheral interface (SPI)Inter-integrated circuit (I2C) interfaceUniversal synchronous/asynchronous receiver/transmitter (USART)Advanced-control timers16-bit advanced-control timerGeneral-purpose timer16-bit general-purpose timersBasic timer8-bit basic timerAlthough the timers seem different with many distinct configurations, their architectureacross and within the product families is the same. There are only variations of a singletimer architecture. From the superset, sub-blocks can optionally be stripped to decrease thenumber of capture/compare channels or remove options necessary only for a few specificapplications such as motor control.Doc ID 154689/18System features AN294510/18 Doc ID 154683 System featuresToday’s MCUs are complex SoCs (systems on chip) that not only include a lot of peripherals,but also advanced-system features aiming at reducing the bill of material or enhancing the products’ safety and robustness. This is true for both 8- and 32-bit platforms.3.1 ResetAs shown in Figure 3, the STM8S and STM32 devices have the same reset circuitry, with only slight differences.The NRST pin is both an input and an open-drain output with a built-in pull-up resistor. For EMS (electromagnetic sensitivity) robustness purposes, a filter is inserted to avoid glitch propagation into the digital circuitry. There are three advantages with having a bidirectional reset:●for multi-MCU systems, bidirectional reset ensures than all subprocessors are correctly synchronized at startup or in case of a warm reset●the voltage supervisors (power-on reset and brownout reset) embedded in the MCU can also be used at system level for other ICs●it is of a great help during debugging when spurious internal resets are generatedAN2945System featuresDoc ID 1546811/183.2 ClockFrom the clock system standpoint, the two products have three main clock sources incommon, that share similar electrical characteristics. See T able 5 for details.The oscillator handles both the crystal and resonators, and is called the HSE (for high-speed external). It can also be bypassed to feed the MCU with an external clock. This isused for applications that have stringent requirements in terms of accuracy and stability, forcommunication purposes for instance.An application can run at a high frequency without an external crystal by using the HSI clock(for high-speed internal). This source has a consumption 10 times lower than the HSE and avery low percentage of accuracy error. It can also be used as a PLL input on the STM32 toincrease the internal frequency to up to 64 MHz.Finally, the low-speed internal clock (LSI) is an ultralow internal power source (a few µA),that can be permanently enabled to clock an auto-wakeup peripheral during the Halt or Stopmode. It can also clock a secondary on-board watchdog (refer to Section 3.4: Safety forfurther details), and be used as the CPU clock on the STM8 products. It is not accurate(error of a few tens of percents), but it can be measured periodically using the precise HSIclock to compensate for chip manufacturing variations or the drift due to temperature forinstance.3.3 MemoryBoth product lines are based on non-volatile memories and have an option byte loader. Thismechanism replaces the legacy fuses for MCU power-up configuration: the user can selectseveral options at programming time, which are written alongside the program binary image.Several features are available on all news microcontrollers:●Reset in Halt, Stop or Standby mode: this is to avoid a deadlock situation in case the MCU enters a low power mode by accident, for applications not designed to handlesuch a configuration●Hardware/Software watchdog, to have the possibility of starting the watchdog by hardware, right after the reset sequence●Memory readout protection, to prevent any piracy on the program content●Memory write protection, to protect part of the memory, if it contains a critical code. Usually, this applies to the boot code or an IAP (in application programming) driver Table 5.STM8S/STM32 clock source characteristics (indicative data (1))1.Refer to product datasheet for detailed electrical characteristics.System clock source FrequencyAccuracy errorConsumption STM8S STM32High-speed external (HSE)1-24 MHz 4-16 MHzCrystal dependent, down to a few tens of ppm 1 to 2 mA High-speed internal (HSI)16 MHz 8 MHz1% typical 100 to 250 µA Low-speed internal 110-146 kHz30-60kHz 20 to 50% 1 to 5 µASystem features AN2945 These options allow automatically enabled safety and robustness features, so that theapplication can recover even if a disturbance or an attack occurs before the very firstinstruction is fetched by the CPU.The STM8S and STM32 devices have an embedded boot loader, making it possiblereprogram the internal Flash memory with an on-board serial interface (the UART forinstance). Any PC with a serial COM interface can then be used as a programming tool toprogram or update the Flash and data EEPROM memory content. ST provides a softwareutility to perform all operations supported by the boot loader.3.4 SafetyThe automotive industry first pushed for increasing the reliability of MCU-based electroniccontrols. This has been followed by similar requests from the industrial segments, andhousehold appliances now have to comply with a specific standard, IEC60335-1. Both theSTM32 and STM8S devices are Class B compliant according to this standard. Complianceis obtained by using dedicated self-test libraries certified by an independent test institute,and also with the help of some specific hardware circuitry. Both the software and hardwarecontribute to significantly reduce the development and qualification time of applications withstringent functional safety requirements.●WatchdogsThe MCUs embed two watchdogs:–The Window Watchdog is intended to monitor the main loop and check that loop time is within a given time frame. It runs on the system clock.–In parallel, an independent watchdog can be activated to increase the system’s robustness This watchdog will indeed continue to operate even in the case of amain clock failure (for instance due to a broken crystal).●Clock monitoringThe standard also requires the detection of crystal failure or oscillations at harmonics/subharmonics. This is achieved using the clock system described in Section3.2: Clock,to periodically measure the external crystal or resonator frequency with the internalclock source. Finally, a clock security system (CSS) also monitors the HSE source andautomatically switches back the system clock to the internal HSI clock in case of afailure.12/18 Doc ID 15468AN2945System featuresDoc ID 1546813/183.5 L ow powerOn top of the core’s intrinsic low power modes, both the STM8S and STM32 devices areable to reduce the overall consumption at system-on-chip level.The power consumption in the Run and Wait modes can be reduced by one of the followingmeans:●Slowing down the system clocks: the consumption can thus be adjusted according to the performance required by the application. This is done using the prescalers includedin the clock controller.●Gating the clocks of the peripherals when they are not used to minimize the dynamic consumption related to the clock tree switching activity.The two products embed regulators to supply the internal logic at 1.8V . These regulatorshave a significant operating current in Run mode (a few tens of µA) where they are able todeliver currents in the mA or tens of mA range. In order to further reduce consumption, it ispossible to configure the regulator in low power mode, and minimize its quiescentconsumption, when the current necessary to supply the logic is in the µA range, typicallyduring the Halt or Stop mode. This mode offers the lowest consumption, with a wakeup timeslightly longer than the configuration using the regulator in Run mode.Software library AN294514/18 Doc ID 154684 Software libraryPeripheral compatibility throughout ST’s STM8 and STM32 MCU families promotes platformdesign and helps significantly switch from one product line to the other. When it comes todevelopment time, however, software support is essential. Extensive software libraries areavailable for both the STM8S and STM32 devices, providing the user with a hardwareabstraction layer (HAL) for all MCU resources. Moreover, there is not a single control/statusbit that is not covered by a C function or an API.The software library covers three abstraction levels, and it includes:1. a complete register address map with all bits, bit fields and registers declared in C. Byproviding this map, the software library makes the designers’ task much lighter and,even more importantly so, it gives all the benefits of a bug-free reference mapping file,thus speeding up the early project phase.2. a collection of routines and data structures in API form, that covers all peripheralfunctions. This collection can directly be used as a reference framework, since it alsoincludes macros for supporting core-related intrinsic features and common constantand data type definition. Moreover, it is compiler agnostic and can therefore be usedwith any existing or future toolchain. It was developed using the MISRA C automotivestandard.3.a set of examples covering all available IPs (85 examples so far for the STM32 family,57 for the STM8S family), with template projects for the most common developmenttoolchains. With the appropriate hardware evaluation board, only a few hours areneeded to get started with a brand new microcontroller.It is then up to you to choose how to use the library. Y ou can either pick up the files useful forthe design, use examples to get trained or quickly evaluate the product. Y ou can also usethe API to save development time.Let us now have a look at the few key files and concepts. Two separate libraries support theSTM8S and STM32F devices. In the file names below, you simply need to replace the“stmxxx_” prefix by “stm32f10x ” or “stm8s ” depending on the chosen product.●stmxxx_.hThis file is the only header file that must be included in the C source code, usually inmain.c . This file contains:–data structures and address mapping for all peripherals –macros to access peripheral register hardware (for bit manipulation for instance), plus STM8S core intrinsics – a configuration section used to select the device implemented in the targetapplication. Y ou also have the choice to use or not the peripheral drivers in theapplication code (that is code based on direct access to registers rather thanthrough API drivers)●stmxxx_conf.hThis is the peripheral driver configuration file, where you specify the peripherals youwants to use in your application, plus a few application-specific parameters such as thecrystal frequency.●stmxxx_it.cThis file contains the template IRQ handler to be filled, but this is already the firstdevelopment step!AN2945Software library Once you have understood the above operating principle and file organization, for simpleapplications, you could virtually switch from one product to the other without referring to thereference manual.Let us take a practical example: an SPI peripheral configured in master mode, used to readfrom/write to an external EEPROM.Figure4 and Figure5 below show the initialization code (using the software library) for anSTM8S and an STM32 product, respectively.Figure 4.STM8S code example/* --------------- Initialize SPI in Master mode -------------- */SPI_Init(SPI_FIRSTBIT_MSB,SPI_BAUDRATEPRESCALER_4,SPI_MODE_MASTER,SPI_CLOCKPOLARITY_LOW,SPI_CLOCKPHASE_2EDGE,SPI_DATADIRECTION_1LINE_TX,SPI_NSS_SOFT,0x07); /* CRC Polynomial *//* ------------------------- Enable SPI ----------------------- */SPI_Cmd(ENABLE);Figure 5.STM32 code example/* Private variables --------------------------------------- */SPI_InitTypeDef SPI_InitStructure;/* ---------------------- SPI1 Master ------------------------- */SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;SPI_InitStructure.SPI_Mode = SPI_Mode_Master;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;SPI_InitStructure.SPI_CRCPolynomial = 7;SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;SPI_Init(SPI1, &SPI_InitStructure);/* ----------------------- Enable SPI1 ------------------------ */SPI_Cmd(SPI1, ENABLE);All parameters are identical, and the procedure is similar with two function calls for bothconfiguration and startup. The main difference lies in the way the parameters are passedinto the function. STM32 devices use a structure passed by address whereas, for STM8Sdevices, parameters are passed directly to minimize the amount of RAM needed during theinitialization phase (this is necessary with devices with down to 1 Kbyte of RAM).Another difference is the possibility, when using STM32 devices, of specifying the data size(8- or 16-bit) for the SPI. In the above example (Figure5), the data size is explicitly defined,however, the library is done so that it can be omitted: if this field is not initialized in thestructure, the 8-bit data size is used by default to maintain compatibility with STM8Sdevices.Doc ID 1546815/18Conclusion AN2945 5 ConclusionThis application note discusses the points that ease the transition from the 8-bit STM8S tothe 32-bit STM32 devices, and vice versa. Based on the 8- to 32-bit core performancecontinuum, the new STM32 and STM8S MCU families have a lot of common features. At theperipheral level, they share standard IPs like timers and communication interfaces. At thesystem level, they have identical features, reducing the external component count (clock andreset systems, safety features, etc).These common features are complemented by a set of software libraries that come as amajor help to get started for new development. The libraries can also serve as foundationsfor a unified development platform supporting both 8- and 32-bit MCUs owing to theabstraction level they both offer.Finally, the common features of the STM8S and STM32 devices with the benefits of theirsoftware libraries maximize design re-use and decrease time to market, specially if theapplication has derivatives with various requirements in terms of processing power,connectivity or control function complexity.16/18 Doc ID 15468AN2945Revision history Doc ID 1546817/186 Revision historyTable 6.Document revision history DateRevision Changes28-Jul-20091Initial release.AN2945Please Read Carefully:Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.All ST products are sold pursuant to ST’s terms and conditions of sale.Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.UNL ESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SAL E ST DISCL AIMS ANY EXPRESS OR IMPL IED WARRANTY WITH RESPECT TO THE USE AND/OR SAL E OF ST PRODUCTS INCL UDING WITHOUT L IMITATION IMPL IED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNL ESS EXPRESSL Y APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.ST and the ST logo are trademarks or registered trademarks of ST in various countries.Information in this document supersedes and replaces all information previously supplied.The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.© 2009 STMicroelectronics - All rights reservedSTMicroelectronics group of companiesAustralia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America18/18Doc ID 15468 Rev 1。

stm8,32详解

stm8,32详解

sTm 8 ,32 详解默认分类2011-01-08 09:32:04 阅读30 评论0 字号:大中小订阅先将ST最近一次研讨会上讲的一些应用实例编入,该文档可点击下载(文件大小: (原文件名:STM32F10x 常见应用解析.pdf)对于论坛中提供代码的酷帖,大部分由于没有多少说明,且不是针对某一类问题的解答,基本只是会在楼下的楼下列出清单,而不会再对其专门组织整理。

按照使用外设模块==================================================================================================== GPIO/AFIO =============================1、GPIO的推动能力================================ Backup ======================================================== Reset/Clock Control =======================1、时钟安全系统(CSS)时钟安全系统被激活后,时钟监控器将实时监控外部高速振荡器;如果HSE时钟发生故障,外部振荡器自动被关闭,产生时钟安全中断,该中断被连接到Cortex-M3的NMI的中断;同时CSS将内部RC振荡器切换为STM32的系统时钟源(对于STM32F103,时钟失效事件还将被送到高级定时器TIM1的刹车输入端,用以实现电机保护控制)。

操作流程:1)、启动时钟安全系统CSS: RCC_ClockSecuritySystemCmd(ENABLE); (NMI中断是不可屏蔽的!)2)外部振荡器失效时,产生NMI中断,对应的中断程序:void NMIException(void){if (RCC_GetITStatus(RCC_IT_CSS) != RESET){操作流程:1)、设置为复用Push-Pull模式。

STM8和STM32产品选型手册

STM8和STM32产品选型手册

9x16-bit / 1x32-bit
13x12-bit 1x12-bit 37 2 1 2 4 1 19x12-bit 1x12-bit 51 2 1 2 4 1 19x12-bit 1x12-bit 87 2 1 2 4 1
2.0 to 3.6 1.7 2.0 to 3.6 1.7 2.0 to 3.6 1.7
16-/32-bit
timers
Others
ADC
DAC
I/Os SPI
I²S
I²C
USART CEC
USB FS
CAN 2.0B
Supply voltage
(V)
Lowest power mode (µA)
Run mode (per MHz) (µA)
Maximum operating temperature range (°C)
55 2
2
2
STM3S2TFM05312Fli0nxe1-li4n8eM- H48z CMPHUzwCPitUh DAC
4
LQFP48
5x16-bit / 1x32-bit
13x12-bit 1x12-bit 39 1 1 1
1
4
TSSOP20
5x16-bit / 1x32-bit
13x12-bit 1x12-bit 13 1 1 1
19x12-bit 1x12-bit 55 1 1 1
1
1
13x12-bit 1x12-bit 39 1 1 1
2
1
13x12-bit 1x12-bit 27 1 1 1
2
1
2.0 to 3.6 1.7 2.0 to 3.6 1.7 2.0 to 3.6 1.7

UM0462STM32STM8SFlashloaderdemonstrator(V6)

UM0462STM32STM8SFlashloaderdemonstrator(V6)

UM0462STM32STM8SFlashloaderdemonstrator(V6)UM0462User manualSTM32? and STM8?Flash loader demonstratorIntroductionThe purpose of this document is to describe the STMicroelectronics STM32? and STM8?Flash loader demonstrator application that was developed to illustrate the System memoryboot loader capabilities.This document details the prerequested hardware and software environments, as well asthe use cases of the demonstrator software.July 2009Doc ID 13916 Rev 61/21/doc/12c30ad184254b35eefd34c8.htmlContents UM0462 Contents1Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1Package contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.1Software contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.2Hardware contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3Flash loader demonstrator installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.3.1Software installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.3.2Hardware installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2User interface description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3Command-line usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202/21 Doc ID 13916 Rev 6UM0462List of tables List of tablesTable 1.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Doc ID 13916 Rev 63/21List of figures UM0462 List of figuresFigure 1.System Properties dialog box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 2.Device Manager window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Figure 3.Connection settings page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 4.Flash status page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 5.Device information page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 6.Operation choice page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 7.Option byte edition page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Figure 8.Operation progress page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4/21 Doc ID 13916 Rev 6UM0462Getting started Doc ID 13916 Rev 65/211 Getting started1.1 Package contentsThe following items are supplied in the Flash loader demonstrator package:1.1.1 Software contents1. STBLLIB.dll : a dynamic-link library implementing the system memory boot loader protocol and the communication APIs as virtual functions to be loaded dynamicallyfrom the STUARTBLLib.dll and STCANBLLib.dll files.2. STUARTBLLib.dll : a dynamic-link library implementing the system memory boot loader protocol and the COM communication APIs.3. STCANBLLib.dll : a dynamic-link library implementing the system memory boot loader protocol and the CAN communication APIs.4. Files.dll : a dynamic-link library implementing the needed file manipulation APIs to load and store binary, hexadecimal and motorola S19 files.5. STMicroelectronics Flash loader.exe: a wizard application that provides the high-level operations that can be performed by the user.6. STMFlashLoader.exe : a command-line version of the STMicroelectronics Flash loader.exe that provides the same features over several options.7. The “Map” directory is located in the installation directory. It contains the mapping description files of the supported devices.8. The “Src” directory is located in the installation directory. It contains the header and Lib files of the two DLLs and the complete source of the command-line version.9.The “Doc” directory is located in the installation directory, it contains the UM0462 andUM0516 (Windows API for STMicroelectronics microcontroller boot loaders ) user manuals.1.1.2 Hardware contentsThe Flash loader demonstrator is designed to work with all STMicroelectronics devices that support the system memory boot mode protocols. For more details, please visit the STMicroelectronics website (/doc/12c30ad184254b35eefd34c8.html ).1.2 System requirementsIn order to use the Flash loader demonstrator with the Windows operating system, a recent version of Windows, such as Windows 98, Millennium, 2000, XP or Vista, must be installed on the PC.The version of the Windows OS installed on your computer may be determined by right-clicking on the “My Computer” icon on the desktop, then clicking on the “Properties” item in the displayed pop-up menu. The OS type is displayed in the “System Properties” dialog box under the “System” label as shown in Figure 1.Getting started UM04626/21 Doc ID 13916 Rev 6Figure 1.System Properties dialog box For communication purposes, you need to verify that you have:●an available COM port (RS232) if the application implements the UART interface ● a ComBox bridge plugged and installed on your machine if the application implements the CAN interfaceTo check that you have an available interface (COM or ComBox), right-click on the “MyComputer” icon on the desktop and select “Properties” from the pop-up menu. The “SystemProperties” dialog box appears. Click on the “Hardware” tab, and then on the “Devicemanager” button to display the system hardware configuration. Available COM ports aregrouped under the “Ports (COM & LPT)” node in the hardware tree and the ComBox bridgeis under the “Universal Serial Bus Controllers” node as shown in Figure 2.UM0462Getting startedDoc ID 13916 Rev 67/21Figure 2.Device Manager window It is interesting to know the capabilities of the COM port. To find out, right click on the Communication Port (COMx) item then click on “Properties” to display the Propertieswindow. Select the “Port Settings” tab, then click on the arrow next to the “Bits per second”combo box to know the baud rates supported by the port.1.3 Flash loader demonstrator installation1.3.1 Software installationIf an older version is installed on you computer, remove it by using the “Add or RemovePrograms” service in the “Control Panel”.Run the Flash_Loader_Demonstrator_V2.0_Setup.exe file: the InstallShield Wizard willguide you through the installation of the Flash loader demonstrator application on yourcomputer. Once the software has been successfully installed, click on the “Finish” button, adirectory containing the driver install for the ComBox Bridge will automatically open. Use theCOMBox.INF file to install this driver.Getting started UM04628/21 Doc ID 13916 Rev 61.3.2 Hardware installationAs the Flash loader demonstrator is able to communicate over the UART and CANinterfaces, the device should be connected to a spare PC COM port and to the PC ComBoxbridge in the event of a UART or CAN communication, respectively.2 User interface descriptionThe Flash loader demonstrator is designed as a wizard application. It is structured into sixsteps, the:1.Connection settings page2. Flash status page3. Device information page4. Operation choice page5. Option byte edition page6. Operation progress pageStep 1Run the Flash loader demonstrator application from the “Programs” menu (connection to thedevice has not been made yet) then, make sure that the device is connected to your PC andreset it to restart the system memory boot loader code.This step consists in selecting the connection interface and its related settings. Select thedesired interface (UART, CAN or USB) then set the connection settings (port name, baudrate and timeout, etc.) as shown in Figure3. For an optimum configuration for the UARTinterface, set “Baud Rate” to 57600 bits per second and “Timeout(s)” to 5 seconds.Ensure that the boot configuration pins are set correctly, then click “Next” to continue. If aconnection has been established, the wizard moves to the next step, otherwise a messagebox is displayed that indicates the error that occurred.Possible errors messages:●“Cannot open the COM/CAN port”: this message is shown if the selected COM port isnot found or if it is already being used by another process.●“Unrecognized device”: this message is shown if the received value is different from79h. Resetting the device may solve the problem.●“No response from the target”: this message is shown when there is no response fromthe target. It indicates that the System memory boot loader is not functional. Verify theboot configuration and check that the used microcontroller contains the boot loadercode.Note:The Timeout argument is the period of time after which a read request from the serial port is aborted if no data is received. The recommended value is 5 seconds, but it depends on theused environment, like the hardware performance.Doc ID 13916 Rev 69/21Figure 3.Connection settings page10/21 Doc ID 13916 Rev 6Step 2In the second step the connection has been established and communication has started. Itconsists in displaying the Flash memory status. This status can be read-protected, in whichcase the “Next” button is disabled until the read protection is removed by clicking on the“Remove protection” button.Note:Clicking on the “Remove protection” button will not only read-unprotect the Flash memory, it will also erase all its pages.Figure 4.Flash status pageDoc ID 13916 Rev 611/21Step 3In this step the Wizard displays the available device information such as the target ID, thefirmware version, the supported device, the memory map and the memory protection status.Select the target name in the target combobox as shown in Figure5, then click on “Next” tocontinue.Figure 5.Device information page12/21 Doc ID 13916 Rev 6Step 4At this step, select the requested operation –Erase, Download, Upload or Disable/Enable Flash protection or Edit option bytes – and set the related parameters:1.Erasea) Choose “All” to erase the whole memoryb) Choose “Selection” to customize the Erase operation. Click the “...” button todisplay the memory mapping dialog window. Then check the pages to be erasedand click “Ok”.2. Download–Click the related browse button to open a binary, hexadecimal or S19 Motorola file.If the loaded file is a binary file, the download address is the start address of thefirst page and the “@” field is still editable to accept changes.If the loaded file is a hexadecimal or an S19 motorola file, the download address isthe start address of the first record in the file, and the “@” field is read-only.–Check the “Verify” check box to launch the verification process when the Download operation is finished.–Check “Jump to the user program” to launch the downloaded program.–Check “Optimize” to filter FFs packets (256 bytes).–Check “Apply option bytes”, then browse the option byte file created by the “Edit option bytes” operation. The values in the selected file will be applied to the deviceafter download.3. Upload–Click the related browse button to select which binary, hexadecimal or S19 motorola file will store the uploaded data.4. Disable/Enable Flash protection–Select the choices from the two drop-down menus to make up the desired command (Enable Read protection, Disable Read protection, Enable Writeprotection, Disable Write protection). All protection commands will be applied to allthe Flash memory pages except for the Enable Write Protection, which can becustomized. This is done by clicking the “...” button to select the pages to be write-protected.5. Edit option bytes–If you need to set the option bytes, check the option then click “Next” to move to the option byte edition page (Step 5 Figure 7.).Warning:Erase and Download operations can be performed only if thewrite protection is disabled.Doc ID 13916 Rev 613/21Figure 6.Operation choice pageStep 5Note:This step applies to STM32 devices only. There is no step 5 for STM8 devices.The last Wizard page depends on the operation selected in Step 4.a) Case of an “Edit option bytes” operation:The Option byte edition page is displayed. It contains the current option byte valuesloaded from the device: RDP, USER, Data0, Data1, WRP0, WRP1, WRP2 and WRP3.For more details, please refer to the Option byte loader section in the “STM32F10xxxFlash programming manual” (PM0042 available from /doc/12c30ad184254b35eefd34c8.html ).This step gives the possibility of applying the edited option byte values, loading themfrom the device and saving them to a file.14/21 Doc ID 13916 Rev 6Figure 7.Option byte edition pageb) Case of any other operation:The operation page is shown. It gives the size of the data to be downloaded oruploaded, the percent completed and the duration of the operation as illustrated in Figure8.●If the operation is successful, the progress bar is green colored. If an error occurs, thebar turns red and the error is displayed.●To stop the operation click the “Cancel” button.●If the “Jump to the user program” check box was checked in the previous step (Step 4),and the user program was successfully downloaded, communication with the system memory boot loader is lost. Consequently, the “Back” button is redirected to the“Connection settings page” (Step 1) to avoid the launch of a new operation.If the “Jump to the user program” check box was not checked in Step 4, the “Back”button is still active and you can return to Step 4 and select a new operation.Doc ID 13916 Rev 615/21Figure 8.Operation progress page16/21 Doc ID 13916 Rev 6UM0462Command-line usage Doc ID 13916 Rev 617/213 Command-line usageThe command-line version (STMFlashLoader.exe ) provides the same functionality as the GUI. It supports several options in order to run a sequence of operations.The following paragraphs describe the available command-line options. STMFlashLoader.exe option [Arguments] [option [Arguments]]...-?Shows help.-c:Defines the COM port.The -c option allows you to select the COM port that the command uses to communicate with the target MCU. By default, the command uses COM1. T o select different COM port and connection settings, use the -c option in the form:-c --pn port_number (e.g 1, 2..., default 1)-c --br baud_rate (e.g 115200, 57600..., default 57600)-c --db data_bits (value in {5,6,7,8}..., default 8)-c --pr parity (value in {NONE,ODD,EVEN}..., default EVEN)-c --sb stop_bits (value in {1,1.5,2}..., default 1)-c --to time_out ((ms) e.g 1000, 2000, 3000..., default 5000)The -c option supports multiple arguments. This means that you can set more than one argument in the same command:-c --pn 1 --br 115200 --to 7000-i device_nameDefines the MCU target to be used.For example: STM32F10xxBxx, STM32F10xx8xx, STM32F10xx6xx. The device name is the name of the map file located in the Map directory.-eErase command.According to the given arguments, the command can be used to erase a specific page of memory or, to erase the entire Flash memory. This operation can take a second or more to complete, depending on the memory size involved.-e --all erase all pages-e --sec number_of_pages_group pages_group_codes-e --sec 3 0 1 2 erases 3 groups of pages coded 0, 1 and 2Command-line usage UM0462-uUploads the Flash memory contents to the specified file (bin, hex or s19 file; the file type is recognized by its extension), to specify a file use the -u option in the form:-u --fn file_name (full path name)-dDownloads the contents of the specified file into the MCU Flash memory at the specified address. To specify the file to be downloaded and the download address, use the -d option in the form:-d --a address(hex) --fn file_name (full path name (bin, hex or s19 file); the file type is recognized by its extension).The address is mandatory in the case of binary files and ignored in the case of hex and s19 files.To verify the downloaded data, add the --v argument.To optimize and remove FF packets, use the --o argument.-oGets or sets option bytes.Use --get to read option bytes from the device and store values to a file.--get --fn file_name (full path name)Use --set to write option bytes to the device. The option bytes can be read from a file or given as values.--set --fn file_name (full path name)--set --vals --OPB hex_value (OPB in (User, RDP, Data0, Data1, WRP0, WRP1,WRP2, WRP3).The -o option can accept multiple arguments as shown below:-o --get get_file_name --set set_file_name-o --get get_file_name --set --vals --User 01 --RDP 5A --Data0 DE --Data1 EA Warning:When setting option bytes, if RDP is not equal to A5h, theread protection is activated, and all subsequent operationswill fail.18/21 Doc ID 13916 Rev 6UM0462Command-line usage-pActivates or deactivates the protection. It is used as shown below:-p --erp (Activate read protection)-p --drp (Deactivate read protection)-p --ewp number_of_pages_group pages_group_codes (activates the write protectionon the given page group codes)-p --dwp (disables the write protection)Warning:The --erp argument activates the read protection. Allsubsequent operations will fail. To avoid this kind of problem,use -p --erp as the last argument.-rPerforms a jump to the specified address. It is used as follows:-r --a address(hex)Note:Note that all command-line options found are executed IN ORDER. Thus, with a careful arrangement of the command-line options, you can perform a complicated sequence ofoperations.Doc ID 13916 Rev 619/21。

STM32的FLASH存储器

STM32的FLASH存储器

关于STM32的FLASH操作说到STM32的FLSAH,我们的第一反应是用来装程序的,实际上,STM32的片内FLASH不仅用来装程序,还用来装芯片配置、芯片ID、自举程序等等。

当然,FLASH还可以用来装数据。

FLASH分类根据用途,STM32片内的FLASH分成两部分:主存储块、信息块。

主存储块用于存储程序,我们写的程序一般存储在这里。

信息块又分成两部分:系统存储器、选项字节。

系统存储器存储用于存放在系统存储器自举模式下的启动程序(BootLoader),当使用ISP方式加载程序时,就是由这个程序执行。

这个区域由芯片厂写入BootLoader,然后锁死,用户是无法改变这个区域的。

选项字节存储芯片的配置信息及对主存储块的保护信息。

FLASH的页面STM32的FLASH主存储块按页组织,有的产品每页1KB,有的产品每页2KB。

页面典型的用途就是用于按页擦除FLASH。

从这点来看,页面有点像通用FLASH的扇区。

STM32产品的分类STM32根据FLASH主存储块容量、页面的不同,系统存储器的不同,分为小容量、中容量、大容量、互联型,共四类产品。

小容量产品主存储块1-32KB,每页1KB。

系统存储器2KB。

中容量产品主存储块64-128KB,每页1KB。

系统存储器2KB。

大容量产品主存储块256KB以上,每页2KB。

系统存储器2KB。

互联型产品主存储块256KB以上,每页2KB。

系统存储器18KB。

对于具体一个产品属于哪类,可以查数据手册,或根据以下简单的规则进行区分:STM32F101xx、STM32F102xx、STM32F103xx产品,根据其主存储块容量,一定是小容量、中容量、大容量产品中的一种,STM32F105xx、STM32F107xx是互联型产品。

互联型产品与其它三类的不同之处就是BootLoader的不同,小中大容量产品的BootLoader只有2KB,只能通过USART1进行ISP,而互联型产品的BootLoader有18KB,能通过USAT1、4、CAN等多种方式进行ISP。

stm8的选项字节设定剖析

stm8的选项字节设定剖析

#include "iostm8.h"void main(void){FLASH_DUKR = 0xae;asm("nop");FLASH_DUKR = 0x56;asm("nop");while(!(FLASH_IAPSR & 0x08));asm("nop");FLASH_CR2 = 0x80;asm("nop");FLASH_NCR2 = 0x7f;asm("nop");*((unsigned char *)0x487e) = 0x55;asm("nop");*((unsigned char *)0x487f) = 0xaa;while(1);}参考这个,相当于操作EEPROM只看该作者有2种方法,第一种可以用代码来设置,我封装的一个函数typedef enum{AFR7_PD4_BEEP=(uint8_t)0x80,AFR6_PB4_5_I2C_SDA_SCL=(uint8_t)0x40,AFR5_PB3_2_1_0_TIM1_ETR_CH2_1_0=(uint8_t)0x20,AFR4_PD7_TIM_CH4=(uint8_t)0x10,AFR3_PD0_TIM1_BKIN=(uint8_t)0x08,AFR2_PD0_CLK_CCO=(uint8_t)0x04,AFR1_PA3_TIM3_CH1_PD2_TIM2_CH3=(uint8_t)0x02,AFR0_PD3_ADC_ETR=(uint8_t)0x01}Remap_Function_TypeDef;/******************************************************************************* * 名称: AlternateFunctionRemapping* 功能: 选功能重映射的设置* 形参: Function 需要重映射的功能* 返回: 无* 说明: 如果调试需要打印数据的时候在自定义宏的地方添加#define DEBUG_AFR即可,下载程序后只有第一次执行打印出来设置前的功能才是对的,执行完之前就被写进flash,如果不修改的话,每次都出来的数据都是一样,所以只执行一次就行了,建议用的时候,就在调试的时候进行执行一次就可以,以后都不需要出现了,除非再次更改。

stm8stm32软件加密绑定ID设计方法

stm8stm32软件加密绑定ID设计方法

stm8stm32软件加密绑定ID设计方法
stm8和stm32都有唯一的ID,在软件设计中可绑定唯一ID值来进行软加密。

具体以轩微编程器为例,此款编程序性价比非常高,本人是非常认可的一款烧录器。

具体方法如下:
1,利用轩微编程器的公式,利用公式计算id及设置的常数得出来的值,值放入程序空间某些地址
stm8程序使用公式一样的方法也计算出某些值,这些值与上面放入程序空间的值进行对比,不相等认为为非法程序。

2,读id时,地址的值通过计算得出来,不要直接用id的地址
3,空间多余的地方填满数据,把前面有用的程序拷贝过去
4,对程序进行校验,别人改过后认为为非法程序。

STM32在keil下使用jlink时产生错误的解决方法

STM32在keil下使用jlink时产生错误的解决方法

最近一段时间一直在学习STM32和ucos的移植,使用的开发环境是keil u4版本。

仿真器是80元买的jlink。

在学习了STM32固件库和ucos内核与移植相关的程序之后,写了一个流水灯程序,准备下载到板子上看看情况。

哪知程序还没有下进去,在debug时,keil的错误提示到:Error: Flash download failed-"Cortex-M3"感觉这么错误很普遍,也是初学者常常遇到的错误,下面我就将这个错误产生的原因和解决方法赘述一下:错误产生的原因和分析,解决。

首先,我们看到提示信息是有关flash的,那么我们来查看一下STM32F103XB的数据手册关于这部分的描述(我使用的芯片是STM32F103RB,有128kflash。

)知道了原来flash在此芯片中的地址是从0x0800 0000到0x0801 FFFF 这段,也就是说这段存储空间是用来存储程序。

而在STM32芯片方面,它又有一个规则,那就是芯片启动的方式,如果你把程序下载到了flash中,那么在复位芯片之前或者通电之前,要将boot0,boot1两个引脚拉到高电平,这样在启动时,芯片初始化之后,运行程序代码才是从flash地址开始执行的。

于是,我们来查看一下keil中仿真器的设置,是不是正确,设置的选项在keil软件的project-options for target中的Utilities中,先来查看下仿真器是否选对,然后点settings,弹出如下菜单:查看一下programming Algorism 下的flash地址是否正确,如果不正确则会引起开始那个错误的提示信息,如果正确还是出现那个错误,那么按照官方给的解决方法是,删除现有的flash地址,重新配置一下,记得要选对芯片型号和地址空间。

配置好之后点击OK退出。

然后再查看一下Target中的地址,是否跟你重新添加的一致,如果一致,那么点OK退出。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

UM0462User manualSTM32™ and STM8™Flash loader demonstratorIntroductionThe purpose of this document is to describe the STMicroelectronics STM32™ and STM8™Flash loader demonstrator application that was developed to illustrate the System memoryboot loader capabilities.This document details the prerequested hardware and software environments, as well asthe use cases of the demonstrator software.November 2009Doc ID 13916 Rev 71/25Contents UM0462 Contents1Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1Package contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.1Software contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.1.2Hardware contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3Flash loader demonstrator installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.3.1Software installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.3.2Hardware installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2User interface description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3Command-line usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242/25 Doc ID 13916 Rev 7UM0462List of tables List of tablesTable 1.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Doc ID 13916 Rev 73/25List of figures UM0462 List of figuresFigure 1.System Properties dialog box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Figure 2.Device Manager window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Figure 3.InstallShield Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 4.InstallShield Wizard license agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 5.Connection settings page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 6.Flash status page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 7.Device information page - STM32 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Figure 8.Device information page - STM8 example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Figure 9.Operation choice page for STM32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Figure 10.Operation choice page for STM8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Figure 11.Option byte edition page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Figure 12.Operation progress page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Figure mand-line version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4/25 Doc ID 13916 Rev 7UM0462Getting started Doc ID 13916 Rev 75/251 Getting started1.1 Package contentsThe following items are supplied in the Flash loader demonstrator package:1.1.1 Software contents1. STBLLIB.dll : a dynamic-link library implementing the system memory boot loaderprotocol and the communication APIs as virtual functions to be loaded dynamicallyfrom the STUARTBLLib dll file.2. STUARTBLLib.dll : a dynamic-link library implementing the system memory boot loaderprotocol and the RS232 COM communication APIs.3. Files.dll : a dynamic-link library implementing the needed file manipulation APIs to loadand store binary, hexadecimal and motorola S19 files.4. STMicroelectronics Flash loader.exe: a wizard application that provides the high-leveloperations that can be performed by the user.5. STMFlashLoader.exe : a command-line version of the STMicroelectronics Flashloader.exe that provides the same features over several options.6. The “Map” directory is located in the installation directory. It contains the mappingdescription files of the supported devices.7. The “Src” directory is located in the installation directory. It contains the header and Libfiles of the two DLLs and the complete source of the command-line version.8.The “Doc” directory is located in the installation directory, it contains the UM0462 andUM0516 (Windows API for STMicroelectronics microcontroller boot loaders ) usermanuals.1.1.2 Hardware contentsThe Flash loader demonstrator is designed to work with all STMicroelectronics devices thatsupport the system memory boot mode UART protocol. For more details, please visit theSTMicroelectronics website ( ).1.2 System requirementsIn order to use the Flash loader demonstrator with the Windows operating system, a recentversion of Windows, such as Windows 98, Millennium, 2000, XP , Vista or Windows7 must beinstalled on the PC.The version of the Windows OS installed on your computer may be determined by right-clicking on the “My Computer” icon on the desktop, then clicking on the “Properties” item inthe displayed pop-up menu. The OS type is displayed in the “System Properties” dialog boxunder the “System” label as shown in Figure 1.Getting started UM04626/25 Doc ID 13916 Rev 7Figure 1.System Properties dialog box For communication purposes, you need to verify that you have an available COM port(RS232) if the application implements the UART interface.To check that you have an available interface (COM), right-click on the “My Computer” iconon the desktop and select “Properties” from the pop-up menu. The “System Properties”dialog box appears. Click on the “Hardware” tab, and then on the “Device manager” buttonto display the system hardware configuration. Available COM ports are grouped under the“Ports (COM & LPT)” node in the hardware tree as shown in Figure 2.UM0462Getting startedDoc ID 13916 Rev 77/25Figure 2.Device Manager window It is interesting to know the capabilities of the COM port. To find out, right click on theCommunication Port (COMx) item then click on “Properties” to display the Propertieswindow. Select the “Port Settings” tab, then click on the arrow next to the “Bits per second”combo box to know the baud rates supported by the port.1.3 Flash loader demonstrator installation1.3.1 Software installationIf an older version is installed on you computer, remove it by using the “Add or RemovePrograms” service in the “Control Panel”.Run the provided Setup.exe file: the InstallShield Wizard will guide you through theinstallation of the Flash loader demonstrator application on your computer as shown inFigure 3 and Figure 4 (Y ou must accept the license agreement to install the software).Getting started UM04628/25 Doc ID 13916 Rev 7Figure 3.InstallShield WizardFigure 4.InstallShield Wizard license agreementOnce the software has been successfully installed, click on the “Finish” button. Theversion.txt file containing the new release notes will automatically open in the Microsoft ®-native Notepad application. Closing Notepad will launch the Flash loader demonstrator if thecheck boxes are kept as default in the InstallShield Wizard.UM0462Getting startedDoc ID 13916 Rev 79/251.3.2 Hardware installationAs the Flash loader demonstrator is able to communicate over the UART interface, thedevice should be connected to a spare PC COM port in the event of a UARTcommunication.User interface description UM046210/25 Doc ID 13916 Rev 72 User interface descriptionThe Flash loader demonstrator is designed as a wizard application. It is structured into sixsteps, the:1.Connection settings page 2. Flash status page3.Device information page 4.Operation choice page 5.Option byte edition page 6. Operation progress page Step 1Run the Flash loader demonstrator application from the “Programs” menu (connection to thedevice has not been made yet) then, make sure that the device is connected to your PC andreset it to restart the system memory boot loader code.This step consists in selecting the UART connection interface and its related settings. Setthe connection settings (port name, baud rate and timeout, etc.) as shown in Figure 5. Foran optimum configuration for the UART interface, set “Baud Rate” to 115200 bits per secondand “Timeout(s)” to 5 seconds.Ensure that the boot configuration pins are set correctly, then click “Next” to continue. If aconnection has been established, the wizard moves to the next step, otherwise a messagebox is displayed that indicates the error that occurred.Possible errors messages:●“Cannot open the COM port”: this message is shown if the selected COM port is not found or if it is already being used by another process.●“Unrecognized device”: this message is shown if the received value is different from 0x79. Resetting the device may solve the problem.●“No response from the target”: this message is shown when there is no response from the target. It indicates that the System memory boot loader is not functional. Verify theboot configuration and check that the used microcontroller contains the boot loadercode.Note:The Timeout argument is the period of time after which a read request from the serial port isaborted if no data is received. The recommended value is 5 seconds, but it depends on theused environment, like the hardware performance.Figure 5.Connection settings pageNote:“Echo” combo-box is present in version 2.1.0 of the Flash loader demonstrator for the support of some STM8 devices that use LIN echo back emulation through the UARTprotocol. If these devices are not used, this option should be kept disabled.Doc ID 13916 Rev 711/25Step 2In the second step the connection has been established and communication has started. Itconsists in displaying the Flash memory status. This status can be read-protected, in whichcase the “Next” button is disabled until the read protection is removed by clicking on the“Remove protection” button.Note:Clicking on the “Remove protection” button will not only read-unprotect the Flash memory, it will also erase all its pages.Figure 6.Flash status page12/25 Doc ID 13916 Rev 7Step 3In this step the Wizard displays the available device information such as the target ID, the firmware version, the supported device, the memory map and the memory protection status. Select the target name in the target combobox as shown in Figure7 and Figure8, then click on “Next” to continue.Figure 7.Device information page - STM32 exampleDoc ID 13916 Rev 713/25Figure 8.Device information page - STM8 example14/25 Doc ID 13916 Rev 7Step 4At this step, select the requested operation –Erase, Download, Upload or Disable/Enable Flash protection or Edit option bytes – and set the related parameters:1.Erasea) Choose “All” to erase the whole memoryb) Choose “Selection” to customize the Erase operation. Click the “...” button todisplay the memory mapping dialog window. Then check the pages to be erasedand click “Ok”.2. Download–Click the related browse button to open a binary, hexadecimal or S19 Motorola file.If the loaded file is a binary file, the download address is the start address of thefirst page and the “@” field is still editable to accept changes.If the loaded file is a hexadecimal or an S19 motorola file, the download address isthe start address of the first record in the file, and the “@” field is read-only.–Check the “Verify” check box to launch the verification process when the Download operation is finished.–Check “Jump to the user program” to launch the downloaded program.–Check “Optimize” to filter FFs packets (256 bytes).–Check “Apply option bytes”, then browse the option byte file created by the “Edit option bytes” operation. The values in the selected file will be applied to the deviceafter download.3. Upload–Click the related browse button to select which binary, hexadecimal or S19 motorola file will store the uploaded data.4. Disable/Enable Flash protection–Select the choices from the two drop-down menus to make up the desired command (Enable Read protection, Disable Read protection, Enable Writeprotection, Disable Write protection). All protection commands will be applied to allthe Flash memory pages except for the Enable Write Protection, which can becustomized. This is done by clicking the “...” button to select the pages to be write-protected.5. Edit option bytes–If you need to set the option bytes, check the option then click “Next” to move to the option byte edition page (Step 5 Figure 11.).Warning:Erase and Download operations can be performed only if thewrite protection is disabled.Doc ID 13916 Rev 715/25Figure 9.Operation choice page for STM3216/25 Doc ID 13916 Rev 7Figure 10.Operation choice page for STM8Step 5Note:This step applies to STM32 devices only. There is no step 5 for STM8 devices.The last Wizard page depends on the operation selected in Step 4.a) Case of an “Edit option bytes” operation:The Option byte edition page is displayed. It contains the current option byte valuesloaded from the device: RDP, USER, Data0, Data1, WRP0, WRP1, WRP2 and WRP3.For more details, please refer to the Option byte loader section in the “STM32F10xxxFlash programming manual” (PM0042 available from ).This step gives the possibility of applying the edited option byte values, loading themfrom the device and saving them to a file.Doc ID 13916 Rev 717/25Figure 11.Option byte edition pageb) Case of any other operation:The operation page is shown. It gives the size of the data to be downloaded oruploaded, the percent completed and the duration of the operation as illustrated inFigure12.●If the operation is successful, the progress bar is green colored. If an error occurs, thebar turns red and the error is displayed.●To stop the operation click the “Cancel” button.●If the “Jump to the user program” check box was checked in the previous step (Step 4),and the user program was successfully downloaded, communication with the systemmemory boot loader is lost. Consequently, the “Back” button is redirected to the“Connection settings page” (Step 1) to avoid the launch of a new operation.If the “Jump to the user program” check box was not checked in Step 4, the “Back”button is still active and you can return to Step 4 and select a new operation.18/25 Doc ID 13916 Rev 7Figure 12.Operation progress pageDoc ID 13916 Rev 719/25Command-line usage UM046220/25 Doc ID 13916 Rev 73 Command-line usageThe command-line version (STMFlashLoader.exe ) provides the same functionality as theGUI. It supports several options in order to run a sequence of operations.The following paragraphs describe the available command-line options as shown inFigure 13.Figure mand-line versionSTMFlashLoader.exe option [Arguments] [option [Arguments]]...-?Shows help.-c:Defines the COM port.UM0462Command-line usage The -c option allows you to select the COM port that the command uses to communicatewith the target MCU. By default, the command uses COM1. T o select different COM portand connection settings, use the -c option in the form:-c--pn port_number (e.g 1, 2..., default 1)-c --br baud_rate (e.g 115200, 57600..., default 57600)-c--db data_bits (value in {5,6,7,8}..., default 8)-c--pr parity (value in {NONE,ODD,EVEN}..., default EVEN)-c--sb stop_bits (value in {1,1.5,2}..., default 1)-c--ec echo (value ON or OFF..., default is OFF)-c--to time_out ((ms) e.g 1000, 2000, 3000..., default 5000)The -c option supports multiple arguments. This means that you can set more than oneargument in the same command:-c --pn 1 --br 115200 --to 7000-i device_nameDefines the MCU target to be used.For example: STM8_32K, STM32_Med-density_128K, STM32_High-density_512K,STM32_Low-density_16K etc. The device name is the name of the map file located in theMap directory.-eErase command.According to the given arguments, the command can be used to erase a specific page ofmemory or, to erase the entire Flash memory. This operation can take a second or more tocomplete, depending on the memory size involved.-e --all erase all pages-e --sec number_of_pages_group pages_group_codes-e --sec 3 0 1 2 erases 3 groups of pages coded 0, 1 and 2-uUploads the Flash memory contents to the specified file (bin, hex or s19 file; the file type isrecognized by its extension), to specify a file use the -u option in the form:-u --fn file_name (full path name)-dDownloads the contents of the specified file into the MCU Flash memory at the specifiedaddress. To specify the file to be downloaded and the download address, use the -d optionin the form:-d --a address(hex) --fn file_name (full path name (bin, hex or s19 file); the file type isrecognized by its extension).The address is mandatory in the case of binary files and ignored in the case of hex and s19files.To verify the downloaded data, add the --v argument.To optimize and remove FF packets, use the --o argument.Doc ID 13916 Rev 721/25Command-line usage UM0462-oGets or sets option bytes.Use --get to read option bytes from the device and store values to a file.--get --fn file_name (full path name)Use --set to write option bytes to the device. The option bytes can be read from a file orgiven as values.--set --fn file_name (full path name)--set --vals --OPB hex_value (OPB in (User, RDP, Data0, Data1, WRP0, WRP1,WRP2, WRP3).The -o option can accept multiple arguments as shown below:-o --get get_file_name --set set_file_name-o --get get_file_name --set --vals --User 01 --RDP 5A --Data0 DE --Data1 EAWarning:When setting option bytes, if RDP is not equal to A5h, theread protection is activated, and all subsequent operationswill fail.22/25 Doc ID 13916 Rev 7UM0462Command-line usage-pActivates or deactivates the protection. It is used as shown below:-p --erp (Activate read protection)-p --drp (Deactivate read protection)-p --ewp number_of_pages_group pages_group_codes (activates the write protectionon the given page group codes)-p --dwp (disables the write protection)Warning:The --erp argument activates the read protection. Allsubsequent operations will fail. To avoid this kind of problem,use -p --erp as the last argument.-rPerforms a jump to the specified address. It is used as follows:-r --a address(hex)-RtsSets the COM RTS pin to either high or low level. It is used as follows:-Rts -- Hi-DtrSets the COM DTR pin to either high or low level. It is used as follows:-Dtr -- LoNote:Note that all command-line options found are executed IN ORDER. Thus, with a careful arrangement of the command-line options, you can perform a complicated sequence ofoperations using custom batch files.Doc ID 13916 Rev 723/25Revision history UM046224/25 Doc ID 13916 Rev 74 Revision historyTable 1.Document revision history DateRevision Changes 25-Oct-20071Initial release.05-Jun-20082Flash loader demonstrator version upgraded to V1.1.Small text changes.Section 1.1.1: Software contents updated. Section 1.2: Systemrequirements modified.Welcome step removed, Flash status page and Option byte editionpage added.Section 3: Command-line usage added.Step 2 on page 12 added. Step 5 on page 17 modified.17-Jun-20083Software revision updated in Section 1.3.1: Software installation onpage 7.31-Oct-20084Flash loader demonstrator version upgraded to V1.2. It can also beused with STM8 devices.Figure 5 to Figure 12 updated accordingly.04-Mar-20095Flash loader demonstrator version upgraded to V1.3. Figure 5 toFigure 12 updated accordingly.02-Jul-20096Flash loader demonstrator version upgraded to V2.0. This versionapplies not only to the STM32™ family but also to the STM8™ family.Section 1.1.1: Software contents updated (STUARTBLLib.dll andSTCANBLLib.dll added).Section 1.2: System requirements modified, Figure 2: DeviceManager window changed.Section 1.3.1: Software installation and Section 1.3.2: Hardwareinstallation updated.Step 1 and Figure 5: Connection settings page updated. Small textchanges.12-Nov-20097Flash loader demonstrator version upgraded to V2.1.0. Figure 1 toFigure 13 updated accordingly.Flash loader demonstrator is upgraded to support only UARTprotocol for STM8™ and STM32™ families.UM0462Please Read Carefully:Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.All ST products are sold pursuant to ST’s terms and conditions of sale.Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.ST and the ST logo are trademarks or registered trademarks of ST in various countries.Information in this document supersedes and replaces all information previously supplied.The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.© 2009 STMicroelectronics - All rights reservedSTMicroelectronics group of companiesAustralia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of AmericaDoc ID 13916 Rev 725/25。

相关文档
最新文档