cancel
Showing results for 
Search instead for 
Did you mean: 

External loader for a custom board issues

Hello everyone!

I am trying to write a custom external loader for a custom board that has the STM32U5A9 microcontroller.

I tried following the guide from this forum post: How to implement and use your own external flash loader: An example using STM32U5A9J-DK and from the GitHub repository found here: https://github.com/STMicroelectronics/stm32-external-loader.

With those, I was able to build an external loader that is visible and usable in the STM32CubeProgrammer tool. However, every operation on the external memories when using it failed as I received errors that the operations could not be done.

So I set up to create a new project from the ground up by generating the STM32CubeIDE project from a STM32CubeMX project file and altering it to fit my needs. Again, I can get the build output to be usable by the STM32CubeProgrammer tool but this time I just stubbed the memory access functions so that they always return LOADER_OK (0x1). Even when configuring that each operation should succeed, the STM32CubeProgrammer reports that they fail.

Here's how the external loader looks like in the list of external loaders in STM32CubeProgrammer:

SakuGlumoffbittium_2-1724411770500.png

For example, if I try to invoke MassErase using STM32CubeProgrammer by clicking on this button:

SakuGlumoffbittium_3-1724411818753.png

I get the following output (verbosity level set to 3):

SakuGlumoffbittium_1-1724411283730.png

My implementation of the MassErase function is as follows:

int MassErase ( void )

{

return LOADER_OK;

}

And here's how the disassembly looks like for it:

20006800 <MassErase>:

* outputs :

* none

* Note: Optional for all types of device

*/

int MassErase ( void )

{

20006800: b480 push {r7}

20006802: af00 add r7, sp, #0

return LOADER_OK;

20006804: 2301 movs r3, #1

}

20006806: 4618 mov r0, r3

20006808: 46bd mov sp, r7

2000680a: f85d 7b04 ldr.w r7, [sp], #4

2000680e: 4770 bx lr

 

Based on the output from STM32CubeProgrammer, I suspect that R0 value should be either 1 (if OK) or 0 (if failed). Am I correct?

The disassembly for MassErase shows that the value 1 (OK) is written to R0 through R3 (or am I wrong?).

Also, it seems that the STM32CubeProgrammer sets the PC correctly to the MassErase function and that most likely means that the binary is built correctly. Am I correct?

Could you please clarify me how I can implement the MassErase function (in this case) in such a way that it succeeds?

That way when I implement the actual memory erasure, I can be sure that the implementation works and that the STM32CubeProgrammer doesn't give me false negatives.

0 REPLIES 0