Skip to main content
MikeDB
Senior II
June 5, 2019
Solved

Declaring variables in SRAM1-3 areas of H7 devices in STM32CubeIDE

  • June 5, 2019
  • 11 replies
  • 4777 views

I've searched in all the obvious places but can't find any directive to tell the compiler to place some large arrays I have in the SRAM1, SRAM2 and SRAM3 memory segments. As these are not contiguous with the AXI memory I would assume I need to place arrays there manually.

Any hints most welcome.

This topic has been closed for replies.
Best answer by Andreas Bolsch

The setting you've to deal with seems to be quite difficult ... And you're probably right that with STM32CubeIDE or "pure" Eclipse there is little hope to solve that problem. In some way or another the IDE would have to be customized, either with an eclipse plugin or (what I'd would do as I'm not familar with eclipse internals) a makefile approach (to generate a linker script / startup file on the fly from 'comments' in the .c file). But both ways are apparently not feasible in your situation.

11 replies

Singh.Harjit
Senior
June 5, 2019

This article shows how to put different variables in different RAMs: https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices

Another article along the same lines: https://sigalrm.blogspot.com/2013/12/using-ccm-memory-on-stm32.html

MikeDB
MikeDBAuthor
Senior II
June 5, 2019

Thanks. I'd seen the first one and in the first example Keil has a menu to set up the various RAM sections but I've failed to find the equivalent in STM32CubeIDE, hence I assume I'll need to do it more manually in the code.

The only definite way I've found so far is to create pointers in the AXI memory to absolute addresses in the SRAM1/2/3 sections, but that seems a little long-winded if I could just tell the compiler to locate the arrays and variables in the SRAM sections directly.

Singh.Harjit
Senior
June 5, 2019

​I don't follow your comment about "The only definite way" and "absolute addresses".

If you assign the attribute to a variable and adjust the linker file, that variable will end up in the appropriate memory. You can still take the address and do all the normal things to the variable. In other words, applying the attribute and doing the linker change doesn't affect how you can use the variable.

For what it is worth, I've used this technique and it works just fine.

Andreas Bolsch
Lead III
June 5, 2019

STM32CubeIDE uses gcc, so you should read the relevant gcc docs: __attribute__ ((section("my_ram")) will place the corresponding variable in elf section "my_ram". Then add the appropriate section(s) to your linker script. For an example see e. g.

STM32Cube_FW_F7_V1.15.0/Projects/STM32746G-Discovery/Demonstrations/STemWin/SW4STM32/STM32F7-DISCO/STM32F746NGHx_FLASH.ld

BTW: That's already described in the first link Singh.Harjit provided. If your're not able to accomplish that without a "menu", perhaps you should find yourself a different occupation.

MikeDB
MikeDBAuthor
Senior II
June 5, 2019

I think your last comment is totally out of order as you have no idea what I am trying to achieve. The product I am designing needs to be customer-alterable and so I am trying to avoid as many complications for them as possible by using a fully integrated IDE with a complete configuration file.

Hand-modifications to the linker script could be lost at any time in the future and the customer would be stuck and need support.

Andreas Bolsch
Lead III
June 6, 2019

Well, admittedly my comment was a bit harsh. But please don't forget: You post a question because you want a solution/suggestion for your problem. Then it's your obligation to describe the problem precisely instead of more or less saying "I want a menu like in Keil". And definitely yes, I had no idea what your're trying to achieve. That's exactly my point ;)

But back to your problem: Surely there is a certain risk that a hand modified linker script gets lost or modified by chance, but the same applies for *ANY* file --- the .c file, the .h file and the project file / makefile. Moreover, it's fairly easy in most IDEs to accidentally modify one setting without realizing the overall implications. So, there is absolutely no way not to have reliable backup / versioning control, in particular as your users are supposed to modify the sources. And then, does it make any real difference whether you have three, four or seven files? If your users are able to modify the sources and flash the compiled firmware successfully, they're certainly able to keep a couple of files in a safe place as well.

Moreover the linker script has to be worked out only *once* for each device, as the available RAM sections are fixed in hardware, say with default data and bss sections in RAM1 and additionally two/four sections for RAM2 and RAM3. And, in case of initialized variables, the startup file must have the initilization code for all three sections (and enabling the RAM sections at the very beginning). Even this is fixed, no need for your customers to *ever* touch that.

All the remaining stuff will be contained in the .c file. Just add the corresponding attribute to the variables (mainly some large arrays, I guess) which should not go to the default place, i. e. RAM1.

MikeDB
MikeDBAuthor
Senior II
June 6, 2019

My question was quite clear in asking how do I set the location of the variables from the compiler. Most (all?) other MCU families have C extensions to provide this facility, even if they are GCC based. I am quite able to modify a linker file but my clients are not. I was hoping they could just install STM32CubeIDE, pull in the C and H files (as they would do with Microchip devices on Visual Studio) and hit Build as all the information the generic linker requires is in the .h file.

Indeed, would the average user even on this forum know where to put the linker file in STM32CubeIDE to ensure it was used rather than the default one ? And even once they've succeeded, programming the device isn't obvious unlike with Microchip. But unfortunately Microchip has fallen behind the curve on the M7 devices so it's STM or NXP. I'm still wondering if I made the wrong choice there.

In fact ST's STM32duino toolset does do what I require very well indeed, but it only supports low end MCUs. If that was extended to the high end it would be perfect. Thus the next best thing seemed to be STMCubeIDE which I hoped would have menus that I could just provide phone support to talk people through any hassles. I understand why many experienced programmers like command line driven Linux based toolsets, but I think if they had to support customers actually making changes, rather than just emailing a new memory image, they might see the advantage of fully integrated IDEs.

And trust me musicians don't understand what backups are :) As for version control, forget it. They always say that more great music has been lost due to overwriting the tapes/discs, not turning on the recording machine, recording on the wrong track, etc, than has ever been published. Even the keyboard techs aren't renowned for making backups and they are the people who often implement the changes. The complexity of modern music generation using customisable plug-ins for Pro Tools or numerous other DAW (Digital Audio Workstation) systems would astound many of the people on here, but the lack of discipline would equally horrify them.

Anyway another issue is I have spent all day playing with the linker files to try to optimize the design first and I noticed a couple of times that memory blocks with attributes weren't being placed where asked for so even that isn't 100% reliable. Still working on why this is, but it's becoming obvious that STM32CubeIDE is still miles from being ready for the field.

Andreas Bolsch
Andreas BolschBest answer
Lead III
June 9, 2019

The setting you've to deal with seems to be quite difficult ... And you're probably right that with STM32CubeIDE or "pure" Eclipse there is little hope to solve that problem. In some way or another the IDE would have to be customized, either with an eclipse plugin or (what I'd would do as I'm not familar with eclipse internals) a makefile approach (to generate a linker script / startup file on the fly from 'comments' in the .c file). But both ways are apparently not feasible in your situation.

MikeDB
MikeDBAuthor
Senior II
June 10, 2019

Actually a makefile approach sounds possible - I'll give it some thought. For now I've just declared all the small variables as members of a struct and allocated that to one of the SRAMs, but moving the stack to DTCM memory (where surely it should belong by default ?) without modifying the linker file seems to be impossible.

I originally looked at actually compiling and linking on the H750s themselves - they are each more powerful than early 1990s PCs we happily did this on all the time - but can't seem to find a suitable base to start with.

Garnett.Robert
Senior III
March 7, 2021

So,

ST Make chips with a large number of memory segments then forget to tell the people they have working on STM32CubeIDE that they need to provide a reasonable way to allocate the heap, stack, DMA buffers etc to the available memory blocks. So C/C++ programmers don't have to play around with internal files like the linker script. There seems to be some notion that you can't be a real C programmer unless you understand all the intricate details of the compilation process. If everyone needs to understand all the details of the compilers why have an IDE at all? Surely Notepad++ would suffice. All of the make files, linker scripts and the rest of it could all be created using notepad.

Given enough time we could all learn this stuff, but that's time we aren't producing useful custom code.

Keil uVision uses scatter files. A bit tedious, but available from, within the IDE, and quite simple and very flexible.