cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-N657X0-Q unable to upload code

D4v1dV4c
Associate II

I have been trying for hours to upload code to the STM32-N6 and I am simply out of ideas. I only managed to upload debug code to RAM once, then I tried erasing the flash on the PCB using STM32CubeProgrammer (which worked, the standard code is not on there anymore) but now I cannot even use the debug option. Every time I try to upload code (I tried all BOOT pin combinations) it simply doesn't work. sometimes it has a timeout while trying to connect and really often I get the following output:

 

 

Starting server with the following options:
Persistent Mode : Disabled
Logging Level : 1
Listen Port Number : 7184
Status Refresh Delay : 15s
Verbose Mode : Disabled
SWD Debug : Enabled
InitWhile : Enabled

Info : default port : 7184
Info : Remote address: 127.0.0.1
Info : stlinkserver already running, exit
Target unknown error 32

Error in initializing ST-LINK device.
Reason: Unknown. Please check power and cabling to target.

 

I am using the 5V_STLK header connection for power. Right now, I cannot do anything with it anymore. not even running in dev mode works. Could the STM32N6 have gotten bricked when I tried to erase its flash? do I need an external ST-Link programmer to try and fix this?

I should also mention that, when trying to upload the firmware to the ST-Link, it failed multiple times before finally working (this was before the RAM loading worked the first time) and after that last time, I was able to upload the firmware 2 times with no problems.
I even tried using a converter between the controller and my laptop just in case the USB protocol was too fast or my laptop did anything weird with newer USB protocols.

System:
Apple Macbook Pro M4 with MacOS 26.2
STM32CubeMX v6.16.1
STM32CubeIDE v2.0.0
STM32CubeProgrammer v2.21.0

4 REPLIES 4
D4v1dV4c
Associate II

Some information I forgot:
Trying to connect using the STM32CubeProgrammer leads to it connecting, trying to read the flash, encountering some kind of error and then disconnecting. Every time.

 

Furthermore (since some might recommend this) I also tried adding the memory map (MX25UM51245G_STM32N6570-NUCLEO.stldr) with enable and initialize both turned on (and with enable on and initialize off)

I truly cannot think of any reason why it wont work. I would theoretically have an ST-Link to my disposal for a bit if I have to re-upload the firmware or something like that but I still need a fix which would let the PCB be programmed over the built-in ST-Link

Kouthair
ST Employee

Hello @D4v1dV4c,

Could you please provide the steps that you are performing using GUI or the command if you are using CLI?
Also, can you verify that the address that you are trying to program at starts from 0x70000000 with the appropriate external loader enabled?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
D4v1dV4c
Associate II

In previous tries I used the ST-Link GDB server setup inside the STM32CubeIDE to try and properly upload the code but it could never connect. I also noticed that the FSBL and Appli subprojects had 0x34000000 or something similar as addresses. After some trials and errors I ended up only using the build step in the STM32CubeMX project in CLion and then created the following shell script to upload the code:

#!/bin/bash
source ~/.zshrc

PROJECTNAME=$1
TARGET=$2
ARTIFACT_DIR="./${TARGET}/build"

# 1. Clean
rm -f "$ARTIFACT_DIR/${PROJECTNAME}_$TARGET.bin" "$ARTIFACT_DIR/${PROJECTNAME}_${TARGET}_signed.bin"

# 2. Extract RAW binary
arm-none-eabi-objcopy -O binary "$ARTIFACT_DIR/${PROJECTNAME}_$TARGET.elf" "$ARTIFACT_DIR/${PROJECTNAME}_$TARGET.bin"

# 3. Sign it
# -of 0x34180400 matches your Linker Script ROM Origin.
STM32_SigningTool_CLI -bin "$ARTIFACT_DIR/${PROJECTNAME}_$TARGET.bin" \
-o "$ARTIFACT_DIR/${PROJECTNAME}_${TARGET}_signed.bin" \
-t fsbl -hv 2.3 -nk \
-of 0x34180400 -align

# 4. Flash it
# ADDED: -rst at the end to force the boot process
STM32_Programmer_CLI -c port=SWD freq=2000 mode=UR \
-el "/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/ExternalLoader/MX25UM51245G_STM32N6570-NUCLEO.stldr" \
-w "$ARTIFACT_DIR/${PROJECTNAME}_${TARGET}_signed.bin" 0x70000000 -v

 

With this I first build the code using CLion, then I extract the binary code, sign it and upload it to the 0x70000000 address with a lower speed without using the GDB server. My only issue here is that I am forced to have my whole application inside the FSBL and I cannot have anything split between an FSBL and Appli. Right now I do not have such a big problem with this as it is the only thing that works and everything I tried worked properly. 

I should also mention that the STM32CubeIDE did have the proper stldr file loaded when trying to upload but it always used the GDB server and there is no option for direct uploading such as the one used in my shell script

D4v1dV4c
Associate II

Furthermore I would like to know the following:
If I were to initialize a project with an FSBL and an Appli, how would I go about programming the STM32N6 using something similar to the top? Can I somehow find out where the FSBL looks for the Appli inside an LRUN project template? Would it be safe to then take the binary of the Appli and write it at that location?

Is there a way of making it so after running the FSBL by loading it from 0x70000000 into RAM to really get it to load the Appli properly and run it?

What also interests me is if loading the Appli is truly necessary or if there is a way to combine the codes into each other to load the FSBL and Appli into RAM at the same time and have them run from there one after the other (I know that the Appli ELF/bin file also contains the vector table which would need to replace the FSBL vector table)

Can anyone lead me into the right direction on how I can create a proper application for the STM32N6 which I can upload to the external flash using the STM32_Programmer_CLI like shown in my previous comment? 

My idea was creating the shell script to build the code and write the FSBL and Appli right after the other but if I mark the Appli as an application and not as FSBL I need a way of making the FSBL load it like in the LRUN template