cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H563 Custom External Loader Issues

lkantoski
Associate

I am trying to build a custom external loader for W25Q64 SPI. I am using the OCTOSPI1 using the follow pins.

PE11OCTOSPI1_NCS
PF6OCTOSPI1_IO3
PF7OCTOSPI1_IO2
PF8OCTOSPI1_IO0
PF9OCTOSPI1_IO1
PF10OCTOSPI1_CLK

I have followed the stm32-external-loader/Demo_Project as template. Currently I have no issue when making a example project using external loader function calls. I can read/write/erase without issue.

However, when the .stdr is used in STM32CubeProgrammer v2.17.0 GUI and command line it fails to do anything.

I get the following:

Reading data...
halt ap 1
w ap 1 reg 15 PC (0x20003000)
w ap 1 reg 17 MSP (0x20003500)
w ap 1 reg 16 xPSR (0x01000000)
Init flashloader...
halt ap 1
w ap 1 reg 0 R0 0x00000000
w ap 1 reg 1 R1 0x00000000
w ap 1 reg 2 R2 0x00000000
w ap 1 reg 3 R3 0x00000000
w ap 1 reg 4 R4 0x00000000
w ap 1 reg 5 R5 0x00000000
w ap 1 reg 6 R6 0x00000000
w ap 1 reg 7 R7 0x00000000
w ap 1 reg 8 R8 0x00000000
w ap 1 reg 9 R9 0x00000000
w ap 1 reg 10 R10 0x00000000
w ap 1 reg 11 R11 0x00000000
w ap 1 reg 12 R12 0x00000000
w ap 1 reg 13 SP 0x00000000
w ap 1 reg 14 LR 0x00000000
w ap 1 reg 15 PC 0x20003521
w ap 1 reg 16 xPSR 0x01000000
w ap 1 reg 17 MSP 0x00000000
w ap 1 reg 18 PSP 0x00000000
run ap 1
halt ap 1
r ap 1 reg 0 R0 0x00000000
Init function fail
r ap 1 reg 16 xPSR 0x01000003
halt ap 1
w ap 1 reg 15 PC (0x20003000)
w ap 1 reg 17 MSP (0x20003500)
w ap 1 reg 16 xPSR (0x01000000)
Error: failed to read the requested memory content

I believe this issue is something with LR and MSP registers not being assigned. However, I am not sure how to go about doing that. I have tried to added debug with LEDs, however it never enters the Init function. The PC appears to point to the Init function

Note: I only have access to STM32CubeIDE.

 

4 REPLIES 4

It's claiming it called Init() and you returned zero (fail code)

There's no static initialization occurring, so no startup.s, SystemInit() or main() being called. There shouldn't be a vector table, and you shouldn't be using interrupts.

You can perhaps use a UART to communicate, or a GPIO / LED in some form or fashion

The build basis for RAM should be 0x20003004, and not 0x20000004 (most) or 0x24000004 (H7)

RAM_PROG (xrw) : ORIGIN = 0x20003004, LENGTH = 256K-12292

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

https://github.com/cturvey/stm32extldr/tree/main/h5_w25q64

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lkantoski
Associate

Thank you for the support. 

 

I believe I found my issue.

After many build attempts, I determined there was a linker issues. I simplified my function calls to just return 1, CubeProgrammer still failed and list that my LR and MSP were both 0x00000000.

In my failing state I turned off "Discard unused sections" in the linker, to preserve my function calls. This appears to be what was causing my issue.

The solutions was:

Leave "Discard unused sections" enabled

In the linker script, add the following to the .text section

 

 

 

KEEP (*(.text.Init))
KEEP (*(.text.DeInit))
KEEP (*(.text.Write))
KEEP (*(.text.Read))
KEEP (*(.text.Verify))
KEEP (*(.text.Checksum))
KEEP (*(.text.SectorErase))
KEEP (*(.text.MassErase))

 

 

After building this way, my Init was no longer failing out and the LR and MSP were both real values.

Now I need to revert my code to make actual calls.

 

 

Yes, that's what I did with my example using GNU/GCC + MAKE in a free standing way.

https://github.com/cturvey/stm32extldr/blob/main/ExternalLoader_H5.ld

Might look at objdump to see what's kept, exported, or discarded.

@STTwo-32 can someone check if STM32 Cube Programmer reports issues/errors if the External Loader doesn't export Init or StorageInfo ? And perhaps explain or document the H5 use of the 0x20003004 RAM basis

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..