Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable RAM sizes for V20x, V30x #280

Open
maxgerhardt opened this issue Feb 18, 2024 · 8 comments
Open

Configurable RAM sizes for V20x, V30x #280

maxgerhardt opened this issue Feb 18, 2024 · 8 comments

Comments

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Feb 18, 2024

The linker script

#elif TARGET_MCU_LD == 3
#if MCU_PACKAGE == 1
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
#elif MCU_PACKAGE == 2
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
#else
#error "Unknown MCU package"
#endif

for V30x only gives the "256K Flash + 64K RAM" and "128K Flash + 32K RAM" option. This is however wrong: The 128K Flash option doesn't exist naturally. The options for 30x are

grafik

And for 20x

grafik

Through invocation of the blackest dark magic I've ever seen, flash cells become RAM cells, and their sum is a constant.

Also see Community-PIO-CH32V/platform-ch32v#20 and Community-PIO-CH32V/platform-ch32v#17 (comment)

What I'm specifically saying is that I think the linker script and Makefile is wrong by deducing the "one right" memory sizes only through the chip's name / package name, when in fact, some chips are more freely configurable.

@bmx
Copy link
Contributor

bmx commented Feb 18, 2024

image
Who's wrong? the datasheet? the linkutility?

@cnlohr
Copy link
Owner

cnlohr commented Feb 18, 2024

Through invocation of the blackest dark magic I've ever seen, flash cells become RAM cells, and their sum is a constant.

wat

Can you validate the actual performance?

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Feb 18, 2024

Who's wrong? the datasheet? the linkutility?

Ah, indeed I'm wrong, or rather, confusingly worded: The V30x devices marked "256K Flash + 64K SRAM" parts are actually configurable for the 4 options shown in the link utility. This is only the CH32V307(RC/WC/VC) and CH32V303(RC/VC) chips. For the other chips, 303(CB,RB), 305(FB,RB), they do have 128K flash and 32K RAM fixed.

CH32V307DS0.pdf:

grafik
grafik

For V20x series chips, only V203RB and all V208 have configurable sizes from selections, all others are 32K+10K or 64K+20K.

The point still stands however, V30x sreies chips can actually have 5 different configurations, the .ld file makes only 2 possible.

@cnlohr
Copy link
Owner

cnlohr commented Feb 19, 2024

@dwillmore has been postulating that the flash is in fact RAM, and that it's somewhat arbitrary how it's configured. I am extremely curious if we find something like that. It seems that there are bits in the option rom for configuring the bits, see FLASH_OBR
image

@maxgerhardt would you be up for adding to the .ld file to enable the other forms? Also, it seems you will need to flash the option bytes in order to select between the different modes. Do you have any recommendations on how we could select the appropriate split?

@cnlohr
Copy link
Owner

cnlohr commented Feb 19, 2024

Wait... does that mean it can be configured at runtime? I also see it here:

image

@jnk0le
Copy link
Contributor

jnk0le commented Apr 22, 2024

Through invocation of the blackest dark magic I've ever seen, flash cells become RAM cells, and their sum is a constant.

wat

@dwillmore has been postulating that the flash is in fact RAM, and that it's somewhat arbitrary how it's configured

This flash is in fact a sram loaded with image from "external" flash, typically done like this: htps://zeptobars.com/en/read/GD32F103CBT6-mcm-serial-flash-Giga-Devices

@dwillmore
Copy link
Collaborator

dwillmore commented Apr 22, 2024 via email

@jnk0le
Copy link
Contributor

jnk0le commented May 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants