For anyone writing firmware for the board before production firmware ships.
Everything here was verified on hardware rev V9 during bring-up. Images are
linked for flash address 0x08000000 and loaded as described in
Programming & flashing.
Rule 1: enable the instruction cache first
Required
Write 1 to ICACHE_CR (0x40030400) as the first instruction after
reset, before any other code.
Without it, tight loops running from flash lock the chip up: the firmware freezes, LEDs stay stuck, and the core is in lockup with a double-bit ECC error reported on the flash line holding the loop. The error moved with the code, so it is not bad flash cells, and adding flash wait states did not help. Enabling the instruction cache cures it. The root cause is not fully understood yet, so treat this as mandatory.
Pin map
From the rev V9 schematic. Package pin numbers are for the LQFP-48.
| Function | MCU pin | Pkg pin | Notes |
|---|---|---|---|
| VIN sense | PA0 | 10 | Supply voltage through a resistor divider (not used yet) |
| TMC5160 CSN | PA4 | 14 | Pull-up to 3.3 V |
| TMC5160 SCK / MISO / MOSI | PA5 / PA6 / PA7 | 15 / 16 / 17 | SPI mode 3, 40-bit datagrams |
| TMC5160 DRV_ENN | PB0 | 18 | Pull-up: driver stays off until firmware drives it low |
| Encoder CSN | PB1 | 19 | MT6701 Z pin in SSI mode; pull-up to 3.3 V |
| CAN TX | PB10 | 21 | FDCAN1, AF9 |
| CAN RX | PB12 | 25 | FDCAN1, AF9 |
| Encoder CLK | PB13 | 26 | MT6701 B pin |
| Encoder DO | PB14 | 27 | MT6701 A pin, through a series resistor. Data valid after CLK rising edge. |
| ERR LED | PB15 | 28 | Red LED, active high |
| USB D− / D+ | PA11 / PA12 | 32 / 33 | USB-C, data only |
| SWDIO / SWCLK | PA13 / PA14 | 34 / 37 | Pads DIO, CLK, GND, NRST, 3V3 |
| Limit 1 (LS3V3) | PB4 | 40 | 10 kΩ pull-up; reads high when open, low when active |
| Limit 2 (NPN) | PB5 | 41 | Schottky-isolated, 10 kΩ pull-up; low when the NPN sensor switches on |
| TMC5160 DIAG0 | PB6 | 42 | Pull-up to 3.3 V; also on CN5 pin 4 (not used yet) |
| TMC5160 DIAG1 | PB7 | 43 | Pull-up to 3.3 V (not used yet) |
| BOOT0 | — | 44 | Pull-down; BOOT button pulls it to 3.3 V |
| NRST | — | 7 | RESET button to GND, 100 nF |
| HSE | PH0 / PH1 | 5 / 6 | 24 MHz crystal, 15 pF load capacitors |
Not connected: PA1–PA3, PA8–PA10, PA15, PB2, PB3, PB8, PC13, PC15. VBAT is tied to 3.3 V.
TMC5160 wiring that firmware must respect
| Driver pin | Wired to | What it means |
|---|---|---|
SPI_MODE | 3.3 V | SPI is always on. The driver needs SPI setup in both modes. |
SD_MODE | SDMODE switch (pull-down) | Switch on = external STEP/DIR (Mode A); off = internal ramp generator (Mode B). Not wired to the MCU: read it from IOIN bit 6 over SPI. |
DRV_ENN | MCU PB0, pull-up | Driver disabled at power-up and while the MCU is in reset |
REFL_STEP / REFR_DIR | CN5 pins 2 / 3, pull-downs | STEP/DIR in Mode A; left/right reference switches in Mode B. Not wired to the MCU. |
DIAG0 / DIAG1 | MCU PB6 / PB7, pull-ups; DIAG0 also on CN5 | Open-drain by default (active low) |
CLK | GND | Internal clock, about 12 MHz |
ENCA / ENCB / ENCN | GND | The driver's own encoder interface is unused; the MT6701 is read by the MCU |
VCC_IO | 3.3 V | 3.3 V logic on SPI, STEP/DIR and DIAG |
VSA, 12VOUT | External 12 V rail (LM5164) | Gate-drive supply comes from the 12 V buck, not the driver's internal regulator |
So even in STEP/DIR mode, firmware must at least write the chopper and current
registers (CHOPCONF with TOFF ≠ 0, IHOLD_IRUN, GLOBALSCALER if used)
and then drive PB0 low before the motor will move.
The MT6701's MODE pin is tied to 3.3 V, which puts it in SSI mode (Z =
CSN, B = CLK, A = DO). Its analog OUT and PUSH pins are not connected.
Key settings
| Setting | Value | Meaning |
|---|---|---|
ICACHE_CR (0x40030400) | 1 | Instruction cache on; required |
| FDCAN1 kernel clock | HSE 24 MHz | RCC_CCIPR5.FDCAN1SEL = 00 |
FDCAN1 NBTP | 0x02020C01 | 500 kbit/s nominal (bring-up value) |
TMC5160 CHOPCONF | 0x000100C3 | SpreadCycle, TOFF 3, 256 microsteps |
| TMC5160 clock | Internal, about 12 MHz | Used in the VMAX formula below |
TMC5160 velocity
With the internal clock (about 12 MHz) and 256 microsteps on a 200-step motor:
VMAX = rpm / 60 × 51200 × 2^24 / 12 000 000For example 300 rpm → VMAX ≈ 357 914.
Encoder frame
The MT6701 returns a 24-bit SSI frame, clocked with CSN low:
| Bits | Field |
|---|---|
| 23:10 | Angle, 14 bits (16,384 counts/rev) |
| 9:6 | Status (0000 = field OK; 1010 was seen with no magnet) |
| 5:0 | CRC6, polynomial x⁶ + x + 1 |
In USB DFU mode the ROM bootloader sets PB13/PB14 to SPI2 (AF5), so the encoder reads all zeros until the chip is reset into user code (or halted at reset).
TMC5160 DRV_STATUS
Bit 24 of DRV_STATUS is the StallGuard flag, not s2ga (short to
ground, phase A). Mixing them up prints a false "short to ground" fault.
Recommendations
- Enable the instruction cache at reset, before any other code.
- Stay in SpreadCycle at all speeds. Keep
THIGH = 0and do not use the high-speed full-step switch-over (vhighfs/vhighchm) without tuning: at about 300 rpm it upset an untuned motor, which then stalled on the way to 900–1500 rpm. - Use the TMC5160's internal ramp generator. The MCU only sets targets and speeds.
- Use the encoder for stall detection and position checks. StallGuard is not tuned on this board yet.
- Use a normal C toolchain (Arm GCC or STM32CubeIDE). Bring-up images were small hand-assembled Thumb-2 test programs and are not a base for product firmware.