cancel
Showing results for 
Search instead for 
Did you mean: 

Flashing a blank STM32

ym21
Associate II

I have an STM32L4R5ZI-P on a custom PCB. When designing the PCB I did not think far ahead enough and do my due diligence when it came to assigning and wiring pins on the STM32 in order to flash it. My design incorporates  USB D connected to my PCB which supplies power, and such, along with connections to USB_DM and USB_DP on my STM32. I did not wire BOOT0 or NRST. After looking online a bit, I heard that I must pull BOOT0 high and NRST low, allowing the STM32 to enter boot mode and then I can flash my STM32 via the DM and DP pins (using the CubeIDE and CubeProgrammer, etc.). I was just planning to jump BOOT0 to 3.3V and NRST to GND and then use my DM and DP pins on the USB to program is somehow using my PC. Am I thinking about this correctly? Is there an easier way to flash my virgin STM32 on my custom PCB? I do have a NUCLEO evaluation board for my specific STM32L4, which I have programmed and ran code on already. I was wondering if I can utilize the ST-LINK that is on the NUCLEO board to flash the virgin STM32 on my custom PCB. Any advice or pointers will help. Thank you

12 REPLIES 12
ym21
Associate II

I am not using an external loader for the STM32H Disco board, that was from a different post in a forum. I changed my .stldr file to the one that is shown below for the STM32L4. I have also linked the discussion where changing the .stldr file and my launch error (OpenOCD).

.stldr: https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/error-in-final-launch-sequence-for-stm32h745i-disco-board-again/td-p/57836
OpenOCD: https://community.st.com/t5/stm32cubeide-mcus/failed-to-start-gdb-server-error-in-initialising-st-link-device/td-p/132760

ym21
Associate II

Hello,

I wanted to update this thread with my progress and ask for advice and a path to move forward with my project. 

I decided to pursue the ST-LINK method to flash the STM32 on my PCB. I removed the ST-LINK jumpers and the jumper on JP4 on the ST-LINK (as shown in the uploaded figures), which removes the connected between the ST-LINK and the STM32 on the development board. I then connected CN5 to my target MCU as follows:
CN5 Pin 1 -> Unconnected
CN5 Pin 2 -> PA14 (SWCLK)
CN5 Pin 3 -> GND
CN5 Pin 4 -> PA13 (SWDIO)
CN5 Pin 5 -> NRST
CN5 Pin 6 -> PB3 (SWO)

After making these connections, I powered up my PCB and target STM32 via an external 3.3V supply with a current limit of 250 mA. I connected the ST-LINK to my laptop and opened STM32CubeProgrammer and my target MCU was able to be detected under Mode: Under Reset. I then proceeded to download my .elf file of the firmware I wanted to run and then I selected "Run after programming" and "Started Programming". I proceeded to receive messages that told me the flash was successful. As a way to check if I programmed the target STM32, I reconnected the jumpers on the ST-LINK to connect the ST-LINK back to the STM32 on the development board, I erased the chip memory on the STM32 on the development board via STM32CubeProgrammer, then reconnected the ST-LINK to the STM32 on the PCB and there was still memory on that chip, which made me think that I successfully flashed my target MCU (as shown in the uploaded images). I was wondering if this is a good indication, or a full validation that the STM32 on my PCB has been successfully flashed. Are there any other tests I can do?

My next step is to see if I can see some sort of output from the STM32 on my PCB now that it has supposedly been flashed with my firmware. To reiterate, I have USB_DM and USB_DP pins configured on my PCB. Does USB_OTG_FS facilitate UART capabilities? Would it be easier to use the debugger (SWO) that comes with the ST-LINK? 

Any advice, tips, or guidance would be greatly appreciated.

TDK
Super User

I think the question in the opening post has been answered. I'm not sure how much more I can provide.

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