stm32的串口编程.pdf
《stm32的串口编程.pdf》由会员分享,可在线阅读,更多相关《stm32的串口编程.pdf(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、October 2010Doc ID 13588 Rev 81/16AN2557Application noteSTM32F10 x in-application programmingusing the USARTIntroductionAn important requirement for most Flash-memory-based systems is the ability to update firmware when installed in the end product.This ability is referred to as in-application progr
2、amming(IAP).The purpose of this application note is to provide general guidelines for creating an IAP application.The STM32100B-EVAL,STM32100E-EVAL,STM3210B-EVAL,STM3210E-EVAL and STM3210C-EVAL boards were used to validate the IAP driver.The STM32F10 x microcontroller can run user-specific firmware
3、to perform IAP of the microcontroller-embedded Flash memory.This feature allows the use of any type of communication protocol for the reprogramming process(such as CAN,USART,USB).USART is the example used in this application ContentsAN25572/16Doc ID 13588 Rev 8Contents1IAP overview .51.1Principle.51
4、.2IAP driver description.52Running the IAP driver.82.1HyperTerminal configuration .82.2Executing the IAP driver.93IAP driver menu.103.1Download image to the internal Flash memory .103.2Upload image from the internal Flash memory .113.3Execute the new program.113.4Disabling the write protection.114ST
5、M32F10 x IAP implementation summary.125User program conditions .146Revision history .15AN2557List of tablesDoc ID 13588 Rev 83/16List of tablesTable 1.STM32F10 xxx IAP implementation .12Table 2.Revision history .15List of figuresAN25574/16Doc ID 13588 Rev 8List of figuresFigure 1.Flowchart of the IA
6、P driver.7Figure 2.COM port properties.8Figure 3.IAP Driver menu when the STM32F10 x Flash memory is not protected.10Figure 4.IAP driver menu when the STM32F10 x Flash memory is write-protected.11Figure 5.Flash memory usage .14AN2557IAP overviewDoc ID 13588 Rev 85/161 IAP overviewLow-density devices
7、 are STM32F101xx,STM32F102xx,and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.Medium-density devices are STM32F101xx,STM32F102xx,and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.High-density devices are ST
8、M32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes.High-density devices are implemented in the STMicroelectronics STM3210E-EVAL evaluation board.Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.Connectivity line devic
9、es are implemented in the STMicroelectronics STM32100C-EVAL evaluation board.Low-density value line devices are STM32F100 x4 and STM32F100 x6 microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.Medium-density value line devices are STM32F100 x8 and STM32F100 xB microcontr
10、ollers where the Flash memory density ranges between 64 and 128 Kbytes.Medium-density value line devices are implemented in the STMicroelectronics STM32100B-EVAL evaluation board.XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 768 Kby
11、tes and 1 Mbyte.High-density value line devices are STM32F100 xC,STM32F100 xD and STM32F100 xE microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes.High-density value line devices are implemented in the STMicroelectronics STM32100E-EVAL evaluation board.1.1 PrincipleYou
12、should program the IAP driver to the Flash memory base address via the JTAG/SWD interface using the development toolchain of your choice or the factory-embedded boot loader in the System memory area.The IAP driver uses the USART to:Download a binary file from the HyperTerminal to the STM32F10 xs int
13、ernal Flash memory.Upload the STM32F10 xs internal flash memory content(starting from the defined user application address)into a binary file.Execute the user program.1.2 IAP driver descriptionThe IAP driver contains the following set of source files:main.c:where the USART initialization is set.A ma
14、in menu is then executed from the common.c mon.c:contains display functions and the main menu routine.The main menu gives the options of loading a new binary file,uploading a new binary file,executing the IAP overviewAN25576/16Doc ID 13588 Rev 8binary file already loaded and disabling the write prot
15、ection of the pages where the user loads his binary file(if they are write-protected).ymodem.c and download.c:they are used to receive the data from the HyperTerminal application(using the YMODEM protocol(a),and then to load them into the STM32F10 xs internal RAM.In the event of a failure when recei
16、ving the data,the“Failed to receive the file”error message is displayed.If the data is received successfully,it is programmed into the internal Flash memory from the appropriate address.A comparison between internal RAM contents and internal Flash memory contents is performed to check the data integ
17、rity.If there is any data discrepancy,the“Verification failed”error message is displayed.Other error messages are also displayed when the image file size is greater than the allowed memory space and when the user aborts the task.upload.c:it is used to transmit the STM32F10 xxx internal Flash memory
18、content started from the user application address using the ymodem protocol.STM32F10 x Standard Peripherals Library.To select the STMicroelectronics evaluation board STM32100B-EVAL(Medium density value line devices),STM3210C-EVAL(Connectivity line devices),STM3210E-EVAL(High density devices),STM3210
19、0E-EVAL(High-density value line devices)or STM3210B-EVAL(Medium-density devices)used to run the IAP,uncomment the corresponding line in stm32_eval.h file(under UtilitiesSTM32_EVAL)/#define USE_STM32100B_EVAL/#define USE_STM3210B_EVAL/#define USE_STM3210E_EVAL/#define USE_STM3210C_EVAL/#define USE_ST
20、M32100E_EVALThe user can choose to either go to the user application or execute the IAP for reprogramming purposes by pressing a push-button connected to a pin.Not pressing the push-button at reset switches to the user applicationPressing the push-button at reset displays the IAP main menuRefer to T
21、able 1.:STM32F10 xxx IAP implementation for more details about the STM32100B-EVAL,STM3210B-EVAL,STM3210E-EVAL,STM3210C-EVAL and STM32100E-EVAL board push-button used to enter the IAP mode.The IAP flowchart is represented in Figure 1.a.The Ymodem protocol sends data in 1024-byte blocks.An error check
22、 is performed in data blocks transmitted to the STM32F10 xxxs internal RAM to compare the transmitted and received data.Blocks unsuccessfully received are acknowledged with an NAK(Negative Acknowledgement).For more details about the Ymodem protocol,refer to existing documentation.AN2557IAP overviewD
23、oc ID 13588 Rev 87/16Figure 1.Flowchart of the IAP driver?Running the IAP driverAN25578/16Doc ID 13588 Rev 82 Running the IAP driverThe IAP driver is programmed in Flash memory:From page 0 to page 11 on Low-density devices,Medium-density devices,Low-density value line devices,and Medium-density valu
24、e line devices.From page 0 to page 5 on High-density,Connectivity line,XL density devices and High-density value line device.The user application occupies the remaining memory space.2.1 HyperTerminal configurationTo use the IAP,the user must have a PC running HyperTerminal or other Terminal program
25、that supports ymodem protocol as shown in Figure 2.In this document the HyperTerminal is used.The following figure shows the HyperTerminal configuration.Figure 2.COM port propertiesNote:The baud rate value of 115200 bps is used as an example.Care must be taken when selecting the system clock frequen
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- stm32 串口 编程
限制150内