← back to the card

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

MCUSTM32F103C8T6, 64 KB flash, 20 KB RAM, 72 MHz off an 8 MHz crystal
LEDsLED1 = PA15, LED2-7 = PB4-PB9, LED8 = PB10, status = PB11
buttonsBTN1-7 = PA1-PA7, BTN8 = PB0, ENTER = PB1
buzzerPA0, TIM2_CH1, low side FET. Resonant around 2.7 kHz
USBPA11 / PA12, with the D+ pull-up on PA8 so firmware controls attach
serialPA9 / PA10 on the TX / RX pads
debugSWDIO 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

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:

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.