cancel
Showing results for 
Search instead for 
Did you mean: 

Gcc does not initialize the "FS_Desc" structure..

Zanon.Luciano
Senior

Hi, I'm installing USB VCP communication, I generated the project with CubeMx, my board is configured as a device and I loaded the virtual com port as a Class for FS IP.

It happens that by compiling the program with GCC (True Studio) the "FS_Desc" structure is not loaded into ram (all pointers are at 0) and consequently when trying to use this structure the program crashes (Hard Fault).

The same program compiled with Keil works perfectly ...

Does anyone have any idea what happens?

I attach the True Studio screenshot with the breakpoint where the crash occurs.

0690X000008BYn3QAG.png

8 REPLIES 8
Pavel A.
Evangelist III

The startup module is wrong or missing? Link script is wrong?

> The same program compiled with Keil works perfectly ..

This is why we like Keil. It usually Just Works. Unlike some "free" stuff which costs nothing upfront, but later we pay more with our time and effort.

-- pa

I agree but free studio is a professional tool .....

The strange thing is that the FS_Desc structure is correctly viewed by Free Studio ...

0690X000008BYs3QAG.png

Then maybe the problem is in the startup module (the assembly one); it is responsible for initializing static data.

-- pa

Zanon.Luciano
Senior

Hi Pavel, thanks again for your reply.

I found the problem, it is a misalignment between LMA, VMA

 and loader, in fact I introduced in the linker script (.ld) an offset of 0x400 bytes and this can be seen in the screenshot where the initial VMA address for .data is 0x20000000 but the address of the first variable (ERT) is at 0x20000408.

However, the loader does not see this offset and only loads 0.4kb in area 0x20000000 ... 0x20000190, leaving all the structures from ERT forward uninitialized.

What I need to do now is instruct the loader that the initial address for the structures to load is 0x20000400 instead of 0x20000000.

I introduced the same offset in the keil scatterload file where I didn't make mistakes ....

Ah .... this is what happens when you use things like .ld and .sct files never used before ......

>>Ah .... this is what happens when you use things like .ld and .sct files never used before ......

That and the rather sophomoric implementation of the GNU statics initialization code to unpack the load regions, define the default stack address, and determine the heap size. The irony here is you probably have a better grasp of the end goal than the people that signed that code into the repository..

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

Hi Clive, it may be, I come from a good assembler programming experience.

> This is why we like Keil. It usually Just Works. Unlike some "free" stuff which costs nothing upfront, but later we pay more with our time and effort.

Oh please... Linux is free (and in runs the world - servers, super-computers, possibly your smartphone, your fridge, your car, your TV, there's a good chance they all have the Kernel inside), Git is free (literally every developer uses it nowadays), Nginx is free (it runs the majority of web servers), Firefox, Chromium, VLC, PostgreSQL, Redis, OpenCV, Blender, GCC, LLVM/Clang, R, Python... I can continue the list for hours.

Free software is already the present and surely the future of computing (if we don't lose the war on general purpose computing). Even the mastodons of closed/proprietary software embrace it, so go tell that free software stinks to Microsoft's execs, or Oracle's..

> rather sophomoric implementation of the GNU statics initialization code

I don't think that the sophomoric code comes from the GNU guys, they develop the compiler/linker/tools, they don't write *.ld or startup code for every processor they support. I just opened a random startup file (startup_stm32l031xx.s) generated by Cube - it isn't GPL licensed, and mentions "MCD Application Team" in the header comments as the author. If I should guess - it's either from ST or Atollic (currently the same thing).