← Commit history

Delete boards/p1-motor-driver/analysis/pinmap-and-bringup.md

John Lauer ·e79d195cc7 · ·parent dfb5144
1 file changed −217
boards/p1-motor-driver/analysis/pinmap-and-bringup.mddeleted−217
@@ -1,217 +0,0 @@-# P1 motor driver: MCU pin map and bring-up notes--Designed to interface spec **v1.4.0**; hardware unchanged from v1.3.15 except the CAN transceiver's VIO, the Kelvin sense nets and the time-delay brake fuse (v1.4.0). v1.4.0 adds the climb policy below. The firmware rules below follow sections 5.3, 5.5 and 5.6, and 8.3 to 8.4 of that version, which take in v1.2.3 (CAN CRC and counters), v1.2.6 (parking brake, Category 1 stops), v1.2.7 (BOOT flag), v1.2.9 and v1.3.0 (SPEED_LIMIT, reverse clamp, OPERATOR_LIVE) and v1.3.7 (1 kW regeneration cap). Firmware is not part of this deliverable; this file is what the firmware author needs.--## MCU: STM32G474RET6 (LQFP-64)--Alternate functions are from ST's open pin data (`STM32_open_pin_data`, `STM32G474R(B-C-E)Tx.xml`), not from memory.--| Pin | Port | Net | Function | Peripheral |-|---|---|---|---|---|-| 42 | PA8 | PWM_HA | high side A | TIM1_CH1 |-| 43 | PA9 | PWM_HB | high side B | TIM1_CH2 |-| 44 | PA10 | PWM_HC | high side C | TIM1_CH3 |-| 35 | PB13 | PWM_LA | low side A | TIM1_CH1N |-| 36 | PB14 | PWM_LB | low side B | TIM1_CH2N |-| 37 | PB15 | PWM_LC | low side C | TIM1_CH3N |-| 20 | PA6 | DRV_NFAULT | gate driver fault (open drain, 10 k pull-up) | TIM1_BKIN (and EXTI) |-| 25 | PB1 | SOA | phase A current, 1.65 V at 0 A, 25 mV/A | ADC1_IN12, COMP1_INP |-| 21 | PA7 | SOB | phase B current | ADC2_IN4, COMP2_INP |-| 24 | PB0 | SOC | phase C current | ADC3_IN12 (or ADC1_IN15), COMP4_INP |-| 12 | PA0 | VMOT_SNS | VMOT / 31.0 (3 x 33 k over 3.3 k: 60 V reads 1.94 V, the 96.8 V TVS clamp 3.12 V) | ADC1_IN1 |-| 8 | PC0 | VU_SNS | phase U voltage, same ratio | ADC1_IN6 |-| 9 | PC1 | VV_SNS | phase V voltage | ADC1_IN7 |-| 10 | PC2 | VW_SNS | phase W voltage | ADC1_IN8 |-| 11 | PC3 | BRD_NTC | board NTC (10 k pull-up, NTCG164BH103, B 3435 K) beside the bridge | ADC1_IN9 |-| 33 | PB11 | MOT_NTC_M | motor winding thermistor (10 k pull-up, type unknown: characterise) | ADC1_IN14 |-| 52 | PC10 | SPI_SCK | DRV8353 SPI | SPI3_SCK |-| 53 | PC11 | SPI_MISO | DRV8353 SDO (open drain, 10 k pull-up) | SPI3_MISO |-| 54 | PC12 | SPI_MOSI | DRV8353 SDI | SPI3_MOSI |-| 51 | PA15 | DRV_NSCS | DRV8353 chip select | GPIO out |-| 41 | PC9 | DRV_EN | firmware permit into the hardware AND with EN (100 k pull-down) | GPIO out |-| 59 | PB6 | EN_IN | EN as seen after 1 k / 10 k (MOTOR_STATUS "EN seen") | GPIO in |-| 60 | PB7 | MCU_OK | healthy; ANDed with DRV nFAULT to pull FAULT low (100 k pull-down) | GPIO out |-| 3 | PC14 | BRK_SENSE | brake chopper active (through 10 k from the 5.1 V comparator) | GPIO in |-| 4 | PC15 | SIDE | strap: low = left (node 0x11), high = right (0x12) | GPIO in |-| 45 | PA11 | CAN_RX | TCAN1462V RXD (swings 0 to VIO = 3V3) | FDCAN1_RX |-| 46 | PA12 | CAN_TX | TCAN1462V TXD (VIH 0.7 x VIO = 2.3 V) | FDCAN1_TX |-| 26 | PB2 | CAN_STB | transceiver standby (10 k pull-up: standby until firmware drives low) | GPIO out |-| 57 | PB4 | ENC_A | encoder A after the AM26LV32 | TIM3_CH1 (encoder mode) |-| 58 | PB5 | ENC_B | encoder B | TIM3_CH2 |-| 38 | PC6 | HALL_U_M | Hall U (4.7 k pull-up to 5 V, 1 k series, 1 nF) | TIM8_CH1 (Hall interface) |-| 39 | PC7 | HALL_V_M | Hall V | TIM8_CH2 |-| 40 | PC8 | HALL_W_M | Hall W | TIM8_CH3 |-| 34 | PB12 | LED_STAT | red status LED (1 k) | GPIO out |-| 5, 6 | PF0, PF1 | HSE_IN, HSE_OUT | 16 MHz crystal, 33 pF loads | RCC_OSC |-| 49, 50 | PA13, PA14 | SWDIO, SWCLK | debug test pads | SWD |-| 56 | PB3 | SWO | trace test pad | SWO |-| 7 | PG10 | NRST | 100 nF, test pad | reset |-| 61 | PB8 | BOOT0 | 10 k pull-down | boot |-| 14, 17 | PA2, PA3 | UART_TX, UART_RX | debug UART test pads | USART2 |-| 18 | PA4 | DAC1 | debug DAC test pad (scope a variable) | DAC1_OUT1 |-| 19 | PA5 | BRK_PWM | parking-brake coil PWM, 20 kHz (100 k pull-down; UCC27517 ANDs it with EN in hardware) | TIM2_CH1 |-| 62 | PB9 | BRK_HOLD | parking-brake release permit: closes the fast-decay bypass (ANDed with EN in hardware; 100 k pull-down) | GPIO out |-| 13 | PA1 | BRK_ISNS | brake coil current, 0.1 ohm, 100 mV/A (1 k / 100 nF) | ADC1_IN2 |-| 22 | PC4 | BRK_N_SNS | chopper switch node BRK_N, 3 x 33 k / 3.3 k (0.032 V/V; 1.94 V at 60 V), 1 nF | ADC2_IN5 |-| 23 | PC5 | ENC_EN | encoder 5 V switch enable (TPS2051B; 10 k pull-up: on from boot) | GPIO out |-| 55 | PD2 | ENC_OC | encoder 5 V overcurrent flag, low = fault (10 k pull-up) | GPIO in |-| 30 | PB10 | BRAKE_SW | brake release-confirm switch, low = closed (10 k pull-up, 1 k series) | GPIO in (FT) |-| 2 | PC13 | BRK_INH | high = open Q13, the chopper series disconnect (100 k pull-down: the chopper works with the MCU in reset) | GPIO out |--Hall inputs on PC6 to PC8 rely on the pins being 5 V tolerant (FT) through the 1 k series resistors; check the "FT" column of the STM32G474 datasheet pin table before first power, and if any is not FT, replace the 4.7 k pull-ups' 5 V end with 3V3 (rework: lift one end).--## Clocks--- HSE 16 MHz, PLL to 170 MHz SYSCLK. FDCAN kernel clock **80 MHz** from PLLQ (interface spec 8.1 requires 40 or 80 MHz).-- FDCAN: 1 Mbit/s nominal (80 MHz, prescaler 1, 80 tq, sample point 80 %), 5 Mbit/s data (prescaler 1, 16 tq, sample point 75 %), BRS on, transmitter delay compensation on.--## Bring-up sequence--1. **No VMOT, 12 V bench supply on 12V_MAIN, current limit 0.3 A.** Expect about 0.1 A. Check 5V (4.94 to 5.14 V), 3V3, green LED. BUCK_SW about 570 kHz.-2. **Program over SWD** (test pads SWDIO, SWCLK, NRST, 3V3; GND on any GND contact). Blink the red LED.-3. **SPI to the DRV8353 with ENABLE high** (EN contact to 3.3 V, DRV_EN high, still no VMOT: the DRV8353 reports VM undervoltage, which proves SPI). Read the status registers.-4. **VMOT from a current-limited supply at 24 V, 0.5 A, motor disconnected.** Expect under 20 mA with EN low. Check V12_BRK (about 11.4 V) and V5_BRK (about 5.1 V).-5. **Configure the DRV8353 over SPI** before the first PWM:-   - 6x PWM mode.-   - IDRIVEP 1 A, IDRIVEN 2 A (switching losses in the calcs assume this; reduce if the phase nodes ring).-   - Dead time 100 ns.-   - VDS_LVL 0.45 V (trips at about 44 A hot).-   - CSA gain 40 V/V, bidirectional.-   - OCP mode latched.-6. **Current-sense zero:** SOA/SOB/SOC at 1.65 V with no PWM; store offsets.-7. **Phase nodes, motor disconnected,** 10 % duty on each phase: check the dead time and ringing on PH_U/V/W.-8. **Motor connected, VMOT 24 V, current limit 5 A.** Hall alignment, then encoder (4 x 4096 counts per revolution, 20 pole pairs, so 819.2 counts per electrical cycle). Open-loop spin, then the current loop, then the speed loop.-9. **Brake chopper,** with a 3.0 ohm resistor on BRK_P/BRK_N and a programmable supply:-   - Ramp VMOT from 54 V; the amber LED and BRK_SENSE come on at 56.76 V nominal and go off at 56.17 V (worst case over temperature 57.69 V on, 55.21 V off; REF3012 reference, the interface spec).-   - Then do a regen test with the supply's sink disabled.-10. **ENABLE timing:** drop EN while switching and confirm DRV_ENABLE and EN_N change within 10 us and all six gates go low (interface spec 5.3).-11. **Parking brake,** with the BFK458-12 on BRAKE_P/N and VMOT at 48 V:-    - Measure the coil L with an LCR meter at 100 Hz, armature in and out (INTORQ does not publish it).-    - EN high, BRK_HOLD high, release: BRK_ISNS reads 0.166 V (1.66 A), then 0.083 V (0.83 A) on hold; BRAKE_N is a 20 kHz square.-    - Drop EN: BRAKE_N flies to VMOT plus about 39 V, then the current is zero. Measure t1 (EN low to torque) against interface spec 5.5's 53 + 20 = 73 ms.-    - With EN low, setting BRK_PWM and BRK_HOLD from firmware must not release it.-12. **FAULT:** confirm FAULT floats high (P4's pull-up) in reset, unpowered, and on a DRV8353 fault, and is low only when MCU_OK is high and nFAULT is high.--## Firmware rules from the interface spec--### Hardware safety (never in firmware alone)--- EN low removes gate drive in hardware by two paths:-  - SN74LVC244 outputs go high-Z, and the DRV8353 inputs' internal pull-downs turn every gate off.-  - DRV8353 ENABLE goes low, through the AND gate with DRV_EN.-- Firmware cannot hold the bridge on against EN.-- FAULT is low only while healthy (interface spec 5.3).-- **Brake on disable (interface spec 5.3): rejected, and the interface spec accepted that.** The spring-applied parking brake (5.5) holds the robot instead.-- **Parking brake (interface spec 5.5, v1.2.6, 35 N m from v1.3.7):**-  - Hardware: the coil runs from VMOT through the 1 A fuse. The PWM switch's driver ANDs BRK_PWM with EN, and the fast-decay bypass is driven by AND(EN, BRK_HOLD). EN low, VMOT loss, 12V_MAIN loss, an MCU reset or a P1 fault all engage the brake. Firmware can engage it but never release it against EN.-  - Brake: INTORQ BFK458-12, 24 V coil: 14.4 ohm, 1.66 A / 40 W release, about 0.83 A / 10 W hold, t1 53 ms, t2 115 ms.-  - Release: BRK_HOLD high, then BRK_PWM current-controlled on BRK_ISNS to 1.66 A for at most 200 ms (t2 is 115 ms), then 0.83 A hold. Feed-forward duty = I x R_coil / VMOT, with R_coil estimated from the release current.-  - Engage: BRK_HOLD low and BRK_PWM 0. The coil current then clamps through the SMCJ24A (38.9 V max; BRAKE_N peaks at 97 V, under 100 V). Engaging from the 0.83 A hold decays in about 10 ms for a 0.5 H coil; INTORQ does not publish L.-  - Feedback: BRK_ISNS checks the coil current (open coil: under 20 % of expected; short: over 2.5 A or the 3 A time-delay fuse open). BRAKE_SW confirms release if the brake has a switch. Either fault sets MOTOR_STATUS byte 13 bit 2. Byte 13 bit 1 = brake released.-  - Parking: with both commanded speeds 0 and wheel speed under 0.5 rpm for 0.5 s, engage. DRIVE_CMD mode 4 engages now. On a non-zero command, release, hold zero speed for the release time, then drive.-- **Stop categories (interface spec 5.5):**-  - Category 1, for firmware causes (STOP_CMD, ToF, CAN timeouts, P4 permit withdrawn): decelerate electrically to zero at the STOP_CMD rate (at least 72 rpm/s), engage the brake below 0.5 rpm, then report it (P4 drops EN only after both brakes report engaged, or 2 s).-  - Category 0, for hardware causes: EN drops, gates off and brake engaged at once, in hardware.-- Regeneration: the hardware chopper holds VMOT at or below 57.4 V worst case (on 56.76 V, off 56.17 V nominal; worst case over temperature 57.69 V on and 55.21 V off, inside the interface spec rule).-  - Firmware caps regenerated power at **1 kW per wheel** (the interface spec; the 3.0 ohm resistor absorbs 1.04 kW at the off threshold).-  - Firmware limits regen current to 15 A into the pack when VMOT is below 53 V.-  - Firmware stops commanding regen torque above 55.0 V.-  - **Stuck chopper (interface spec 7.1):** two signs, each qualified for 20 ms:-    - BRK_N_SNS under 0.15 V (BRK_N under 5 V) while BRK_SENSE is off: Q7 is shorted;-    - BRK_SENSE on while VMOT is under 55.0 V: the comparator or the gate driver is stuck.-  - Either one: drive BRK_INH high (Q13 opens the chopper path within microseconds), latch it until a power cycle, set FAULT and MOTOR_STATUS, stop commanding regeneration (short-phase braking only, limited to the winding rating), and make a Category 1 stop onto the parking brake.-  - Check it at bring-up: with the chopper idle, BRK_N_SNS reads VMOT x 0.0323; pulse BRK_INH and confirm Q13 opens (BRK_N stays at VMOT while BRK_SENSE is forced).-  - The resistor's series thermal cut-out is the second line, for a double fault: a **Schurter RTS-AC100** (210 C, 60 V DC, one-shot), accepted as Q13's backup in the interface spec-  - **Chopper latched off (the interface spec section 5.7; supersedes the v1.4.5 service-only clear):**-    - **Set by** any stuck-chopper sign above, or a blown cut-out: BRK_N_SNS under 0.15 V while BRK_SENSE is off. With the chopper off, a healthy resistor holds BRK_N at VMOT; an open cut-out lets the divider pull it to about 0 V.-    - **Action:** BRK_INH high (Q13 open). MOTOR_THERMAL byte 3 bit 5 and MOTOR_STATUS report it. No regeneration torque while Q13 is open.-    - **Short-phase braking** (DRIVE_CMD mode 3) **stays allowed** with Q13 open, because it dissipates in the windings, not the bus. Firmware limits it to **22 A peak** (about 7 to 14 A at 0.8 m/s), using the existing shunts and the DRV8353 current-sense amplifiers. No hardware change: the low-side FETs short the phases and Q13 is only in the chopper path.-    - **Clear:** bit 5 clears only on a power cycle, and only after the chopper self-test passes at boot. The self-test pulses BRK_INH with the bridge off: Q13 must open and close (BRK_N_SNS follows), and BRK_N_SNS must read VMOT x 0.0323 with the chopper idle, which proves the resistor and cut-out are intact. Until it passes, bit 5 stays set and the board refuses regeneration.-- **Required bench test before the first robot run (the interface spec):**-  - Drive one HCF166J3R0J with its RTS-AC100 in series at about 1 kW (about 18 A at 55 V) from a current-limited DC supply until the cut-out opens.-  - Record the time to open and the housing temperature (thermocouple at the body centre; at most 265 C).-  - Confirm no flame, no smoke escaping and no ejection; the resistor stays within 5 % afterwards.-  - Mount it as on the robot: vertical, leads down, free air.-- DC bus current limit 25 A (interface spec 2.3): estimated each PWM period from the three phase currents and duties (Idc = da*ia + db*ib + dc*ic). Torque is derated when the estimate reaches 25 A or when VMOT is low; MOTOR_STATUS fault bit 8 reports it.-- Brownout: run down to 30 V on VMOT (interface spec 4); firmware derates torque below 33 V.-- **Climb policy and motor protection (the interface spec section 2.1):**-  - 17 N m (7.5 A) is the motor's continuous thermal rating, 51 N m its peak. The p99 grade (12.1 %) needs 18.2 N m for up to 10 minutes; grades up to 23.4 % need 27 N m for at most 60 s. The robot's route planner enforces the 60 s limit; P1 does not.-  - **Thermistor derate:** torque is derated linearly from full at 90 C to zero at 100 C on the motor winding thermistor (MOT_NTC). 100 C is the ceiling until the winding insulation class is known; raise it only with the class from the vendor. Characterise thermistor at bring-up (type not stated on the wiring sheet).-  - **MOTOR_THERMAL (0x0C1 / 0x0C2), the interface spec :**-    - byte 3, derate flags: bit 0 thermistor, bit 1 I-squared-t, bit 2 FET temperature, bit 3 bus current limit, bit 4 regeneration cap, bit 5 chopper latched off;-    - byte 4: the applied torque limit in percent;-    - byte 5: reserved.-  - **I-squared-t backup:** a first-order winding model, integrating (I_rms^2 - 7.5^2) with a time constant set from the vendor's 10-minute p99 allowance; it derates on its own if thermistor reads open, shorted or implausible. MOTOR_THERMAL (0x0C1/0x0C2) reports thermistor and the estimate; MOTOR_STATUS reports the derate.-- **DRV8353 VM is fed from 12V_MAIN** (VIN_LOG). The VM pin is 80 V absolute, so it cannot sit on VMOT under the interface spec VGLS follows VM, so firmware derates current when VIN_LOG is under 10.5 V (low-side gate under 10 V).-- **Speed limits (interface spec 5.6, v1.2.9 and v1.3.0):**-  - Clamp the commanded wheel speed to SPEED_LIMIT (0x112) forward v_max, and reverse speed to its reverse v_max (at most 200 mm/s).-  - Reverse is allowed only while reverse v_max is above 0, or with DRIVE_CMD byte 9 bit 0 (OPERATOR_LIVE) set, still at most 0.2 m/s.-  - SPEED_LIMIT stale for 100 ms: ramp to zero and hold.-  - Deceleration toward a lower limit, and on STOP_CMD, is at least 72 rpm/s (1.5 m/s^2 at the 1.25 m wheel circumference).--### CAN-FD (interface spec 8)--- **Node ID:** 0x11 when SIDE is low (left), 0x12 when open (right). Read SIDE at boot.-- **Transmit:**-  - MOTOR_STATUS 0x0A1 / 0x0A2 every 10 ms.-  - MOTOR_ODOM 0x0B1 / 0x0B2 every 10 ms.-  - MOTOR_THERMAL 0x0C1 / 0x0C2 every 100 ms.-  - NODE_ALIVE 0x700 + node immediately at boot, then every 1 s. Only the first one after each boot sets the **BOOT flag** (byte 5 bit 7); bits 0 to 6 carry the CAN error counter saturating at 127 (the interface spec).-  - DIAG_RESP 0x680 + node.-- **Receive:** ESTOP_STATE 0x010, DRIVE_CMD 0x030 (use the wheel speed for this side), STOP_CMD 0x031, DIAG_REQ 0x600 + node.-- **Every frame ends with counter (u8) then CRC-8.**-  - The CRC is CRC-8/SAE-J1850: poly 0x1D, init 0xFF, no reflection, xorout 0xFF, check value over "123456789" = 0x4B.-  - It covers bytes 0 up to and including the counter (section 8.3).-  - A bad CRC is always dropped and counted.-  - Reference implementation:--    ```c-    uint8_t crc8_j1850(const uint8_t *p, size_t n) {-        uint8_t c = 0xFF;-        while (n--) { c ^= *p++; for (int i = 0; i < 8; i++) c = (c & 0x80) ? (uint8_t)((c << 1) ^ 0x1D) : (uint8_t)(c << 1); }-        return c ^ 0xFF;-    }-    /* crc8_j1850("123456789", 9) == 0x4B: assert this at boot */-    ```--- **Counter, transmit:** per identifier, start at 0 after every boot and add 1 mod 256 per frame.-- **Counter, receive (8.3a):** per identifier per sender, with d = (received - last accepted) mod 256:--  | d | Action |-  |---|---|-  | 1 | accept |-  | 2 to 15 | accept, count lost frames |-  | 0 | drop |-  | 16 to 255 | resync: store the counter as the new reference and do not act on this frame |--  A NODE_ALIVE with the **BOOT flag** set from that sender forces a resync once per boot (the interface spec; uptime no longer does).-- **Stops act on a good CRC whatever the counter (8.3):**-  - ESTOP_STATE with any cause bit set, the safety switch open, or EN_L / EN_R low (for this side).-  - STOP_CMD.-  - DRIVE_CMD mode 0 (idle), 3 (electrical brake) or 4 (park).--  The counter gates only frames that permit or increase motion.-- **Timeouts (8.3b),** from the last accepted frame of that identifier, reported in MOTOR_STATUS fault bit 7:--  | Watched frame | Timeout | Action |-  |---|---|---|-  | DRIVE_CMD | 50 ms | ramp to zero torque and hold; resume only on a new DRIVE_CMD after a resync |-  | ESTOP_STATE | 100 ms | treat as a stop: ramp to zero torque and hold |-  | SPEED_LIMIT | 100 ms | ramp to zero and hold (section 5.6) |--  EN in hardware still rules over both.-- **Byte layouts:** interface spec 8.4.-  - MOTOR_STATUS VMOT is in 10 mV units; this board measures it on VMOT_SNS. Byte 13: bit0 EN seen, bit1 parking brake released, bit2 parking brake fault.-  - DRIVE_CMD byte 8 mode 4 = park; byte 9 bit 0 = OPERATOR_LIVE.-  - MOTOR_THERMAL: the FET temperature is estimated from BRD_NTC, which sits beside the bridge. Calibrate the offset against thermal analysis.--## Power-up defaults that keep the bridge off--| Signal | Default | Why |-|---|---|---|-| DRV_EN | 100 k pull-down | DRV8353 asleep while the MCU resets |-| BRK_PWM, BRK_HOLD | 100 k pull-downs | parking brake engaged while the MCU resets |-| MCU_OK | 100 k pull-down | FAULT released (fault) while the MCU resets |-| CAN_STB | 10 k pull-up | transceiver in standby until firmware is ready |-| BOOT0 | 10 k pull-down | boots from flash |-| EN | 10 k pull-down | a cut EN wire disables the bridge |