Firmware (src/app): - system state machine: IDLE / ROTATING / POWER_OFF - button: 20 ms debounce, short/double/long classification, boot hold-off - LED: idle slow blink, solid, speed/direction feedback patterns - motor: 8-phase half-step drive with trapezoidal acceleration, speed levels 2.5/5/7.5/10 RPM, reversal via standstill - power latch on P33 (push-pull, high = hold, low = cut) with decelerate-to-stop sequence before power-off (FR18) - base timer mode-2 reload semantics (interval = 0x10000 - ARR) Build: Makefile for arm-none-eabi-gcc, selective DDL compile, vendor startup + linker script under src/. Docs: FIRMWARE_REQUIREMENTS.md, STATE_MACHINE.md, README.md. Vendor datasheet/RM/DDL references under docs/ are kept locally and tracked in a separate shared repo.
2.1 KiB
2.1 KiB
Turning Table Firmware (HC32F005C6PA)
Bare-metal C firmware for a motorized turning table. Drives a 28BYJ-48 stepper motor (ULN2003 board, half-step, trapezoidal acceleration) and is controlled with a single button plus one status LED. Power is held by a GPIO latch so the system can switch itself off.
Hardware
| Pin | Function | Config |
|---|---|---|
| P02 | LED | open-drain output, active low |
| P23–P26 | Motor IN1–IN4 | push-pull output |
| P32 | Button | input, internal pull-up, active low |
| P33 | Power latch | push-pull output, high = hold power, low = cut power |
Behavior
- Power-on → IDLE (LED slow blink 0.5 Hz). Holding the button at power-on is ignored.
- Short press in IDLE → rotate at Speed 1; short press again cycles Speed 1→2→3→4→1 (2.5 / 5 / 7.5 / 10 RPM), LED blinks N times as feedback.
- Double press → reverse direction (LED quick double-blink); speed changes and reversal ramp smoothly to avoid skipped steps.
- Long press (> 2 s) → motor decelerates to a full stop, LED off, power cut via P33.
Full specification: FIRMWARE_REQUIREMENTS.md. State machine details: STATE_MACHINE.md.
Repository layout
src/app/ application: main.c (system state machine), button.c, led.c, motor.c, power.c
src/driver/ vendor device driver library (gpio, bt, sysctrl, ...)
src/common/ vendor system headers, board pin map (board_stkhc32f005.h)
src/gcc/ startup code and linker script (32K flash / 4K RAM)
docs/ MCU datasheet, reference manual, DDL docs, vendor examples
Build
Requires arm-none-eabi-gcc and make:
make # builds build/turntable.elf/.bin/.hex (~4.5K flash, ~2.1K RAM used)
make clean
Only the DDL modules in use are compiled. Flashing is done with your own SWD programmer (no flash target is provided).
Notes
- The base timers run in mode 2 (reload): interval =
0x10000 − ARRwith CNT primed to ARR (HC32F005 reference manual §9) — seeTickInit()andMotor_ArrForSps(). - The 1 ms system tick (TIM0) drives button scanning and LED patterns; the stepper generator (TIM1) runs autonomously in its own ISR.