User avatar
hesam_m
Posts: 25
Joined: Thu Apr 25, 2019 9:45 am

Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 6:05 am

Hi,

I'm using C/C++ SDK for the Pico board and I have compiled and run the C code successfully. I have two questions:

1) is there any way to see the consumed memory and usage statistic (Flash, SRAM)?

2) How can I optimize the code (probably through CMake) for size or speed?
Last edited by hesam_m on Sat Jun 19, 2021 12:50 pm, edited 1 time in total.

pic0
Posts: 53
Joined: Tue Jan 26, 2021 11:04 am

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 10:46 am

Hi,
hesam_m wrote:
Sat Jun 19, 2021 6:05 am
1) is there any way to see the consumed memory and usage statistic (Flash, SRAM)?
See here.

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 706
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 1:11 pm

also looking at the generated map file gives you aa trove of information

defaault build is optimized; pass -DCMAKE_BUILD_TYPE=MinSizeRel to cmake for a min size release build, though generally you're better off with the default.

User avatar
hesam_m
Posts: 25
Joined: Thu Apr 25, 2019 9:45 am

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 1:13 pm

pic0 wrote:
Sat Jun 19, 2021 10:46 am
Hi,
hesam_m wrote:
Sat Jun 19, 2021 6:05 am
1) is there any way to see the consumed memory and usage statistic (Flash, SRAM)?
See here.
Thank you, however where the Size command belongs to?

User avatar
hesam_m
Posts: 25
Joined: Thu Apr 25, 2019 9:45 am

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 1:16 pm

kilograham wrote:
Sat Jun 19, 2021 1:11 pm
also looking at the generated map file gives you aa trove of information

defaault build is optimized; pass -DCMAKE_BUILD_TYPE=MinSizeRel to cmake for a min size release build, though generally you're better off with the default.
Thank you. How can I optimize it for speed?

User avatar
triss64738
Posts: 31
Joined: Wed Jun 16, 2021 5:13 pm
Location: masto/fedi: sys64738@hellsite.site
Contact: Website

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 1:49 pm

-DCMAKE_BUILD_TYPE=Release optimizes for speed, which I think is already the default.

User avatar
hesam_m
Posts: 25
Joined: Thu Apr 25, 2019 9:45 am

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 2:24 pm

triss64738 wrote:
Sat Jun 19, 2021 1:49 pm
-DCMAKE_BUILD_TYPE=Release optimizes for speed, which I think is already the default.
I'm using VSCode. I changed the Cmake to "Release" and compiled the code. The generated UF2 file is 20K or so heavier and it has not optimized for Speed. is there anything I missed?

Image

User avatar
triss64738
Posts: 31
Joined: Wed Jun 16, 2021 5:13 pm
Location: masto/fedi: sys64738@hellsite.site
Contact: Website

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 4:06 pm

If you're on Windows, you can find the "size" binary somewhere around where your cross-compiler is installed. (I don't know where that is, I don't run Windows.)
hesam_m wrote:and it has not optimized for Speed
How so? It should (compared to -DCMAKE_BUILD_TYPE=Debug).

User avatar
hesam_m
Posts: 25
Joined: Thu Apr 25, 2019 9:45 am

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 5:04 pm

triss64738 wrote:
Sat Jun 19, 2021 4:06 pm
If you're on Windows, you can find the "size" binary somewhere around where your cross-compiler is installed. (I don't know where that is, I don't run Windows.)
Yes, the file on windows is arm-none-eabi-size.exe and this is the output, Now I'm not sure which one is FLASH and which one is SRAM

Image

How so? It should (compared to -DCMAKE_BUILD_TYPE=Debug).
Because I'm actually testing the execution speed of a known code block, that I have tested the speed difference on the STM32 compiler by using optimized for speed (-Ofast). The speed of the know code block I see on Pico is the default speed, the same as STM32 with no applied optimization. So selecting Release did not help.

Image

I'm using VSCode and I change Debug and Release there

Image

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 706
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 5:51 pm

The default release cmake build is optimized...

you may be having issues with VS Code... try doing a clean build, also the output from the cmake generation or the build is most useful if you are making screenshot.
Because I'm actually testing the execution speed of a known code block,
Fair enough, but are you running the instructions more than once? the first execution is likely to be slower as it will read from flash.

User avatar
triss64738
Posts: 31
Joined: Wed Jun 16, 2021 5:13 pm
Location: masto/fedi: sys64738@hellsite.site
Contact: Website

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 6:17 pm

hesam_m wrote:
Sat Jun 19, 2021 5:04 pm
triss64738 wrote:
Sat Jun 19, 2021 4:06 pm
If you're on Windows, you can find the "size" binary somewhere around where your cross-compiler is installed. (I don't know where that is, I don't run Windows.)
Yes, the file on windows is arm-none-eabi-size.exe and this is the output, Now I'm not sure which one is FLASH and which one is SRAM

Image
Yes, that's the default output of size. If you add the --format=SysV or -A flag, it gives a more detailed output. -x turns the output into hexadecimal:

Code: Select all

$ arm-none-eabi-size -Ax test.elf
test.elf  :
section                  size         addr
.text                  0xb914   0x20000000
.rodata                 0xa28   0x2000b918
.binary_info             0x38   0x2000c340
.data                   0x124   0x2000c380
.uninitialized_data       0x0   0x2000c4a4
.scratch_x                0x0   0x20040000
.scratch_y                0x0   0x20041000
.bss                   0x175c   0x2000c4a8
.heap                   0x800   0x2000dc04
.stack_dummy            0x800   0x20041000
.ARM.attributes          0x2d          0x0
.comment                 0x11          0x0
.debug_line             0x228          0x0
.debug_info             0x9a4          0x0
.debug_abbrev           0x1fc          0x0
.debug_aranges           0x40          0x0
.debug_str              0x5d9          0x0
.debug_loc               0x90          0x0
.debug_ranges            0x10          0x0
.debug_frame             0x28          0x0
Total                 0x100db
All the .debug etc. stuff can be ignored, but the rest gives you an idea about how everything is laid out. The addresses tell you whether things are in SRAM, or in flash. Addresses starting with 0x2 are in SRAM, those with 0x1 are in flash. In the above example, everything is in SRAM, because I compiled it with the -DPICO_NO_FLASH=On CMake option. If I wouldn't have specified it, .text and .rodata would most likely have addresses starting with 0x1, and thus be in flash. If you want a nicer output, I guess you could write a script that parses this output.

User avatar
hesam_m
Posts: 25
Joined: Thu Apr 25, 2019 9:45 am

Re: Raspberry Pi Pico using C/C++ SDK

Sat Jun 19, 2021 7:58 pm

Thank you for your helpful comments and replies. The problem of both cases are now solved.

Return to “SDK”