Swindle : Downloading code to the CH32VXX faster

 Now that the new bootloader shown that it can be fast to write to the CH32v3xx flash, time to revisit the swindle way of loading code.

(Gemini was really helpful again. But as a smart assistant, no vibe coding here).

Starting point:

So we started around average speed of 3kB/S (including erase, download and write)

Optim 1: use bigger blocks

Before, we were configuring the block size/erase size to be 256 bytes (same as the small hardware pages).

Reconfiguring the description to be 4kB gave a small speed bump => 5 kB

(internally it will call 256 bytes multiple times, it just reduces the overhead).


Optim 2: Faster writing to RAM

The dominant slowdown is the amount of time needed to write to the CH32V3xx ram (then we call the flashstub to actually write it, that's pretty fast).

Just the writing caps the overall speed to 9 kB/s , without even erasing or writing.

So the optimisation is to use a fast_write_ram function there that is using abstract commands with auto exec to pipeline data write to ram. It's about 4x timer faster

(Nb: it works here because the debug link is so slow there is no need to wait for the write command to be done to switch to the next one)


=> Overall speed is now 8kB/S Better but still not great


Optim 3: Varying block size


That one is a little bit more intrusive. Declare (optionnaly) a list of erase block sizes, and erase using the biggest possible block size (taking into account alignment). For the CH32v3xx we can now use the 32k Erase like with the DFU bootloader.

==> Overall Speed is now 25 kB/S

Wait a minute

It's actually more nuanced than that. The end result is actually a mix of two behaviours : 
- when it can use 32kB erase, more than 25 kB/s
- when it cannot, much less like 8kB/s

so if you write large blocks (like 200kB), the overall speed is closer to 25 kB/s
but when you write smaller firmware, where there is not a lot of full 32kB blocks it is more in the 8 kBs/s range.


Nonethless, it is now bearable, while before it was in the 1mn range to flash the whole swindle firmware. Now it's more in the 15sec range.

Comments

Popular posts from this blog

G600 Microscope Battery charging mod

INA3221, weird wiring

Component tester with STM32 : Part 1 ADC, Resistor