Yes, the codebase is structured to make this practical. The src/hardware/ tree is cleanly separated from src/core/, and there are already two working ARM Cortex-M0 ports in the tree (nuvoton-M051 and nuvoton-NUC029xAN) that you can use as a template. STM32F0 is the same Cortex-M0 class, so most of the work is register-level mapping, not algorithmic.
Quick question first: which specific charger or board are you targeting? That determines effort more than the chip choice. If you can share the model name and ideally a photo of the PCB, it helps narrow the path. Somebody may have already documented the pin map, or it might mirror a known clone.
For an existing STM32-based charger, the actual work breaks down roughly as follows:
- Reverse-engineering the pin map (MCU to LCD, keyboard, ADC frontend,
SMPS PWM out): around 3 to 5 days. This is the real time sink.
Multimeter continuity from chip pins to peripherals. - Toolchain setup (arm-none-eabi-gcc, OpenOCD or ST-Link, CMake
additions): 2 to 3 days. - Porting src/hardware/stm32fX/cpu/ from the Nuvoton template
(Timer, ADC, GPIO, USART, NVIC): about 1 to 1.5 weeks. - EEPROM emulation in Flash (STM32 has no dedicated EEPROM):
2 to 3 days. Standard library, but you have to deal with
wear-leveling. - PROGMEM compatibility layer (cheali-charger uses PROGMEM heavily
for menus, strings, vtables; STM32 has unified Flash via const):
1 to 2 days. Just a thin wrapper. - Bring-up and calibration against real hardware: about 1 week,
iterative. Multimeter and dummy loads.
Total: roughly 3 to 4 weeks of focused work if you have the hardware sorted and some ARM-GCC experience.
Practical prerequisites:
- SWD access. Most STM32 chargers have an unpopulated 5-pin SWD
header somewhere near the MCU. If not, you have to solder directly
to PA13 and PA14. An ST-Link V2 clone from AliExpress is about
3 EUR. - Read-protection check. If the factory firmware was flashed with
RDP, you cannot read it for analysis, but you can still overwrite.
Worst case for you, best case for them.
Worth knowing: matiaschamu has an in-progress port of cheali-charger to the CMS32L051 (Chinese Cortex-M0 used in newer iMaxB6 clones). See:
https://github.com/matiaschamu/cheali-charger/tree/Support-cms32l051
Same architecture class as STM32F0, so looking at that branch gives you a concrete sense of what changes are needed.
One more pointer: I have my own fork at https://github.com/DieterMayerOSS/cheali-charger where over the past few weeks I have been doing maintenance work that would be useful to anyone starting a port. Highlights, in case any of it saves you time:
- Eight firmware bug fixes in src/, all small and contained. ETA
calculation was reversed since 2013 (uint32_t underflow), the
isCalibrationRequired guard was missing for an empty connection
mask, a div-by-zero in calibrateValue, a dead state in
TheveninMethod, etc. Worth picking up before you carry the code
forward to a new MCU. - Pb/AGM float charging (cherry-picked from gromdar's fork) plus
three smaller Iggnus features (chemistry-aware capCutoff
defaults, long-press STOP to prevent accidental aborts, frozen
V/I display after charge completes). - Three written audits under docs/ covering SMPS.cpp, the watchdog
situation (spoiler: there isn't one), and the EEPROM corruption
handling. These document undocumented design intent that would
otherwise need to be rediscovered during a port. - Public-API Doxygen annotation on AnalogInputs.h, Strategy.h, and
Calibration.h. Helps when you're mapping interfaces to a new HAL. - A host-side sim under sim/ with about 110 unit tests covering
the algorithmic core (Thevenin model, balancer logic,
calibration, monitor safety checks). If you port the firmware
to STM32, you can keep running these tests to confirm the
algorithm code still behaves identically on the new architecture. - API typo cleanup (intterrupt, Mesurment, Ballancing, procent,
etc.) which makes the code easier to navigate, though it does
create merge friction with the original upstream.
It is on a branch called sim, version bumped to 3.0. There are also rebuilt .hex files under hex/ for the 20 atmega32 targets in case you want a known-good baseline before swapping to STM32. Feel free to cherry-pick anything that is useful.
Which board are we talking about?