how to enable ch32V307 480K flash - Page 1
Forum section: electronics / general

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 10, 2025, 08:53:12 pm
content: Hi,The advertised 480K flash is in the datahseet, But later in the datahseet it points this optionsQuoteAnd then there is only these options in the moun river linker scriptQuoteSo 480KB is available or not? with how much ram? what numbers we could use in the linker script?

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 10, 2025, 09:21:55 pm
content: If I remember correctly, the 480KB of flash is always there, regardless of what you set the code/RAM split option byte setting to - you just can't run code from outside the configured area. That is, you can define a section in flash at 0x08000000 to be 480KB in size and put other stuff there (in the remainder that is non-code) and read from it.RAM will always be whatever you configure in the option bytes, though.

author: brucehoult
author_rank: Super Contributor
timestamp: July 11, 2025, 02:59:46 am
content: If it's not clear, what is happening here is there is actually 320k of RAM and your selected program flash size is copied into RAM at reset.There is 480k of flash but you can't have 480k of program because there isn't enough RAM to copy it into for fast execution.You can however use the remaining flash as something like a disk drive using a serial protocol instead of the faked XIP memory-mapping.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 11, 2025, 07:37:10 pm
content: thanks for the inputs, The question is how to do it?

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 11, 2025, 08:19:36 pm
content: Ok, so as Bruce said, there's a total of 320 KB RAM internally, which is shared between usable RAM for data and "aliased" Flash (which is actually a copy of part of the Flash memory into RAM).The "aliased" (copied to RAM) Flash memory starts at address 0x0000_0000. The RAM usable for other purposes is mapped at address 0x2000_0000.The Flash memory itself is mapped at address 0x0800_0000. It starts with the amount of Flash copied to RAM and the rest is available for storing anything else.All 480 KB of Flash are readable starting at 0x0800_0000, but with wait states, while the part that is copied to RAM has zero wait state, like all RAM in the chip.In your own code, you can read from and execute in (but slower, as there are wait states and no cache) Flash in the whole 0x0800_0000 to 0x8077FFF region.To access it, first you can define a new MEMORY region in the linker script. For instance, you can define the upper Flash region like:UPPER_FLASH (rx) : ORIGIN = 0x08000000 + LENGTH(FLASH), LENGTH = 480K - LENGTH(FLASH)and then define one or more sections inside this memory region, where you can put code or data (again, be aware that access will be significantly slower).The trickier part is "flashing" the MCU with this extra region. Due to the fact there is a big gap between the first region that's written to Flash mapped at 0x0000_0000 and the UPPER_FLASH region, if you need to generate a binary file, it will be gigantic. If your flashing tool can take the .elf file instead, that's much better.Thing is, it will still depends on the flashing tool you use. I personally use wlink, and it doesn't (yet, but didn't re-check recently) support flashing at two different regions like this at once, so it requires two flashing passes and generating two different elf files. A bit annoying. But if you use WCH tools, maybe it's seamless. Didn't check.

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: July 12, 2025, 08:41:38 am
content: thanks SiliconWizard for clarification.