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. 6 w d u w 6 3 , % r r w o r d g h u : d l w i r u d f r p p d q g * h w f p g u r x w l q h * h w f p g 5 ' f p g u r x w l q h * 2 f p g u r x w l q h - 3 w r b d g g u h v v & |