# STM32 In-System Programming (ISP) > [name= Adcantech Barry.Chung] ###### tags: `STM32` ## Bootloader * IC内部有一塊特別的區域,晶片出廠時在這個區域設置了一段Bootloader,就是常說的ISP程序。 * 在這特別的區域的內容,在IC出廠後沒有人能夠修改或擦除,因為寫死在ROM裡面。。 ## STM32L05xxx/06xxx devices bootloader * [STM32 microcontroller system memory boot mode - AN6206](https://www.st.com/resource/en/application_note/cd00167594-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf) * The STM32L05xxx/06xxx bootloader is activated by applying Pattern 1 (described inTable 2: Bootloader activation patterns). The following table shows the hardware resources used by this bootloader. ![](https://i.imgur.com/J2ilOjw.png) ![](https://i.imgur.com/cxGFiay.png) ### Bootloader selection * The figure below shows the bootloader selection mechanism. ![](https://i.imgur.com/ToNYXCd.png) ## STM32L47xxx/48xxx devices bootloader * AN2606 Application note * [STM32 microcontroller system memory boot mode - AN6206](https://www.st.com/resource/en/application_note/cd00167594-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf) * Two bootloader versions are available on STM32L47xxx/48xxx: * V10.x supporting USART, I2C and DFU (USB FS Device). * This version is embedded in STM32L47xxx/48xxx rev. 2 and rev. 3 devices. * V9.x supporting USART, I2C, SPI, CAN and DFU (USB FS Device). * This version is embedded in STM32L47xxx/48xxx rev. 4 devices. ### Bootloader configuration * The STM32L47xxx/48xxx bootloader is activated by applying Pattern 7 (described in Table 2: Bootloader activation patterns). The following table shows the hardware resources used by this bootloader. ![](https://i.imgur.com/gYjJxUE.png) ![](https://i.imgur.com/oF5Jndn.png) * For USARTx and I2Cx bootloaders no external clock is required. * USB bootloader (DFU) requires either an LSE (low-speed external clock) or a HSE (highspeed external clock): * In case, the LSE is present regardless the HSE presence, the MSI is configured and trimmed by the LSE to provide an accurate clock equal to 48 MHz which is the clock source of the USB. The system clock is kept clocked to 24 MHz by the HSI. * In case, the HSE is present, the system clock and USB clock is configured respectively to 24 MHz and 48 MHz with HSE as clock source. ![](https://i.imgur.com/DvWKg7y.png) ### Bootloader selection ![](https://i.imgur.com/Nw31AMA.png) ## [Ultra-low-power STM32L0x1 advanced Arm®-based 32-bit MCUs](https://www.st.com/resource/en/reference_manual/dm00108282-ultralowpower-stm32l0x1-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) ![](https://i.imgur.com/yK76CRu.png) ![](https://i.imgur.com/mFIbnfB.png) ## [STM32L4+ Series advanced Arm®-based 32-bit MCUs](https://www.st.com/resource/en/reference_manual/dm00310109-stm32l4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) ![](https://i.imgur.com/eNRNkKE.png) ### UART ![](https://i.imgur.com/EkLVobC.png) ### I2C ![](https://i.imgur.com/cIS8jHA.png) ## [ISP for winwods](https://www.st.com/en/development-tools/flasher-stm32.html) ### STM32F103C8T6 * 需跳線 boot0 0 1 * boot1 1 0 ![](https://i.imgur.com/FQdy7ZF.png) ### STM32L073RZ * 需先把 BOOT0 Push high ,外加一顆電組 * boot1 在STM32之後的設計更改為軟體。 * 早期的F系列開發版會設置 boot0 and boot1 * Open Flash Loader Demonstrator * commadns選完後,先按下mcu_rst,在按下畫面中 Next ![](https://i.imgur.com/mmfmgGj.png) ![](https://i.imgur.com/jLlew2h.png) ## [STM32flash ISP ARM LINUX](https://packages.ubuntu.com/search?keywords=stm32flash) ![](https://i.imgur.com/j3RLLYt.png) ### [STM32flash ISP command](http://manpages.ubuntu.com/manpages/bionic/man1/stm32flash.1.html) * sudo stm32flash -b 115200 /dev/ttyTHS1 * sudo stm32flash -w xx.bin -v -g 0x0 -b 115200 /dev/ttyTHS1 * 叮嚀 需要先把boot 拉hi 和 mcu RESRT LOW HI一次 * 在執行 stm32flash #### MIC-715PB FW update ``` /opt/tools/gpio_board.sh 7 1 # BOOT0 = “high” /opt/tools/gpio_board.sh 6 1 # assert MCU Reset sleep 0.1 /opt/tools/gpio_board.sh 6 0 ``` ![](https://i.imgur.com/kGL43V9.png) ![](https://i.imgur.com/4tMPrCN.png) ![](https://i.imgur.com/kJumbdf.png) ![](https://i.imgur.com/6OQU0s7.png) ![](https://i.imgur.com/bau7e5n.png) #### STM32flash 0.5 ![](https://i.imgur.com/jiDyTpL.png) ## make flash * 複製壓縮檔工具專案並產生壓縮檔,make 參數 a 是韌體檔案的位置,參數 b 是版本名稱 * 先把 .bin 放進 expample 目錄 * make a=example/MIC715PB-0805.bin b=0805 ``` barry@debian-8:~/mic715_mcu_upgrade$ make a=example/MIC715PB-0809.bin b=0809 rm -rf build/ mkdir -p build/mic715_mcu_0809/resource cp example/MIC715PB-0809.bin build/mic715_mcu_0809/resource cp source/main.sh build/mic715_mcu_0809 cp source/README build/mic715_mcu_0809 echo v0.1 > build/mic715_mcu_0809/tool_version echo 0809 > build/mic715_mcu_0809/firmware_version echo 20210818_102124 > build/mic715_mcu_0809/build_time cd build; tar cfj mic715_mcu_0809.tbz2 mic715_mcu_0809 cd build; md5sum mic715_mcu_0809.tbz2 > mic715_mcu_0809.md5sum done build/mic715_mcu_0809.tbz2 barry@debian-8:~/mic715_mcu_upgrade$ ``` ## 參考資料 * [flash loader下载使用说明](https://blog.csdn.net/weixin_40593838/article/details/107646070) * [STM32 的USART1(PA9、PA10)](https://www.jianshu.com/p/c5f14dd97628) * [STN32 UART FW update for Linux](https://wiki.oberon.org/ob/o7/stm32flash) * [关于STM32的BOOT0和BOOT1](https://blog.csdn.net/c12345423/article/details/52809527)