it's yours now
Theres programming pads on there for a reason. Its a 72 MHz Cortex-M3 with nine LEDs, nine buttons, a buzzer and USB hanging off it, and right now its running a birthday card, which is prolly the least interesting thing you could put on it. So put something else on it.
You cant permanently break it. Worst case you flash something that doesnt
boot, and then you flash souffle-original.bin back over it and
youre exactly where you started.
whats on the board
| MCU | STM32F103C8T6, 64 KB flash, 20 KB RAM, 72 MHz off an 8 MHz crystal |
| LEDs | LED1 = PA15, LED2-7 = PB4-PB9, LED8 = PB10, status = PB11 |
| buttons | BTN1-7 = PA1-PA7, BTN8 = PB0, ENTER = PB1 |
| buzzer | PA0, TIM2_CH1, low side FET. Resonant around 2.7 kHz |
| USB | PA11 / PA12, with the D+ pull-up on PA8 so firmware controls attach |
| serial | PA9 / PA10 on the TX / RX pads |
| debug | SWDIO PA13, SWCLK PA14, SWO PB3, on the Tag-Connect pads |
Two things caught me out, so they'll prolly catch you out too.
PA15 and PB4 are JTAG pins at reset. PA15 is JTDI and PB4 is NJTRST,
and until you turn JTAG off they arent GPIOs at all, so you can write to
them all day and LED1 and LED2 just sit there. Call
__HAL_AFIO_REMAP_SWJ_NOJTAG(), or write
SWJ_CFG = 010 into AFIO_MAPR if youre doing
registers, and do it before you configure any pins. Dont disable SW at the
same time or you lose the debugger and have to do the BOOT0 thing to get
back in.
The LEDs sink to light. The anodes all go to 3V3 and the pin is on the cathode side through a 120R resistor, so driving the pin LOW is on and HIGH is off. Backwards from what you'd expect and i got it wrong the first time.
downloads
- souffle-original.bin what it shipped with, goes at 0x08000000
- souffle-original.hex same thing, if your tool wants hex instead
- souffle-schematic.pdf the whole schematic, opens in the browser
- souffle-starter.c bare metal, no HAL, about 100 lines of register writes
- souffle-starter-hal.c same thing but with the HAL, drop it into a CubeMX project
- souffle-pinout.ioc open it in CubeMX, all 31 pins already named
putting code on it
Two ways in. Get an ST-Link if you dont have one, the clones are like $15 and it makes all of this alot less painful.
SWD, the Tag-Connect pads
Clip the ST-Link onto the Tag-Connect pads. Then either open STM32CubeProgrammer and point it at the file, or from a terminal:
STM32_Programmer_CLI -c port=SWD mode=UR -d souffle-original.bin 0x08000000 -v -rst
serial, no ST-Link
The F103 has a bootloader burned into ROM from the factory that speaks UART, so any USB-serial adapter works. Tie BOOT0 to 3V3, put the adapter on the TX and RX pads, then power cycle it. It comes up in the bootloader instead of your code and just sits there waiting. Then:
stm32flash -w souffle-original.bin -v -g 0x0 /dev/tty.usbserial-XXXX
Put BOOT0 back to ground afterwards, otherwise it keeps coming up in the bootloader and youll think you bricked it.
You cant reflash it over USB-C on its own, sorry. The ROM bootloader on this chip is UART only, and i didnt write a USB one into flash for it to jump to. If that annoys you, writing one is genuinely a good project. You put it at the start of flash, link your own code above it, and have it jump across unless some button combo is held at boot.
two starters, pick one
These both do the same thing, they read the nine buttons and light the matching LEDs. One is registers, one is HAL. Use whichever, the registers one is easier to actually understand and the HAL one is easier to bolt USB onto later.
Registers only, so theres no build system to fight with.
arm-none-eabi-gcc, any F103 linker script, done.
if you go the CubeMX route
Open souffle-pinout.ioc and all 31 pins are already named and
assigned, which is the boring part. Two things it wont do for you:
- set SYS > Debug. It defaults to Disable, which leaves JTAG switched on, which is the PA15 / PB4 thing above. Set it to Trace Asynchronous SW, that frees both of them and gives you SWO on PB3 so you can printf into the debugger. Plain Serial Wire works for the LEDs too, you just dont get the trace pin.
- set Clock Configuration. HSE 8 MHz, PLLMul x9, SYSCLK 72 MHz, APB1 /2 (it maxes out at 36), APB2 /1, USB prescaler /1.5. Thats the only combination that lands on exactly 48 MHz for USB, which is the whole reason the crystal is 8 MHz. CubeMX opens on the internal oscillator so you have to go and set this yourself.
the protocol the original speaks
If you'd rather poke at the firmware thats already on there than replace
it, its just ASCII lines over USB CDC. Baud rate doesnt matter, its USB so
the number is made up. HELLO gets you a banner and whatever
state its in. READ n asks for chunk n of the message and it
will refuse unless it reckons you solved it. Theres no unlock command, i
never wrote one, so theres nothing you can send from the computer to talk
your way past it.
It also dumps the message out the UART pads in plain text while its streaming, so if you just want to read it with a serial adapter and no browser at all, thats there.