Part Number Hot Search : 
68801 66000 UPD17132 6029E MIC2568 T260XW01 SMPA48 A5800732
Product Description
Full Text Search
 

To Download AN4286 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  may 2014 docid024458 rev 2 1/38 AN4286 application note spi protocol used in the stm32 bootloader introduction this application note describes the spi pr otocol used in the stm32 microcontroller bootloader. it details each supported command. for more information about the spi hardware resources and requirements for your slave bootloader, refer to application note ?stm32 microcontroller system memory boot mode? (an2606). this document applies to the products listed in table 1 . table 1. applicable products product family product series microcontrollers stm32l0 series: ? stm32l051xx, stm32l052xx, stm32l053xx ? stm32l062xx, stm32l063xx stm32f4 series: ? stm32f401xx, stm32f411xx ? stm32f405xx, stm32f407xx ? stm32f415xx, stm32f417xx ? stm32f429xx, stm32f439xx www.st.com
contents AN4286 2/38 docid024458 rev 2 contents 1 spi bootloader code sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 bootloader command set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.1 safety of communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 get command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.3 get version command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4 get id command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.5 read memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.6 go command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.7 write memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.8 erase memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.9 write protect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.10 write unprotect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.11 readout protect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.12 readout unprotect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3 evolution of the bootloader pr otocol versions . . . . . . . . . . . . . . . . . . 36 4 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
list of tables AN4286 3/38 docid024458 rev 2 list of tables table 1. applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 table 2. spi bootloader commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 table 3. bootloader protocol versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 table 4. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
list of figures AN4286 4/38 docid024458 rev 2 list of figures figure 1. bootloader for stm32 with spi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 figure 2. get ack procedure (master side) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 figure 3. bootloader spi synchronization fr ame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 figure 4. spi command frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 5. read data frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 6. get command: master si de. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 figure 7. get command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 8. get version: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 9. get version: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 10. get id command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 11. get id command: slave side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 figure 12. read memory command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 figure 13. read memory command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 figure 14. go command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 figure 15. go command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 figure 16. write memory command: master si de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 figure 17. write memory command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3 figure 18. erase memory command: master si de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 19. erase memory command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 figure 20. write protect command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 figure 21. write protect command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 figure 22. write unprotect command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 figure 23. write unprotect command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 figure 24. readout protect command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 figure 25. readout protect command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 figure 26. readout unprotect command: master side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 figure 27. readout unprotect command: slave side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
spi bootloader code sequence AN4286 5/38 docid024458 rev 2 1 spi bootloader code sequence the stm32 bootloader is an spi slave. for all spi bootloader operations, the nss pin (c hip select) must be tied low. if the nss pin is tied high, the communication on the sp i bus will be ignored by the stm32 slave. figure 1. bootloader for stm32 with spi once the system memory boot mode is entered and the stm32 microcontroller has been configured (for more details, refer to your stm32 system memory boot mode application note) the bootloader code begins to scan the spi_mosi line pin, waiting to detect a synchronization byte on the bus (0x5a). on ce a detection occurs, the spi bootloader firmware waits to receive the acknowledge procedure (refer to figure 2 ) and then starts to receive master commands. 6wduw63,%rrwordghu :dlwirud frppdqg *hwfpg urxwlqh *hwfpg 5'fpg urxwlqh *2fpg urxwlqh -3wrbdgguhvv &rppdqg uhfhlyhg *rfpg :5fpg urxwlqh 6\qfkurql]dwlrq %\wh [$  uhfhlyhg" $fnqrzohgjh 069
docid024458 rev 2 6/38 AN4286 spi bootloader code sequence 37 figure 2. get ack proc edure (master side) to start communication with the bootloader, the master must first send a synchronization byte (0x5a) and wait to receive an acknowledge (ack). figure 3. bootloader spi synchronization frame where xx represents a dummy byte.  6hqg [ 5hfhlyh gxpp\ 6hqg gxpp\ 5hfhlyh ?gdwda ?gdwda [ " ?gdwda  [)" *hw$&. 6hqg [ 5hfhlyhgxpp\ <hv <hv 1r 1r $&. 1$&. (qg 069 gdwd 166 026, 0,62 [$ [$ [ [[ [[ [[ [ [ 6<1&e\wh *hw$&.riwkh6<1&e\wh 63,errwordghufrqqhfwhg 7lph   069
spi bootloader code sequence AN4286 7/38 docid024458 rev 2 figure 4. spi command frame to read any data, the master should send a dummy byte before starting to read data sent by the slave. this applies to all commands where a read is required. figure 5. read data frame 166 026, 0,62 [ [[ [[ [ $fn [ 6hqgvwduwriiudph wrnhq [$ *hw$&.riwkhfrppdqg   069 [$ [[ [[ [ &pgfrgh &pg;25 [ 6hqgfrppdqg frppdqg frghdqglwv;25fkhfnvxp frqwlqxh frppdqggdwd 166 026, 0,62 5hfhlyhgdwd vhqggxpp\hdfkwlph wruhfhlyhgdwd   069 [[ gdwd gdwd )luvwe\whlv gxpp\wrvwduw gdwduhfhswlrq frqwlqxh uhfhlyhgdwd frppdqg [[ [[ [[
docid024458 rev 2 8/38 AN4286 bootloader command set 37 2 bootloader command set table 2 lists the supported commands. each command is further described in this section. since the spi is configured in full duplex, each time the master transmits data on the mosi line, it simultaneously receives data on the miso line. since the slave?s answer is not immediate, the received data is ignored (dummy) while the master is transmitting (this data is not used by the master). when the slave has to transmit data, the master sends its clock, so it has to transmit data on the mosi line to be able to receive slave data on the miso line. in this case, the master should always send 0x00 (this data is not used by the slave). table 2. spi bootloader commands command (1) command code comma nd description get (2) 0x00 gets the version and allowed commands supported by the current version of the bootloader. get version (2) 0x01 gets the bootloader version. get id (2) 0x02 gets the chip id. read memory (3) 0x11 reads up to 256 bytes of memory starting from an address specified by the application. go (3) 0x21 jumps to user application code located in the internal flash memory. write memory (3) 0x31 writes up to 256 bytes to the memory starting from an address specified by the application. erase (3) 0x44 erases from one to all the flash memory pages or sectors using two- byte-addressing mode. write protect 0x63 enables write protection for some sectors. write unprotect 0x73 disables write prot ection for all flash memory sectors. readout protect 0x82 enables read protection. readout unprotect (2) 0x92 disables read protection. 1. if a denied command is received or an error occurs duri ng command execution, the bootloader sends a nack byte and goes back to command checking. 2. read protection ? when the rdp (read protection) option is acti ve, only this limited subset of commands is available. all other commands are nacked and have no effect on the slav e. once the rdp has been removed, the other commands become active. 3. please refer to stm32 product datasheet and an2606: stm32 mi crocontroller system memory boot mode to know which memory spaces are valid for this command.
bootloader command set AN4286 9/38 docid024458 rev 2 2.1 safety of communication all communication from the programming master to the slave is verifi ed in the following way. ? checksum: received blocks of data bytes ar e xored. a byte containing the computed xor of all previous bytes is added to the end of each communication (checksum byte). by xoring all received bytes, data + checks um, the result at th e end of the packet must be 0x00. ? if the received data is one byte, then its c hecksum is the bit negation of the value (the checksum of 0x02 is 0xfd). ? for each command, the master sends three bytes: a start of frame (sof = 0x5a), a byte representing the command value and it s complement (xor of the command and its complement = 0x00). ? each packet is either accepted (ack answer) or discarded (nack answer). ? ack = 0x79 ? nack = 0x1f note: the master?s frame can be one of the following. send command frame: the master initiates communication as master transmitter and sends two bytes to the slave: command code + xor. wait for ack/nack frame: the master initia tes an spi communication as master receiver and receives one byte from the slave: ack or nack. receive data frame: the master initiates an spi communication as master receiver and receives the response from the slave. the number of received bytes depends on the command. send data frame: the master initiates an spi communication as master transmitter and sends the needed bytes to the slave. the nu mber of transmitted bytes depends on the command. 2.2 get command the get command enables you to get the version of the bootloader and the supported commands. when the bootloader receives t he get command, it transmits the bootloader version and the supported command codes to the master, as described in figure 6 .
docid024458 rev 2 10/38 AN4286 bootloader command set 37 figure 6. get command: master side  6hqg&rppdqgiudph [[)) :dlwiru$&. ru1$&.iudph (qgri*hw 5hfhlyhgdwdiudph qxpehurie\whv errwordghuyhuvlrq olvwrivxssruwhgfrppdqgv 1$&. $&. 6wduw*hw :dlwiru$&. ru1$&.iudph 1$&. $&. 6hqg6wduw2i )udph [$  069
bootloader command set AN4286 11/38 docid024458 rev 2 figure 7. get command: slave side the stm32 sends the bytes as follows. ? byte 1: ack ? byte 2: n = 11 = the number of bytes to follow ? 1 except current and acks. ? byte 3: bootloader version (0 < version < 255), example: 0x10 = version 1.0. ? byte 4: 0x00 (get command) ? byte 5: 0x01 (get version) ? byte 6: 0x02 (get id) ? byte 7: 0x11 (read memory command) ? byte 8: 0x21 (go command) ? byte 9: 0x31 (write memory command) ? byte 10: 0x44 (erase command) ? byte 11: 0x63 (write protect command) ? byte 12: 0x73 (write unprotect command) ? byte 13: 0x82 (readout protect command) ? byte 14: 0x92 (readout unprotect command) 069  5hfhlyhgiudph [$[[))" 6hqg$&.iudph 6hqggdwdiudph qxpehurie\whvwrehvhqw errwordghuyhuvlrq olvwrivxssruwhgfrppdqgv 1r <hv 6wduw*hw (qgri*hw 6hqg1$&.iudph 6hqg$&.iudph
docid024458 rev 2 12/38 AN4286 bootloader command set 37 2.3 get version command the get version command is used to get the version of the spi protocol. when the bootloader receives the command, it transmits the information described below (bootloader version) to the master. figure 8. get version: master side the stm32 sends the bytes as follows: ? byte 1: ack ? byte 2: bootloader version (0 < version 255), example: 0x10 = version 1.0 ? byte 3: ack 6hqgfrppdqg iudph [[)(  :dlwiru$&. ru1$&.iudph (qgri*hw9huvlrq 5hfhlyhgdwdiudph  errwordghuyhuvlrq 1$&. $&. 6wduw*hw9huvlrq :dlwiru$&. ru1$&.iudph 1$&. $&. 6hqg6wduw2i )udph [$  069
bootloader command set AN4286 13/38 docid024458 rev 2 figure 9. get version: slave side 2.4 get id command the get id command is used to get the version of the chip id (identification). when the bootloader receives the command, it transmits the product id to the master. the stm32 slave sends the bytes as follows. ? byte 1: ack ? byte 2: n = the number of bytes ? 1 (n = 1), except for current byte and acks. ? bytes 3-4: pid ? byte 3 = msb ? byte 4 = lsb ? byte 5: ack 069 5hfhlyhgiudph  [$[[)(" (qgri*hw9huvlrq 6hqg$&.iudph 6hqggdwdiudph   errwordghuyhuvlrq 1r <hv 6wduw*hw9huvlrq 6hqg1$&.iudph 6hqg$&.iudph
docid024458 rev 2 14/38 AN4286 bootloader command set 37 figure 10. get id command: master side d^?e?s ^ v  }uu v (?u ~? ?= ? &  t]? (}?  < }? e < (?u  v }(' ?/ z] ?(?uw r vu? }(??? r r ??}?/  e <  < ^ ???' ?/  t]? (}?  < }? e < (?u e <  < ^ v ^ ???k ( & ?u ~??
bootloader command set AN4286 15/38 docid024458 rev 2 figure 11. get id command: slave side 2.5 read memory command the read memory command is used to read data from any valid memory address in the ram, flash memory and information block (system memory or option byte areas). when the bootloader receives the read memory command, it transmits the ack byte to the application. after transmission of the ack byte, the bootloader waits for an address (4 bytes, byte 1 being the address msb and byte 4 being the lsb) and a checksum byte, then it checks the received address. if the address is valid and the checksum is correct, the bootloader transmits an ack byte; otherwise it transmits a nack byte and aborts the command. when the address is valid and the checksum is correct, the bootloader waits for the number of bytes to be transmitted (n bytes) and fo r its complemented byte (checksum). if the checksum is correct, it transmits the needed data to the application, starting from the received address. if the checksum is not co rrect, it sends a nack before aborting the command. 069 5hfhlyhgiudph  [ $[  [)'" (qgri*hw,' 6hqg$&.iudph 6hqggdwdiudph  qxpehurie\whv  surgxfw,' 1r <hv 6wduw*hw,' 6hqg1$&.iudph  6hqg$&.iudph
docid024458 rev 2 16/38 AN4286 bootloader command set 37 the master sends bytes to the stm32 as follows. ? start of frame: 0x5a ? bytes 1-2: 0x11+0xee ? wait for ack (as described in section 1) ? bytes 3 to 6: start address (byte 3: msb, byte 6: lsb) ? byte 7: checksum: xor (byte 3, byte 4, byte 5 and byte 6) ? wait for ack (as described in section 1) ? byte 8: number of bytes to be read - 1 (0 < n 255); ? byte 9: checksum: xor byte 8 (complement of byte 8) figure 12. read memory command: master side 069    6hqgfrppdqg iudph [[((  :dlwiru$&. ru1$&.iudph (qgri5hdg0hpru\ 6hqggdwdiudphvwduwdgguhvv e\whv zlwkfkhfnvxp 5hfhlyhgdwdiudph qhhghggdwdiurpwkh%/ 6hqggdwdiudphqxpehurie\whvwreh uhdg e\wh dqgdfkhfnv xp e\wh 1$&. $&. 6wduw5hdg 0hpru\ :dlwiru$&. ru1$&.iudph 1$&. $&. :dlwiru$&. ru1$&.iudph 1$&. $&. 6hqg6wduw2i )udph [$ 
bootloader command set AN4286 17/38 docid024458 rev 2 figure 13. read memory command: slave side 069    6hqg$&.iudph (qgri5hdg0hpru\ 5hfhlyhgdwdiudphvwduwdgguhvv e\whv zlwkfkhfnvxp 6wduw5hdg0hpru\ &khfnvxp2. " 1r <hv $gguhvvydolg  fkhfnvxp2. " 1r 5hfhlyhgiudph  [ $ [  [(( 5'3dfwlyh " 1r <hv <hv 1r <hv 6hqg$&.iudph 5hfhlyhgdwdiudphqxpehurie\whvwreh uhdg e\wh dqgdfkhfnvxp e\wh  6hqg$&.iudph 6hqggdwdiudph uhtxhvwhggdwdwrwkhkrvw 6hqg1$&.iudph
docid024458 rev 2 18/38 AN4286 bootloader command set 37 2.6 go command the go command is used to execute the downloaded code or any other code by branching to an address specified by the application. when the bootloader receives the go command, it transmits the ack byte to the applicatio n. after transmission of the ack byte, the bootloader waits for an address (4 bytes, byte 1 being the address msb and byte 4 the lsb) and a checksum byte, then it checks the receiv ed address. if the address is valid and the checksum is correct, the bootloader transmits an ack byte; otherwise it transmits a nack byte and aborts the command. when the address is valid and the checksum is correct, the bootloader firmware performs the following. ? initializes the registers of the peripherals us ed by the bootloader to their default reset values. ? initializes the user applic ation?s main stack pointer. ? jumps to the memory location programmed in the received ?address + 4? (which corresponds to the address of the application?s reset handler). for example, if the received address is 0x08000000, the bootloader jumps to the memory location programmed at address 0x08000004. in general, the master should send the base ad dress where the application to jump to is programmed. note: the jump to the app lication works only if the user application sets the vector table correctly to point to the application address. the master sends bytes as follows to the stm32. ? start of frame: 0x5a ? byte 1: 0x21 ? byte 2: 0xde ? wait for ack (as described in section 1) ? byte 3 to byte 6: start address ? byte 3: msb ? byte 6: lsb ? byte 7: checksum: xor (byte 3, byte 4, byte 5 and byte 6)
bootloader command set AN4286 19/38 docid024458 rev 2 figure 14. go command: master side 069   6hqgfrppdqg iudph [['(  :dlwiru$&. ru1$&.iudph (qgri*2 6hqggdwdiudph6wduw$gguhvv e\whv dqgfkhfnvxp 1$&. $&. 6wduw*2 :dlwiru$&. ru1$&.iudph 1$&. $&. 6hqg6wduw2i )udph [$ 
docid024458 rev 2 20/38 AN4286 bootloader command set 37 figure 15. go command: slave side 2.7 write memory command the write memory command is used to write data to any valid memory address (see note below) of the ram, flash memory or option byte area. when the bootloader receives the write memory command, it transmits the ack byte to the application. after transmission of the ack byte, the bootloader waits for an address (4 bytes, byte 1 being the address msb and byte 4 being the lsb) and a checksum byte, and then checks the received address. if the received address is valid and the checksum is correct, the bootloader transmits an ack byte; otherwise it transmits a nack byte and aborts the command. when the address is valid and the checksum is correct, the bootloader then does the following. ? gets a byte, n, which contains the number of data bytes to be received. ? receives the user data ((n + 1) bytes) an d the checksum (xor of n and of all data bytes). ? programs the user data to memory starting from the received address. 069    5hfhlyhgiudph [ $[ ['( " -xpswrxvhudssolfdwlrq 6hqg$&.iudph 5hfhlyhgdwdiudphvwduw dgguhvv e\whv dqgfkhfnvxp 1r <hv 6wduw*2 6hqg$&.iudph 6hqg1$&.iudph 5'3dfwlyh" <hv 1r $gguhvvydolg  fkhfnvxp2. " 1r (qgri*2 <hv
bootloader command set AN4286 21/38 docid024458 rev 2 at the end of the command, if the write operatio n is successful, the bootloader transmits the ack byte; otherwise it transmits a nack byte to the application and aborts the command. if the write memory command is issued to the option byte area, all options are erased before writing the new values, and at the en d of the command the bootloader generates a system reset to take into account the new configuration of the option byte. the start address and the maximum length of the block to be writ ten in the option byte area has to respect the address and size of the product?s option bytes. if the write memory destination is the flash memory then the master has to wait enough time for the sent buffer to be written (refer to product datasheet for timing values) before polling for a slave response. note: the maximum length of the block to be written in the ram or flash memory is 256 bytes. write operations to the flash memory must be word (16-bit) aligned and data should be in multiples of two bytes. if less data is written, the remaining bytes shou ld be filled by 0xff. when writing to the ram, you should take care not to overlap the first ram memory used by the bootloader firmware. no error is returned when performing write operations in write-protected sectors. the master sends the bytes to the stm32 as follows. ? start of frame: 0x5a ? byte 1: 0x31 ? byte 2: 0xce ? wait for ack (as described in chapter 1 ): ? byte 3 to byte 6: start address ? byte 3: msb ? byte 6: lsb ? byte 7: checksum: xor (byte3, byte4, byte5, byte6) ? wait for ack (as described in chapter 1 ) ? byte 8: number of bytes to be received (0 < n 255) ? n +1 data bytes: (max 256 bytes) ? checksum byte: xor (n, n+1 data bytes)
docid024458 rev 2 22/38 AN4286 bootloader command set 37 figure 16. write memory command: master side note: in some operating conditions, the master has to wait for a delay of 1 ms after receiving the acknowledge and before sending the data frame (number of bytes to be written, data to be written and checksum). 069  6hqgfrppdqgiudph [[&(  :dlwiru$&. ru1$&.iudph (qgri:ulwh0hpru\ 6hqggdwdiudph   qxpehurie\whvwrehzulwhq gdwdwrehzulwwhq  fkhfnvxp 1$&. $&. 6wduw:ulwh0hpru\ :dlwiru$&. ru1$&.iudph 1$&. :dlwiru$&. ru1$&.iudph 1$&. $&. 6hqggdwdiudphvwduw dgguhvv e\whv zlwk fkhfnvxp $&. 6hqg6wduw2i )udph [$ 
bootloader command set AN4286 23/38 docid024458 rev 2 figure 17. write memory command: slave side 069    ^v<(?u v}(t?]?du}?? z]?(?uw??????? ~e???]?zzl?u ^???t?]?du}?? zl?uk<m 1r <hv ???o]? zl?uk<m 1r z](?u zw?] e} <hv <hv 1r <hv ^v<(?u z]?(?uw r vu?}(????}?]??v r??}?]??v rzl?u ^ve<(?u t?]??z?]??} uu}??(?}u?z???? ??? ^v<(?u 'v??????u??? ? ?]??v]v k??]}v???m 1r <hv ??=??=?m
docid024458 rev 2 24/38 AN4286 bootloader command set 37 2.8 erase memory command the erase memory command allows the master to erase the flash memory pages or sectors using two-byte addressing mode. when the bootloader receives the erase memory command, it transmits the ack byte to the ma ster. after transmission of the ack byte, the bootloader receives two bytes (number of pages or sectors to be erased), the flash memory page codes (each one coded on two bytes, m sb first) and a checksum byte (xor of the sent bytes). if the checksum is correct, the bootloader erases the memory and sends an ack byte to the master. otherwise it sends a nack byte to the master and the command is aborted. erase memory command specifications the bootloader receives two bytes that contain n, the number of pages or sectors to be erased. ? for n = 0xfffy (where y is from 0 to f) a special erase is performed. ? 0xffff for a global mass erase. ? 0xfffe for a bank 1 mass erase (only fo r products supporting this feature). ? 0xfffd for a bank 2 mass erase (only for products supporting this feature). ? values from 0xfffc to 0xfff0 are reserved. ? for other values where 0 n < maximum number of pages or sectors: n + 1 pages or sectors are erased. the bootloader then receives the following. ? in the case of a special erase, one byte: checksum of the previous bytes: (that is, 0x00 for 0xffff). ? in the case of n+1 pages or sector erase, th e bootloader receives (2 x (n + 1)) bytes, each half-word containing a page number (coded on two bytes, msb first). then all previous byte checksums (in one byte). note: no error is returned when performing erase operations on write-protected sectors.the maximum number of pages or sectors is relative to the product and thus should be respected. the master sends bytes to the stm32 as follows. ? start of frame: 0x5a ? byte 1: 0x44 ? byte 2: 0xbb ? wait for ack (as described in section 1) ? bytes 3-4: ? special erase: global eras e (0xfffy where y={f, e, d}) or ? number of pages or sectors to be erased (n+1 where: 0 n < maximum number of pages or sectors). ? remaining bytes: ? checksum of bytes 3-4 in the case of a special erase (0x00, 0x01 or 0x02). or ? (2 x (n + 1)) bytes (page numbers coded on two bytes msb first) then the checksum for bytes 3-4 and all the following bytes).
bootloader command set AN4286 25/38 docid024458 rev 2 figure 18. erase memory command: master side 069 6hqgfrppdqgiudph [ [%& :dlwiru$&. ru1$&.iudph (qgri(udvh 1$&. $&. 6wduw(udvh :dlwiru$&. ru1$&.iudph $&. 6shfldo (udvh" 6hqggdwdiudph[)))[iru6shfldohudvh [)))wr[)))&duhuhvhuyhg  fkhfnvxpriwkhwzr%\whv 6hqggdwdiudphqxpehurisdjhvwr ehhudvhg1 rqwzre\whv 06%iluvw fkhfnvxpriwkhwzr%\whv 6hqggdwdiudphsdjhqxpehuv hdfkrqwzre\whv06%iluvw fkhfnvxp :dlwiru$&. ru1$&.iudph $&. 1$&. 1$&. 6hqg6wduw2i )udph [$ 
docid024458 rev 2 26/38 AN4286 bootloader command set 37 figure 19. erase memory command: slave side 069  6hqg$&.iudph (qgri(udvh 5hfhlyhqxpehurisdjhvwr ehhudvhg1 e\whv 06% iluvwfkhfnvxp 6wduw(udvh &khfnvxp2." 1r 6shfldo(udvh &pguhfhlyhg" 5hfhlyhgiudph [$[[%&" 5'3dfwlyh 1r <hv <hv 1r <hv 5hfhlyhgdwdiudphsdjh frghv rqe\whvhdfk06% iluvw fkhfnvxp  6hqg$&.iudph 6hqg1$&.iudph (udvhwkhfruuhvsrqglqjsdjhv <hv &khfnvxp2." 1r <hv 6hqg1$&.iudph 3huirup6shfldohudvh [)))[uhfhlyhg"  1r <hv &khfnvxp2." 1r <hv 1r
bootloader command set AN4286 27/38 docid024458 rev 2 2.9 write protect command the write protect command is used to enable the write protection for some or all flash memory sectors. when the bootloader receives the write protect command, it transmits the ack byte to the master. after transmission of the ack byte, the bootloader waits for the number of bytes to be received (sectors to be protected) and then receives the flash memory sector codes from the application. at the end of the write protect command, the bootloader transmits the ack byte and generates a system reset to take into account the new configuration of the option byte. the write protect command sequence is as follows. ? the bootloader receives one byte that contai ns n, the number of sectors to be write- protected - 1 (0 n 255) ? the bootloader receives (n + 1) bytes, each byte contains a sector code. note: the total number of sectors and the sector number to be protected are not checked, which means that no error is returned when a command is passed with a wrong number of sectors to be protected or a wrong sector number. if a second write protect command is executed , the flash memory sectors that had been protected by the first command become unprote cted and only the sectors passed within the second write protect command become protected.
docid024458 rev 2 28/38 AN4286 bootloader command set 37 figure 20. write protect command: master side 069  6hqgfrppdqgiudph [[& :dlwiru$&. ru1$&.iudph (qgri:ulwh3urwhfw 6hqggdwdiudphqxpehurivhfwruvwreh surwhfwhg e\wh fkhfnv xp 6hqggdwdiudphvhfwru frghvfkhfnvxp 1$&. $&. 6wduw:ulwh3urwhfw :dlwiru$&. ru1$&.iudph 1$&. $&. :dlwiru$&. ru1$&.iudph 1$&. 6hqg6wduw2i )udph [$ 
bootloader command set AN4286 29/38 docid024458 rev 2 figure 21. write protect command: slave side 069    6hqg$&.iudph (qgri:ulwh3urwhfw 5hfhlyhgdwdiudphqxpehurivhfwruv wrehsurwhfwhg e\whfkhfnv xp  6wduw:ulwh3urwhfw &khfnv xp2." 1r <hv 5hfhlyhgiudph  [$[[&" 523dfwlyh 1r <hv <hv 1r 5hfhlyhgdwdiudph vhfwrufrghvfkhfnv xp 6hqg$&.iudph *hqhudwhv\v whpuhvhw 6hqg1$&.iudph :ulwhsurwhfwwkhuhtxhvwhg vhfwruv &khfnv xp2." 1r 6hqg$&.iudph <hv
docid024458 rev 2 30/38 AN4286 bootloader command set 37 2.10 write unprotect command the write unprotect command is used to di sable the write protec tion of all the flash memory sectors. when the bootloader receives the write unprotect command, it transmits the ack byte to the master. after transmission of the ack byte, the bootloader disables the write protection of all the flash memory sect ors. after the unprotec tion operation, the bootloader transmits the ack byte. at the end of the write unprotect command, the bootloader transmits the ack byte and generates a system reset to take into account the new configuration of the option byte. figure 22. write unprotect command: master side d^?e?s? 6wduw:ulwh8qsurwhfw 6hqg6wduwri)udph [[& 6hqgfrppdqg)udph [[& :dlwiru$&. ru1$&.iudph (qgri:ulwh8qsurwhfw :dlwiru$&. ru1$&.iudph 1$&. $&. 1$&. $&.
bootloader command set AN4286 31/38 docid024458 rev 2 figure 23. write unprotect command: slave side 2.11 readout protect command the readout protect command is used to enab le the flash memory read protection. when the bootloader receives the readout protect command, it transmits the ack byte to the master. after transmission of the ack byte, the bootloader enables the read protection for the flash memory. at the end of the readout protect command, the bootloader transmits the ack byte and generates a system reset to take into account the new configuration of the option byte. 069   5hfhlyhgiudph [$[[&" (qgri:ulwh8qsurwhfw 6hqg$&.iudph 5hpryhwkhzulwhsurwhfwlrqiru wkhhqwluh)odvkphpru\ 1r <hv 6wduw:ulwh8qsurwhfw 6hqg$&.iudph 6hqg1$&.iudph 5'3dfwlyh" <hv 1r *hqhudwh6\vwhp5hvhw
docid024458 rev 2 32/38 AN4286 bootloader command set 37 figure 24. readout protect command: master side d^?e??s? 6wduw5hdg8qsurwhfw 6hqg6wduwri)udph [$ 6hqgfrppdqg)udph [[' :dlwiru$&. ru1$&.iudph (qgri5hdg8qsurwhfw :dlwiru$&. ru1$&.iudph 1$&. $&. 1$&. $&.
bootloader command set AN4286 33/38 docid024458 rev 2 figure 25. readout protect command: slave side 2.12 readout unprotect command the readout unprotect command is used to disable the flash memo ry read protection. when the bootloader receives the readout un protect command, it transmits the ack byte to the master. after transmission of the ac k byte, the bootloader erases all the flash memory sectors and it disables the read protec tion for the entire flash memory. if the erase operation is successful, the bootloader deactivates the rdp. if the erase operation is unsuccessful, the bootloader transmits a nack and the read protection remains active. the master has to wait enough time for the read protection disable (which is equivalent to the mass erase time on most products - refer to product datasheet for more information) before polling for a slave response. at the end of the readout unprotect command, the bootloader transmits an ack and generates a system reset to take into account the new configuration of the option byte. 069   5hfhlyhgiudph [$[['" (qgri5hdg3urwhfw 6hqg$&.iudph $fwlydwh5hdg3urwhfwlrqiru )odvk0hpru\ 1r <hv 6wduw5hdg3urwhfw 6hqg$&.iudph 6hqg1$&.iudph 5'3dfwlyh" <hv 1r *hqhudwh6\vwhp5hvhw
docid024458 rev 2 34/38 AN4286 bootloader command set 37 figure 26. readout unprotect command: master side d^?e??s? 6wduw5hdg8qsurwhfw 6hqg6wduwri)udph [$ 6hqgfrppdqg)udph [[' :dlwiru$&. ru1$&.iudph (qgri5hdg8qsurwhfw :dlwiru$&. ru1$&.iudph 1$&. $&. 1$&. $&.
bootloader command set AN4286 35/38 docid024458 rev 2 figure 27. readout unprotect command: slave side 069  5hfhlyhgiudph [$[['" (qgri5hdg8qsurwhfw 6hqg$&.iudph 'lvdeoh5hdg3urwhfwlrqiruwkh )odvk0hpru\ 6wduw5hdg8qsurwhfw 6hqg1$&.iudph *hqhudwh6\vwhp5hvhw &ohdu$oo5$00hpru\
docid024458 rev 2 36/38 AN4286 evolution of the bootloader protocol versions 37 3 evolution of the bootloader protocol versions table 3 lists the bootloader versions. table 3. bootloader protocol versions version description v1.1 updated the acknowledge mechanism. updated the get, getid, getversion and read commands. v1.0 initial bootloader version.
revision history AN4286 37/38 docid024458 rev 2 4 revision history table 4. document revision history date revision changes 27-mar-2014 1 initial release. 02-may-2014 2 updated table 1: applicable products . added footnote in table 2: spi bootloader commands . updated section 2: bootloader command set . updated figure 22 , figure 24 and figure 26 .
AN4286 38/38 docid024458 rev 2 please 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 he rein 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 as sumes 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. i f 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 whatsoev er 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 parti cular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. st products are not designed or authorized for use in: (a) safety critical applications such as life supporting, active implanted devices or systems wi th product functional safety requirements; (b) aeronautic applications; (c) automotive applications or environments, and/or (d) aerospace applications or environments. where st products are not designed for such use, the purchaser shall use products at purchaser?s sole risk, even if st has been informed in writing of such usage, unless a product is expressly designated by st as being intended for ?automotive, automotive safety or medical? industry domains according to st product design specifications. products formally escc, qml or jan qualified are deemed suitable for use in aerospace by the corresponding governmental agency. 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 whatsoev er, 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. ? 2014 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN4286

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X