PSOC4 Initial SRAM Consumption

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
WaSI_2022226
Level 1
Level 1

Hi all,

I,m working on a PSOC4 CY8C4245AXI-483. After create, configure and compile an empty project, I'm getting high SRAM usage.

Flash used: 3096 of 32768 bytes (9,4%).

SRAM used: 1616 of 4096 bytes (39,5%). Stack: 128 bytes. Heap: 128 bytes.

The map file shows that the compiler is using libc.a, but i've disabled the usage of libraries on Buld Settings:

Use Default Libraries = False

Use newlib-nano = False

Use newlib-nano Float Formating= False

.data.impure_data

                0x200000e0      0x428 c:/program files (x86)/cypress/psoc creator/4.2/psoc creator/import/gnu/arm/5.4.1/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv6-m\libc.a(lib_a-impure.o)

The GCC settings are these:

-nodefaultlibs -Wl,--gc-sections -g -ffunction-sections -Og -ffat-lto-objects -Wl,--end-group

What's wrong?

Regards.

0 Likes
1 Solution
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored
3 Replies
BiBi_1928986
Level 7
Level 7
First comment on blog 500 replies posted 250 replies posted

Hi.

Have you turned off Debug?

Is GCC compiler optimization options set for Speed or Size?

Is this a Bootloadable project or Normal project?

All above changes SRAM (and FLASH) usage.  Just some suggestions to look at.

Open the .map file and scroll down (or search) for 0x20000000.  This is the start of .ramvectors.  By adding up all the used bytes, you should reach 1616 SRAM byte used.

When I compiled an empty project, using same processor, Creator 3.1, this is what it generated  (I've deleted some lines to shorten the text):

Flash used: 776 of 32768 bytes (2.4 %).

SRAM used: 1404 of 4096 bytes (34.3 %). Stack: 1024 bytes. Heap: 128 bytes.

.ramvectors     0x20000000       0xc0

                0x20000000                __cy_region_start_ram = .

.noinit         0x200000c0        0x4

*(.noinit)

.noinit        0x200000c0        0x4 .\CortexM0\ARM_GCC_484\Release\Cm0Start.o

.data           0x200000c8       0x18 load address 0x000002f0

                0x200000c8                __cy_region_start_data = .

.jcr           0x200000c8        0x4 c:/program files/cypress/psoc creator/3.1/psoc creator/import/gnu_cs/arm/4.8.4/bin/../lib/gcc/arm-none-eabi/4.8.4/armv6-m/crtend.o

*(.data .data.* .gnu.linkonce.d.*)

.data          0x200000cc       0x10 .\CortexM0\ARM_GCC_484\Release\Design02.a(CyLib.o)

                0x200000cc                cydelay32kMs

                0x200000d0                cydelayFreqKhz

                0x200000d4                cydelayFreqMhz

                0x200000d8                cydelayFreqHz

                0x200000e0                . = ALIGN (0x8)

*fill*         0x200000dc        0x4

.bss            0x200000e0       0x20 load address 0x00000308

*(COMMON)

                0x20000100                . = ALIGN (0x8)

.heap           0x20000100       0x80 load address 0x00000308

                0x20000180                . = (. + 0x80)

.stack          0x20000c00      0x400

                0x20000c00                __cy_stack_limit = .

                0x20001000                . = (. + 0x400)

When I add up SRAM used, it does equal 1404 (in my example build).

For the most part, it's the Stack and Heap, that takes up most SRAM.

1024+128=1152

The rest is taken up with other variables for Vectors,Timers, fill bytes,2 sets of Load Addresses,

192+4+24+32=252

1152+252=1404 as reported by Creator.

Maybe I could reduce SRAM usage if I also disabled the library options.

[edit]


I changed the linker build settings similar to yours and I had the same result as you did.

I then set each of the libraries back to True (one-by-one) and found the Use newlib-nano = False is the culprit.  If you set this back to TRUE, less SRAM is used and the .data.impure_data will dissappear.

This appears to be a bug.

I hope somebody from Cypress will comment.

Bill

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

To utilize Cypress provided initialize and startup function it is better using

the default settings.

001-Build-Settings.JPG

And I think that the initial SRAM usage is more depending on the stack and heap size.

So in the Workspace Explorer > Project > Design Wide Resources > System

I tried to change

    Heap Size 0x80 > 0x10

    Stack Size 0x0400 > 0x0040

Although I'm not sure if this is practical, the result SRAM usage was 464 bytes (11.3%)

000-system.JPG

As the output said Stack 64 bytes Heap 16 bytes, rest of 384 byte must have been reserved for the library.

And IMHO, 384 does not seem to be very big for a 32 bit CPU.

moto

0 Likes
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Adding on to MoTa_728816 's reply; please have a look at Controlling SRAM Usage in PSoC® Applications - KBA93584