# 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 − ARR` with CNT primed to ARR (HC32F005 reference manual §9) — see `TickInit()` and `Motor_ArrForSps()`. - The 1 ms system tick (TIM0) drives button scanning and LED patterns; the stepper generator (TIM1) runs autonomously in its own ISR.