RAM, Heap and Stack for STM32 board

I am working on a project that requires at least 500 kB of memory. I have an SDK with this code defining a stack and a bunch, and it works fine.

Stack_Size EQU 0x00004000 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp ; <h> Heap Configuration ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; </h> Heap_Size EQU 0x00200000 AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base Heap_Mem SPACE Heap_Size __heap_limit 

However, I am trying to integrate the camera and LCD function in this SDK, and when I do, the highest stack and heap values ​​that at least will trigger the LCD screen are shown below. Any values ​​above this and the LCD screen remain black and the application does not work.

 Stack_Size EQU 0x00004000 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp ; <h> Heap Configuration ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> ; </h> Heap_Size EQU 0x00002B50 AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base Heap_Mem SPACE Heap_Size __heap_limit 

I need the stack and heap sizes in the second code example to match the sizes in the first code example so that I don't get stuck in the hard loop of error elimination due to lack of available memory. Why does increasing heap size make my project worse? Sense, why doesn’t it even work when I increase the heap size?

I added a screenshot of my project settings so that you can see the RAM configuration.

Screen shot

The following is the amount of memory. Doesn't that mean I have 2 MB of RAM?

An 8 M x ​​32-bit SDRAM connects to SDRAM Bank1 from the STM32F439NIH6 FMC interface.

1 Mbps x 16 SRAM is connected to bank1 NOR / PSRAM2 of the FMC interface and both 8-bit and 16-bit access are allowed by BLN0 and BLN1 connected to BLE and BHE SRAM respectively.

+6
source share
2 answers

Your STM32F4 microcontroller physically does not have 0x200000 (2 MB) RAM, starting at address 0x20000000. I believe that it has only 0x30000 (192 KB). Check the memory card section in the data table.

If you tell the linker that there is nonexistent memory, then the linker may try to use that memory, and then your program will crash. I suspect that for your original program, the linker never used non-existent memory, so the program worked successfully. But in your subsequent program, the linker tries to use non-existent memory, and the program crashes. Look at the map file generated by the linker to see how the various components of your program were assigned by the linker to memory. You will probably find that the first program does not use memory beyond 0x20030000, but the second program does.

If you really need 500 KB of memory or more, you will have to add an external storage device to your board, because the microcontroller does not have much RAM.

Update. If your board has memory connected to the FMC (flexible memory controller), then this is external or off-peak memory. However, external memory is not addressed to 0x20000000. It should be located somewhere in the range from 0x60000000 to 0xDFFFFFFF (see the section of the memory card data table). Your program will need to configure FMC properly before accessing external memory. And you should probably tell the linker that external memory exists by including one (or more) of these memory sections outside the chip in this settings dialog box. You can probably get detailed information and tips on how to enable extra-internal memory from the board designer.

+9
source

If you tell the linker that you have a 2-megabyte ROM chip and 2Mb + 64Kb of internal memory, you are lucky and we will be happy to find the code and data accordingly, but do not expect anything useful when you have a memory that does not exist!

If you correctly configured the memory areas, the linker will fail if you exceed the target capacity. This is a physical limit, the solution should not lie in the linker - it just generates a run-time error, not a build error.

0
source

Source: https://habr.com/ru/post/972758/


All Articles