If the chip was configured to have one configuration (e.g., "FLASH-288K + RAM-32K") but the platformio.ini configuration builds a firmware for the "FLASH-256K + RAM-64K" configuration, the chip will fail too boot properly, because the linker script and startup file will place the initial stack pointer (SP) at the end of RAM (so e.g. 0x200000 + 64K) which is not RAM in the current configuration, so at the first usage of the stack (like a jal instruction), the chip HardFault's.
We need a way for these chips to readout the current Flash+SRAM configuration and check them against the used build config, then either throw a really big warning or straightup fail the build or upload process.
It would also be good if we had a way to set a desired configuration and have that available as a PlatformIO task (together with removing read/write protection locks).
Currently I've been doing this via the official W.CH ISP Programmer tools.
Very sneakily, some CH32V20x and CH32V30x chips have the capability for different Flash+SRAM configurations.
These seem to be programmed into the option bytes (through the flash peripheral).
Original linker scripts.
Currently we only hint at this in the
platformio.ini
for one chiphttps://github.com/Community-PIO-CH32V/platform-ch32v/blob/f1eb50cee3b0a9a068fadc87f54f8c89e3cab310/examples/blinky-none-os/platformio.ini#L28-L43
If the chip was configured to have one configuration (e.g., "FLASH-288K + RAM-32K") but the
platformio.ini
configuration builds a firmware for the "FLASH-256K + RAM-64K" configuration, the chip will fail too boot properly, because the linker script and startup file will place the initial stack pointer (SP) at the end of RAM (so e.g. 0x200000 + 64K) which is not RAM in the current configuration, so at the first usage of the stack (like ajal
instruction), the chip HardFault's.We need a way for these chips to readout the current Flash+SRAM configuration and check them against the used build config, then either throw a really big warning or straightup fail the build or upload process.
It would also be good if we had a way to set a desired configuration and have that available as a PlatformIO task (together with removing read/write protection locks).
Currently I've been doing this via the official W.CH ISP Programmer tools.