software,

RAM Computation for ARM Microcontroller

Follow Apr 20, 2016 · 3 mins read

RAM Computation for ARM Microcontroller

An ARM Cortex compiled bare metal application consists of the following sections.

  • text - shows the code and read-only data in your application (in decimal)
  • data - shows the read-write data in your application (in decimal)
  • bss - show the zero initialized (‘bss’ and ‘common’) data in your application (in decimal)
  • dec - total of ‘text’ + ‘data’ + ‘bss’ (in decimal)
  • hex - hexidecimal equivalent of ‘dec’

If there are no dynamic allocations in the application these section can help us determine the RAM requirements of the microcontroller.

klugadmin@klugserver:/mnt/hgfs/repos/arya_firmware/arya_main$ arm-none-eabi-size --format=berkeley build/src.elf
   text    data     bss     dec     hex filename
  96324     244    3460  100028   186bc build/src.elf

The Flash size and RAM size occupied by the compiled program can be estimated as below.

Occupied Flash size ≈ data size + bss size + text size
Occupied RAM size ≈ data size + bss size

For the above example the

occupied flash size is 244+3460+96324 =100046 ~100Kb
and RAM size is 244+3460=3700Bytes~3.7Kb

With RTOS 2 threads the RAM and flash utilizations are as follows

klugadmin@klugserver:/mnt/hgfs/repos/arya_firmware/arya_main$ arm-none-eabi-size -B -t build/src.elf
   text    data     bss     dec     hex filename
  99596     244    6496  106336   19f60 build/src.elf

For the above example the

occupied flash size is 244+6496+106376     =113116~113Kb
and RAM size is 244+6496=6740~6.7Kb

Thus RTOS library increases the RAM requirements by around 3KB

Each RTOS thread will allocate a default stack for each Thread which is 2048 bytes. The stack size must be sufficient hand all the allocations happening within the thread

The Regular threads constructor will use 172 bytes. 96 of these bytes are used for the _user_perthread_libspace.

Now, according to the MBED RTOS Memory Model, the Idle Thread, Timer Thread, and OS Scheduler also consume some RAM. This infor can be found in RTX_Conf_CM.c and each of them require 128Bytes

Thus for each mbed RTOS thread approximately 3KB RAM will be required.

Thus for an application consisting of 4 RTOS threads and user application we obtain RAM requirement to be 18KB

  • LCD (which will be used in the product) dimension: 176x220
  • LCD Aspect ratio: 1.25
  • Image size: 90x112 (Aspect ratio: 1.24)
  • Image data: 901122 = 20160 bytes
  • No. of rows to scale per row in image: 220/112 ~ 2 Hence buffer size required for scaling: 21762 (2 bytes for color) = 704 bytes ~ 0.69kB
  • Buffer size for LCD: 2500 (1/8th of image) ~ 2.4 kB
  • Buffer size for UART: 2500 (1/8th of image) ~ 2.4 kB
  • Total dynamic allocation: 5.5 kB
  • Total static allocation (computed from program size): 1.8 kB
  • Total RAM size required: 7.3kB

Image size: 50x66 (Aspect ratio: 1.32) Image data: 50662 = 6600 bytes

No. of rows to scale per row in image: 220/66 ~ 3 Hence buffer size required for scaling: 31762 (2 bytes for color) = 1056 bytes ~ 1kB

Buffer size for LCD: 6600 ~ 6.4 kB Buffer size for UART: 6600 ~ 6.4 kB

Total dynamic allocation: 13.8 kB Total static allocation (computed from program size): 1.8 kB Total RAM size required: 15.6kB


  • Image size: 30x37 (Aspect ratio: 1.23)
  • Image data: 30372 = 2220 bytes

  • No. of rows to scale per row in image: 220/37 ~ 6
  • Hence buffer size required for scaling: 61762 (2 bytes for color) = 2112 bytes ~ 2kB

  • Buffer size for LCD: 2220 ~ 2.2 kB
  • Buffer size for UART: 2220 ~ 2.2 kB

  • Total dynamic allocation: 6.4 kB
  • Total static allocation (computed from program size): 1.8 kB
  • Total RAM size required: 8.2 kB

Conclusion

Thus 30x37 is the image size we can go with current optimization with high degree optimization it may increase to 1.5x to 2x maximum size

but initial design specification will be 30x37 ,we will increase it if optimization permits it over the coming month

References

  • https://developer.mbed.org/questions/2065/RTOS-Memory-Usage-Confusion/
  • https://developer.mbed.org/questions/1280/Ram-usage-of-Threads/
  • https://developer.mbed.org/handbook/RTOS-Memory-Model
Written by