2021-12-10 06:20 AM
Hello Everyone.
I'm currently trying to understand how the startup sequence (from power-on to main) of the STMs work.
As I always used the provided tools and files from ST I never had to deal with linker scripts, startup code etc.
This lack of knowledge always bothered me, so I decided to fill this gap.
I thought to make a small project where I don't use any of the ST files and write everything on my own to learn how the startup process actually works.
For this purpose, I created a very basic blinky LED project for a Nucleo-F072RB board, tested it with the common toolchain (CubeIDE and STM scripts & files) to make sure that the code is correct and then create the whole startup sequence on my own with the help of some online tutorials on this matter.
As I'm not familiar with assembly language I unfortunately couldn't take the ST files as a base (and because they are much more advanced as I want them to be for the start)
My toolchain is as follows:
Compiler: ARM (arm-none-eabi-gcc)
Build Utility: GNU Make
Programmer: CubeProgrammer
As the title of my question already suggests I was not able to get it working and therefore seeking your help.
I created a very basic makefile, a startup code where I set up the memory sections and provide the vector table, as well as a simple linker script. For the main code I created a small device header where I simply copied the necessary register defines from the official stm32f072xx.h.
The compilation works without issues and the map file also looks ok. I can see that the vector table is set up in the correct memory region (at least as far as my understanding goes).
But after looking at the GPIO registers I manipulate in my code, I can see that they are unchanged and therefore my code was not executed at all.
Because I have no experience with this, I don't have much ideas about what could cause the problem. But it seems that there is most probably still something wrong with the linker script or startup code.
So it would be much appreciated if someone could have a look at my files and help me finding the problem and get a better understanding of the whole process.
Thank you in advance
Best regards
Flo
2021-12-14 08:22 AM
I found a small error in the makefile and fixed it, but the behaviour remains the same (MCU was set to cortex-m4 instead of cortex-m0).
I also found the option to set the program counter to a certain address in the CubeIDE debugger and set it to 0x08000000. After that I went through step by step. Unfortunately it justs steps through the vector table and went right into the hardfault after executing the 4th instruction of main.
I even forced it to the address of the reset handler with the same result.
It looked like this:
2021-12-21 09:18 AM
Ok, it seems like it was a problem with the board and/or its initial programming.
I don't really know what happend, but the exact same project I posted before, works without issues right now.
I played around with the Linker Script and at somepoint during flashing I got an error and was not able to access the ST-Link anymore.
After I flashed a working project with the CubeIDE to get it working and tried again, I got the following message with the CubeProgrammer and after that everything works as I would expected it from the beginning.
I don't know what changed, I did a full flash erase before without any progress at all, but even after changing my linker script back to the "problematic" version, it now works fine.
Lastly I even tried a second Nucleo-Board fresh out of the box, I got the same error message/behaviour like shown in the picture and it also worked after this.
So yeah, the problem is solved even in a very unsatisfied way as I still don't know what caused the problem in the first case...