Flash pages are only erased as needed during the flash routine, which makes flashing faster as well as making the transfer consistent.
Later datasheets have the flash clock set to 2MHz. I've set it to 2MHz here. I may undo this change later depending on how slow loading a 14K firmware feels.
Was able to save enough space to reduce bootloader size from almost 2.5K to 2K exactly. Adjusted flash offsets to start from 0x800.
GPIO values are now mostly reset to power-on defaults.
Fixed some formatting. Removed dead code.
Took a publicly available XMODEM bootloader and made it work on HK32F.
Known issues:
- Erase is super slow on this MCU. The upload routine erases all flash before loading, which means the first packet seems to hang. This also erases possibly persistent data stored in unused pages on flash.