mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-12-06 09:06:52 +01:00
125 lines
3.4 KiB
YAML
125 lines
3.4 KiB
YAML
---
|
|
# Seeed XIAO STM32C5 as a CANopen node (mrk's canopen hub + canopen_entities), MCUboot, OTA over CAN from can2mqtt
|
|
# (upload .esphome/build/<node>/.west_build/zephyr/zephyr/zephyr.signed.bin).
|
|
# Needs: substitutions node_id; the esphomeplatformzephyr fork (esphome-zephyr).
|
|
# Pinout:
|
|
# PB12 user LED (active low) -> LED (light binary)
|
|
# PH2 BOOT0, left alone (a pull-up there sends software resets to ROM DFU)
|
|
# PB5/PB13 FDCAN2 RX/TX, PB14 CAN_STB -> on-board transceiver (board DTS)
|
|
# PB3/PB4 I2C2 SCL/SDA, LSM6DS3TR-C @0x6A -> on-board IMU (motion lsm6ds)
|
|
# First flash (TinyUF2 erased with mcu-stm32-xiao-c5-eraser.yaml), hold BOOT + press RESET for ROM DFU:
|
|
# dfu-util -a 0 -s 0x08000000 -D .esphome/build/<node>/.west_build/mcuboot/zephyr/zephyr.bin
|
|
# dfu-util -a 0 -s 0x08008000:leave -D .esphome/build/<node>/.west_build/zephyr/zephyr/zephyr.signed.bin
|
|
|
|
external_components:
|
|
- source: github://mrk-its/esphome-canopen@dc6efff43e0076a5c2820800e6ff5ce28ee4c678 # canopen_entities; newer needs consts the zephyr fork lacks
|
|
components: [canopen, canopen_entities]
|
|
|
|
stm32:
|
|
variant: STM32C5
|
|
board: xiao_stm32c5
|
|
framework:
|
|
advanced:
|
|
bootloader: mcuboot
|
|
# required by the fork for MCUboot on the XIAO; the first flash is dfu-util by hand (see above)
|
|
runner: stm32cubeprogrammer
|
|
|
|
logger:
|
|
logs:
|
|
# canbus logs every frame at DEBUG; over USB CDC that stalls the loop and the RX queue overflows
|
|
canbus: INFO
|
|
|
|
i2c:
|
|
# pins come from the board DTS (i2c2: PB3/PB4), STM32C5 takes no sda:/scl:
|
|
- id: i2c_imu
|
|
dts_node_override: i2c2
|
|
|
|
motion:
|
|
- platform: lsm6ds
|
|
id: imu
|
|
i2c_id: i2c_imu
|
|
address: 0x6A
|
|
update_interval: 5s
|
|
|
|
sensor:
|
|
- platform: lsm6ds
|
|
id: imu_temp
|
|
name: IMU Temperature
|
|
- platform: motion
|
|
motion_id: imu
|
|
id: pitch
|
|
type: pitch
|
|
name: Pitch
|
|
- platform: motion
|
|
motion_id: imu
|
|
id: roll
|
|
type: roll
|
|
name: Roll
|
|
|
|
output:
|
|
- platform: gpio
|
|
id: led_out
|
|
pin:
|
|
number: PB12
|
|
inverted: true
|
|
|
|
light:
|
|
- platform: binary
|
|
name: LED
|
|
id: led
|
|
output: led_out
|
|
|
|
# no button on PH2: it is BOOT0, and with BOOT_SEL on the pin (after tinyuf2_eraser) an internal pull-up there makes
|
|
# every software reset (OTA, reboot) start the ROM DFU bootloader instead of MCUboot
|
|
|
|
canbus:
|
|
- platform: zephyr_can
|
|
id: can_bus
|
|
can_id: 0
|
|
bit_rate: 500kbps
|
|
# an SDO block (16 frames) arrives back to back and must fit the RX queue (default 8)
|
|
rx_buffer_size: 32
|
|
|
|
canopen:
|
|
id: can_gate
|
|
canbus_id: can_bus
|
|
node_id: ${node_id}
|
|
heartbeat_interval: 5s
|
|
|
|
canopen_entities:
|
|
canopen_id: can_gate
|
|
entities:
|
|
- id: led
|
|
index: 1
|
|
tpdo: 0
|
|
# 2-byte encoding over min..max, so the three fit one TPDO
|
|
- id: pitch
|
|
index: 3
|
|
tpdo: 1
|
|
size: 2
|
|
min_value: -180
|
|
max_value: 180
|
|
- id: roll
|
|
index: 4
|
|
tpdo: 1
|
|
size: 2
|
|
min_value: -180
|
|
max_value: 180
|
|
- id: imu_temp
|
|
index: 5
|
|
tpdo: 1
|
|
size: 2
|
|
min_value: -40
|
|
max_value: 125
|
|
remote_logs:
|
|
level: INFO
|
|
|
|
ota:
|
|
- platform: canopen_entities
|
|
# the XIAO's board layout has slot0 one sector larger than slot1 (swap-move); with the fork's default
|
|
# (offset) MCUboot finds the slots incompatible and never installs the update
|
|
swap_method: move
|
|
|
|
# confirms the new MCUboot image after a good boot; without it MCUboot rolls back at the next reset
|
|
safe_mode:
|