cancel
Showing results for 
Search instead for 
Did you mean: 

How to flash a board using a bash/python script

CHech.1
Associate III

Hi,

I'm using an STM32L496G board, currently flashing it through CubeMX/Touchgfx Designer.

In the future, i'd like to be able to flashthe board by running a bash/python/other script from a linux machine.

The board will be connected to the linux machine via uart.

I'm not sure how to do that, and I wasn't able to find helpful instructions online.

I'd appreciate your help.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
CHech.1
Associate III

My solution:

(script is obviously very basic and needs error checking etc.)

import os
 
CUBE_PROGRAMMER_CLI_PATH = 'C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin'
FILE_TO_DOWNLOAD_NAME = 'MyFlashes\\MyFile.elf'
CONNECTION_PORT = 'swd'
EXTERNAL_LOADER_PATH = 'MX25R6435F_STM32L496G-DISCO.stldr'
 
 
def main():
    os.chdir(CUBE_PROGRAMMER_CLI_PATH)
    os.system(f"STM32_Programmer_CLI.exe -c port={CONNECTION_PORT} -w {FILE_TO_DOWNLOAD_NAME} -v -el {EXTERNAL_LOADER_PATH}")
    os.system(f"STM32_Programmer_CLI.exe -c port={CONNECTION_PORT} -hardRst")
 
if __name__ == '__main__':
    main()

View solution in original post

4 REPLIES 4
KnarfB
Principal III

There are command line tools available: openOCD and stlink-tools.

hth

KnarfB

TDK
Guru

STM32CubeProgrammer has a command line interface (CLI) available as well. That's probably the simplest.

https://www.st.com/resource/en/user_manual/dm00403500-stm32cubeprogrammer-software-description-stmicroelectronics.pdf

If you feel a post has answered your question, please click "Accept as Solution".
Imen.D
ST Employee

Hello @CHech.1​ ,

Were you able to resolve the issue you described in this post ?

If yes, please share the final solution you found and mark the reply as Best answer.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
CHech.1
Associate III

My solution:

(script is obviously very basic and needs error checking etc.)

import os
 
CUBE_PROGRAMMER_CLI_PATH = 'C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin'
FILE_TO_DOWNLOAD_NAME = 'MyFlashes\\MyFile.elf'
CONNECTION_PORT = 'swd'
EXTERNAL_LOADER_PATH = 'MX25R6435F_STM32L496G-DISCO.stldr'
 
 
def main():
    os.chdir(CUBE_PROGRAMMER_CLI_PATH)
    os.system(f"STM32_Programmer_CLI.exe -c port={CONNECTION_PORT} -w {FILE_TO_DOWNLOAD_NAME} -v -el {EXTERNAL_LOADER_PATH}")
    os.system(f"STM32_Programmer_CLI.exe -c port={CONNECTION_PORT} -hardRst")
 
if __name__ == '__main__':
    main()