cancel
Showing results for 
Search instead for 
Did you mean: 

Using more of RAM over ROM is better or not

DJ1
Associate III

Hi, I have been using PWM with DMA in one project with register-level programming, there i could find the RAM usage was around 28% and the ROM usage was hardly 0.5%. The similar application project when i tried with using HAL API's, I found the RAM usage was 6% and ROM usage was 3%. So i don't understand how there is so much difference when i use HAL over register level programming. At the same time using more of RAM is better or utilization of ROM is better?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> Also as you said register level uses less memory compared to HAL, that is true in case of ROM, but just not in case of RAM.

The map file can help you determine what is taking up space. Register-level coding doesn't use more RAM than HAL for the same code functionality. The size of buffers certainly doesn't change between the two.

> So what should be the solution for having larger dynamic buffer sizes in the code as they are going to be a part of RAM only and not ROM.

No magic solution here. You have a fixed amount of RAM, divvy it up however you need. If you need more, consider external SDRAM or similar for storage.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

7 REPLIES 7
TDK
Guru

Generally, using ROM is preferable since you have more of it, but it doesn't really matter as long as you have sufficient resources.

Using register-level programming should use less RAM and ROM than using HAL. If it's not, you're doing something very differently. Probably you have a large DMA array declared which isn't in or doesn't match the size in the HAL version.

If you feel a post has answered your question, please click "Accept as Solution".

While we can play the guess game, this is also an opportunity for you to learn how to find out where the memories go: have a look at the mapfile.

I often do projects where it's not clear beforehand how much resources would there be needed. In that case, I usually opt to spend FLASH and spare RAM, because as @TDK said above, RAM is a more scarce thus precious resource in mcus.

JW

DJ1
Associate III

Yep, i am using large DMA buffer size, roughly 226 * 3 (bytes). Also as you said register level uses less memory compared to HAL, that is true in case of ROM, but just not in case of RAM. So what should be the solution for having larger dynamic buffer sizes in the code as they are going to be a part of RAM only and not ROM.

Please do share some insights on this: @waclawek.jan.

TDK
Guru

> Also as you said register level uses less memory compared to HAL, that is true in case of ROM, but just not in case of RAM.

The map file can help you determine what is taking up space. Register-level coding doesn't use more RAM than HAL for the same code functionality. The size of buffers certainly doesn't change between the two.

> So what should be the solution for having larger dynamic buffer sizes in the code as they are going to be a part of RAM only and not ROM.

No magic solution here. You have a fixed amount of RAM, divvy it up however you need. If you need more, consider external SDRAM or similar for storage.

If you feel a post has answered your question, please click "Accept as Solution".
DJ1
Associate III

Hey, just looking for some heads up, where exactly can i find my memory map file?

This is toolchain-dependent; if you use some kind of IDE, surely documentation to that IDE will tell you. You may also need to tick some tickbox for the mapfile to be generated; again, toolchain-dependent.

JW

In STM32CubeIDE, it's in the same directory as the output ELF file, but with a MAP extension. It is created as part of the compilation process. It is a text file and can be viewed in a text viewer of your choice.

 

If you feel a post has answered your question, please click "Accept as Solution".