Community-PIO-CH32V / platform-ch32v

PlatformIO platform for CH32V RISC-V chips (CH32V003, CH32V103, CH32V20x, CH32V30x, CH32X035) and CH56x, CH57x, CH58x, CH59x
Apache License 2.0
228 stars 37 forks source link

Significant discrepancy in RAM/Flash usage and binary size between Mounriver Studio and PlatformIO #45

Closed scomx closed 9 months ago

scomx commented 9 months ago

This is for a project ported from MRS to PlatformIO, no code changes were made.

Compiled in MRS on Windows 11:

Memory region         Used Size  Region Size  %age Used
           FLASH:       79652 B       224 KB     34.73%
             RAM:       44460 B        96 KB     45.23%

Compiled using PIO on Mac M2:

RAM:   [=====     ]  45.2% (used 44480 bytes from 98304 bytes)
Flash: [=====     ]  45.9% (used 105276 bytes from 229376 bytes)

Note the flash usage specifically is quite a bit more compared to MRS. The compiled PIO binary is 102KB vs. 39KB on MRS.

I reviewed project flags which were copied over from MRS and believe they are the same.

pio run --verbose
Processing genericCH32V307VCT6 (board: genericCH32V307VCT6; board_upload.maximum_size: 229376; board_upload.maximum_ram_size: 98304; platform: ch32v; framework: noneos-sdk; monitor_speed: 115200; build_flags: -Os -I src/ -D SYSCLK_FREQ_144MHz_HSE=144000000 -march=rv32imafcxw -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -nostartfiles -specs=nano.specs -specs=nosys.specs; build_unflags: -march=rv32imacxw)
scomx commented 9 months ago

Please ignore flash discrepancy. The difference was because of a source file from the examples that I accidentally included in the project. Correcting and re-compiling gives me expected RAM+Flash usage.

RAM:   [=====     ]  45.0% (used 44240 bytes from 98304 bytes)
Flash: [===       ]  30.1% (used 69004 bytes from 229376 bytes)

The binary, however, is still larger than expected and I'm not sure why -- PIO 69KB vs MRS 39KB.

maxgerhardt commented 9 months ago

PIO 69KB vs MRS 39KB.

Where do you see 39KB? Your report above says

Memory region         Used Size  Region Size  %age Used
           FLASH:       79652 B       224 KB     34.73%

so that's even circa 79KB for the needed FLASH code.

scomx commented 9 months ago

You're right, another unfortunate oversight on my part. I reviewed the MRS project and the 39 KB binary was from and older build, prior to adding wchnet library and additional code. I had switched it to build Intel-HEX only at some point so the binary was never updated. Actual size is 78 KB. IOW all good.