1. 首页
  2. 行业
  3. 嵌入式
  4. um0560_stm8_bootloader

um0560_stm8_bootloader

上传者: 2018-12-25 16:40:30上传 PDF文件 1.15MB 热度 41次
ST官方的BOOTLOADER,适用于STM8系列,里面有详细的协议说明,如果需要使用官方的bootloader,可以参考进行协议对接UM0560Contents3.8 Software model(STM8AF, STM8AL, STM8L and STM8S Series583. 8. 1 RAM erase/write routinesError management60Programming time.........,,,,,,,.,,..61Appendix a How to upgrade roP protected device62A 1 Rules for upgrading ROP protected devices,62Appendix B Bootloader entry points..............,..... 63Appendix c SPl peripheral timing options...……..…….….65C 1 SPI with busy state checking65C2 Modified erase/write RAm routines65Appendix d PC software support66Appendix E Bootloader UART limitation67E 1 Description■■■.67E.1.1 UART automatic baudrate calculation...67E.1.2 Description of UART limitation67E2 Workaround for UaRT limitation68Appendix F Limitations and improvements versus bootloader versions69Revision history∴....n,,,,,72DocID14798 Rev 103/75List of tablesUM0560List of tablesTable 1. stM8 groups featuring a bootloaderTable 2STM8 groups without bootloaderTable 3. Bootloader versions for which bootloader activation flowchart is validTable 4. Initial checking11Table 5Serial interfaces associated with stm8 devices12Table 6Bootloader commands16Table 7Bootloader codesTable 8. Examples of delay..39Table 9. stm8 sector codesTable 10. error table60Table 11. USART/LINUART/UART1/UART2/ART3 programming timesTable 12. SPI programming timeTable 13. CAN programming time6Table 14. Bootloader entry points..63Table 15. Description of limitation, improvements and added features:·69Table 16. Document revision history4/75DocD14798 Rev 10/UM0560List of fiquresList of figuresFigure 1. Bootloader activation flowchartFigure 2. CAN frame.14Figure 3. Get command via USART/LINUART/UART 1/UART2/UART3-host side17Figure 4. Get command via USART/LINUART/UART1/UART2/UART3-device side18Figure 5. Get command via SPI-host sideFigure 6. Get command via SPl-device side20Figure7. Get command via Can- host side21Figure 9Read memory command via USART/LINUART/UART1/UART2/UART3-host SI/ . ....22Figure 8. Get command via CAN-device sideFigure 10. Read memory command via USART/LINUART/UART1/UART2/UART3-device side.. 24Figure 11. Read memory command via SPl-host side25Figure 12. Read memory command via SPI-device sideFigure 13. Read memory command via CAN -host side28Figure 14. Read memory command via CAN-device side..28Figure 15. Erase memory command via USART/LINUART/UART1/2/3-host side...30Figure 16. Erase memory command via USART/LINUART/UART 1/2/3-device sideFigure 17. Erase memory command via SPl-host side......32Figure 18. Erase memory command via SPI-device side33Figure 19. Erase memory command via CAN- host sideFigure 20. Erase memory command via CAN-device side.35Figure 21. Write memory command via USART/LINUART/UART1/UART2/UART3-host side ... 37Figure 22. Write memory command via USART/LINUARTUART 1/2/3-device side38Figure 23. Write memory command via SPI-host side39Figure 24. Write memory command via SPI-device sideFigure 25. Write memory command via CAN- host side42Figure 26. Write memory command via CAN-device side,,,,43Figure 27. Speed command via CAN-host side.,..44Figure 28. Speed command via Can-device side.45Figure 29. Go command via USART/LINUART/UART1/UART2/UART3-host side46Figure 30. Go command via USART/LINUART/UART 1/UART2/UART3-device side47Figure 31. Go command via SPI-host side.48Figure 32. Go command via SPl-device side49Figure 33. Go command via Can -host side.50Figure 34. Go command via CAN-device sideFigure 35. delay elimination in modified RAM routines65Figure 36."Flash loader demonstrator"software66DocID14798 Rev 105/75Bootloader introductionUM0560Bootloader introductionThe main task of the bootloader is to download the application program into the internalmemories through the integrated peripherals(UARTS, SPl, or CAN)without using the SWIMprotocol and dedicated hardware. Data are provided by any device(host)that is capable ofsending information through one of the above-mentioned serial interfacesThe bootloader permits downloading of application software into the device memoriesincluding RAM, program and data memory, using standard serial interfaces. It is acomplementary solution to programming via the SWIM debugging interfacehe bootloader code is stored in the internal boot ROM memory. After a reset, thebootloader code checks whether the program memory is virgin or whether a specific optionbyte is set allowing code modificationsIf these conditions are not fulfilled the bootloader resumes and the user application isstartedIn case of a successful check the bootloader is executedWhen the bootloader procedure starts, the main tasks arePolling all supported serial interfaces to check which peripheral is usedProgramming code, data, option bytes and/or vector tables at the address(es)receivedfrom the hostEach STM8 device embeds a specific bootloader code which is common to a whole groupof STM8 devices. The correspondence between STM8 groups and STM8 part numbers isgiven in Table 1. These STM8 groups are used all over this user manualTable 1. STM8 groups featuring a bootloaderSTM8 groupSTM8 part numbersSTMBAF and stm8s SeriesSTM8AF52XX. STMBAF6269/8x/Axhigh densitySTM8AF5 1xX STM8AF6169/7x/8X/9x/AxSTM8S20XXX. STM8S007XXSTM8AF and stm8s seriesSTM8AF622X/4X. STM8AF6266/68medium densitySTM8AF612x/4x, STM8AF6166/68STM8S105xX. sTM8S005xxSTM8L and sambAl seriesSTM8L 15xx8. STM8L15XR6. STM8L16xX8high/medium+ densitySTM8L052R8. STM8AL318X, STMBAL3L8XSTM8AL31E8X, STMBAL3LE8XSTM8L 15xC4 STM8L15xK4. STM8L15xG4STM8 and stm8Al SeriessTM8L15×c6,STM8L15×K6,STM8L15XG6,medium densitySTM8L052C6. STM8AL313x, STM8AL314xSTM8AL316X. STM8AL3L. STM8AL3L6XSTM8L SeriesSTM8L 15XC2. STM8L15xK2. STM8L15XG2low densitySTM8L15XC3, STM8L15xK3. STM8L15xG3STM8LX151F3. STM8L050J3 STM8L051F36/75DocD14798 Rev 10/UM0560Bootloader introductionTable 2 gives the list of sTm8 devices without embedded bootloader(no rom bootloader isimplemented inside the microcontroller ) When using these devices, the user has to writehis own bootloader code and save it in the UBC program area(refer to STM8S, STM8AFSTM8L, STM8AL and STM8T Series reference manuals for information on the UBC areaTable 2. sTM8 groups without bootloaderSTM8 groupSTM8 part numbersSTMBAF and stm8s serieslow densitySTM8AF621x/2X, STM8Sx03XX, STM8S001xxSTM8L101 linelow densitySTM8L101XX. STM8L001XXSTM8T SeriesSTM8TL5XXXultra low-powerBootloader activationThe stM8 hardware reset vector is located at the beginning of the boot ROM(0X00 6000)while the other interrupt vectors are in the Flash program memory starting at address0x008004The device executes the boot RoM (jumps inside the boot Rom area )and after checkingcertain address locations (see Table 4: Initial checking on page 11), it starts to execute thebootloader or the user code defined by the reset vector(0x00 8000)The bootloader activation flowchart is described in Figure 1: Bootloader activation flowchart.In previous bootloader versions, a return to the "wait for SYNCHR "state(see dashed line inFigure 1)was performed when the "Flash virgin"test was positive. In newer versions, it hasbeen replaced by a software(sW)reset to prevent the customer firmware from remaining ina infinite loop(e. g. due to EMC disturbance). This bootloader modification is referred to asEMC lockup protection "in Table 15. Table 3 lists the bootloader versions for which thedashed line was replaced by a sw resetThe bootloader version number of a given device is obtained by the" Get command"(seeSection 3. 1: Get command). the bootloader version is represented by a two-digitbinary-coded decimal (BCD)numberwith a decimal point between the two digits)which iscoded into one byte in the "Get command" result. For example, 0x21 version byte isbootloader version 2.1Table 3 Bootloader versions for which bootloader activation flowchart is validSTM8 groupBootloader versionSTM8AF and stm8S Seriesv2.2high densitySTMBAF and sTm8s Series1.3medium densitySTM8L and stmAl Serieshigh/medium+ density1.0DocID14798 Rev 107/75Bootloader introductionUM0560Table 3. Bootloader versions for which bootloader activation flowchart is validSTM8 groupBootloader versionSTM8L and stmAL SeriesV1.2medium densitySTM8L Serieslow density8/75DocD14798 Rev 10/UM0560Bootloader introductionFigure 1. Bootloader activation flowchart(0×6000)Disable allinterrupt sources又2BLor is Flash memory virginYes3Is ROP activeemory is readout-protected)External clock present?4Wait 6ms for HSE crystalInitialize CANat 125 kbpsConfigure Hsi and initialize RxD UARTin GPIOmode(pull-up state).Configure SPI in slave modeSW resetWait 4ms for stabilization of pin statesNon-SYNCHR byte/message receivedTimeout(1sWait for SYNCHR66SYNCHR failedSYNCHR receivedSend Ack byte and disableIs Flash virginunused peripheralsNoRecover reset status6Wait forregistersa commanand receivedGET cmdRM crmdEM cmdWM cmdGO crndGET cmdRM cmdEM cmdWM cmd IcmdGo cmdroutineroutineoutineroutineroutineRemove em and wmroutines from ramFlash resetjump to host(0×6000addressMSv300833v21. See Flowchart description on page 10 for explanation of points 1 to 82. See Table 4: Initia/ checki3. Dotted routines are loaded in RAM by the host. they are removed by the go command before jumping to the Flash programmemory to executeplication4. Virgin Flash memory is tested according to the contents of address 0X8000. If [0X8000]==0X82 or OXAC, then the Flashmemory is not virginDocID14798 Rev 109/75Bootloader introductionUM0560Flowchart description1. Disable all interrupt sources2. The host can start the bootloader process according to checks shown in Table 4(inkeeping with the content of the first Flash program memory location(0x00 8000)andbootloader enable"option bytes). The host checks the following bootloader startconditionsCondition 1: the host checks if the device memory is empty by inspecting thecontent of address 0x00 8000(reset vector). If the content is not equal to 0X82 orOXAC, the device is recognized as being empty and the bootloader remains activeand waits for host commands without timeoutsCondition 2: the host checks if the bootloader option bytes (two bytes) are set toenable the bootloader or not the bootloader is enabled with a value of ox55aaand disabled by all other values(see the device datasheets for the bootloaderoption byte locations). If the option bytes are enabled the bootloader remainsactive and waits for host commands with a 1-second timeout If the host does notsend a command within this timeout, the bootloader jumps directly to theapplication user vector (jump to address 0X00 8000)Condition 3: if the option bytes disable the bootloader(by a value different from0x55AA), the bootloader jumps directly to the application user vector (jump toaddress0×008000)The above checking process is summarized in Table 43. When readout protection(ROP)is active, the Flash program memory is readoutprotected. In this case, the bootloader stops and the user application starts. If ROP isinactive, the bootloader continues to be executed (see Appendix A: How to upgradeROP protected device)4. The can peripheral can only be used if an external clock 8 MHz, 16 MHZ, or 24 MHz)is present. It is initialized at 125 Kbit/s. The UARTS and SPl peripherals do not requirean external clock. There is a 6 ms waiting time for HSE crystal stabilization5. Set the high speed internal RC oscillator(HSi)to 16 MHz and initialize the UARTsreceiver pins in input pull-up mode in the GPio registers. Initialize the spl in slavemode. Then, wait 4 ms for 1o pin voltage level stabilization. It is recommended that thehost waits 10 ms from the STM8 reset before sending the sYNChr byte/messageThis is the time needed for bootloader initialization6. Interface polling: The bootloader polls all peripherals waiting for a synchronizationbyte/message(SYNCHR =0x7F)within a timeout of 1 second. If a timeout occurs,either the Flash program memory is virgin in which case it waits for a synchronizationbyte/message in an infinite loop through a software reset, or the Flash programmemory is not virgin and the bootloader restores the registers reset status and jumpsto the memory address given by the reset vector (located at 0X00 8000). For thebootloader versions listed in Table 3, a software reset is generated after a timeout haselapsed, in case the Flash program memory is empty(this is because it is safer to stayin an infinite loop if there is a hardware chip error)NoteWhen synchronization fails( the bootloader receives a byte message different toSYNCHR =0X7F), two different situations can be distinguished according to the peripheralWith the UART peripherals, a device reset or power-down is necessary beforesynchronization can be tried again. Refer to Appendix E: Bootloader UART limitationWith the CAN or SPl peripheral, the user can continue to poll the interfaces untilasynchronization or a timeout occurs10/75DocID14798 Rev 10/
下载地址
用户评论
码姐姐匿名网友 2018-12-25 16:40:30

性价比不错,可以参考一下