• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created about 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The bootloader used to flash our CAN-connected boards

Bootloader protocol

Python tests

Unit tests

STM32 builds

This repository contains the code used for the bootloader running on every microcontroller in our robots. It allows us to quickly update the firmware on all (>20) boards quickly and without disassembly or additional electrical connections.

Config pages

The bootloader code is followed by two pages of bootloader config. The two pages are for redundancy and are checked by a CRC32 placed at the beginning of a page. The bootloader checks the configuration CRC at boot. If an invalid page is detected, its content is replaced by the redundant page.

After the bootloader has updated one of the two configuratio pages, it verifies it before proceeding to the second one. This ensures that there is always a valid configuration page to prevent bricking a board.

The config contains the following informations, stored as a messagepack map:

  • ID: Unique node identifier, ranging from 1 to 127.
  • name: Human readable name describing the board (ex: "arms.left.shoulder"). Max length: 64
  • device_class: Board model (ex: "CVRA.MotorController.v1"). Max length: 64
  • application_crc: Application CRC. If the CRC matches the bootloader will automatically boot into it after a timeout.
  • application_size: Needed for CRC calculation.
  • update_count: Firmware update counter. Used for diagnostics and lifespan estimation.

Performance considerations

Assuming :

  • CAN speed is 1 Mb/s
  • CAN overhead is about 50%
  • Protocol overhead + data drop is about 10%. The size of a write chunk might affect this since invalid data is dropped by chunk.
  • Binary size : 1 MB
  • The bottleneck is in the CAN network, not in the CRC computation or in the flash write speed.
  • The time to check the CRC of each board can be neglected.
  • We use multicast write commands to lower bandwith usage.

We can flash a whole board (1MB) in about 20 seconds. If all board in the robot run the same firmware, this is the time required to do a full system update!

Safety features

The bootloader is expected to be one of the safest part of the robot firmware. Correcting a bug in the bootloader could be very complicated, requiring disassembly of the robot in the worst cases. Therefore, when implementing the bootloader or the associated protocol, the following safety points must be taken into account:

  • The bootloader must never erase itself or its configuration page.
  • It should never write to flash if the device class does not match. Doing so might result in the wrong firmware being written to the board, which is dangerous.
  • If the application CRC does not match, the bootloader should not boot it.
  • On power up the bootloader should wait enough time for the user to input commands before jumping to the application code.

Building

  1. Run CVRA's packager script: packager.
  2. Build libopencm3: pushd libopencm3 && make && popd.
  3. Build your desired platform: cd platform/motor-board-v1 && make.
  4. Flash the resulting binary to your board: make flash.

More Repositories

1

pid

A PID controller implementation
C++
68
star
2

robot-software

CVRA monorepo - All software running on our bots lives here
C
44
star
3

CAN-USB-dongle-fw

slcan firmware for the CVRA CAN to USB dongle
C
36
star
4

goap-cpp

A C++ implementation of Goal Oriented Action Planning from
C++
29
star
5

lwip_ucos2

A port of LWIP on Micrium uC-OS/2 OS
C
16
star
6

arm-cortex-tools

Commonly used code for projects using ARM Cortex-M with ChibiOS
C
13
star
7

motor-control-board

DC Motor Controller with CAN Interface. CC-BY 4.0
12
star
8

CAN-USB-dongle

CAN bus to USB adapter dongle
12
star
9

msgbus

Microcontroller message bus
C++
10
star
10

can-io-board

small, cheap IO board on CAN bus. CC-BY 4.0
9
star
11

stm32-ethernet-over-usb

C
8
star
12

lwip

A Lightweight TCP/IP stack
C
8
star
13

arm-cortex-mpu

Memory Protection Unit driver for Cortex M-4.
C
8
star
14

kicad-lib

KiCad Library
8
star
15

clang-format-action

A github action to run clang-format on all C/C++ sources in a repository
Shell
7
star
16

goap-python

GOAP: Goal Oriented Action Planner
Python
6
star
17

filter

A collection of signal processing filters.
C++
6
star
18

tim561_lidar_driver

simple python driver for SICK TIM561 LIDAR
Python
6
star
19

inverse-kinematics

Time-optimal trajectory generator for Debra's arms
Python
5
star
20

modules-old

The library made for the differents robots by the CVRA
C
5
star
21

motor-control-firmware

DEPRECATED! replaced by cvra/robot-software
C
4
star
22

goldorak

Project Goldorak, CVRA's small robot for Eurobot 2016, running ROS
C++
4
star
23

LIDAR-Simulation

Gazebo simulation of the Sick TiM 561 for positioning and environment information extraction purpose
C++
3
star
24

state-machine

State machine manager in C.
C
3
star
25

platform-abstraction

Platform abstraction layer for microcontrollers
C
3
star
26

parameter_flash_storage

Save a parameter tree in flash memory for persistency. (deprecated, now a part of https://github.com/cvra/robot-software)
C
3
star
27

nucleo144-shield

IO shield for the ST Nucleo144 master board. CC-BY 4.0
3
star
28

uwb-beacon-board

Universal beacon system board based on UWB modules and an IMU. CC-BY 4.0
3
star
29

kprintf

C
2
star
30

actuator-board

PCB for controlling our robot's RC servo and vacuum pump actuators including sensor feedback.
2
star
31

localization-stack

Kalman, LIDAR, Odometry
Python
2
star
32

CRC

C
2
star
33

uwb-beacon-fw

UWB beacon software repo
C
2
star
34

3phase-board

1
star
35

sensor-board

Time of flight distance and RGB color sensor board with CAN interface. CC-BY 4.0
Python
1
star
36

fifo

fifo buffer
C++
1
star
37

odometry

Pose estimation through asynchronous odometry
C++
1
star
38

motor-control-uavcan-dsdl

Data Structure Description for CVRA's DC Motor Controller.
1
star
39

hall-sensor-board

Hall sensor board used for axis indexing
1
star
40

coding-style

The coding style rules used at the club.
1
star
41

VL53L0X-tof-sensor-board

PCB design for the VL53L0X time of flight distance sensor connected over CAN
Python
1
star
42

chibios-syscalls

Better syscalls implementations for ChibiOS
C
1
star
43

debra-old

Code source of our big robot Debra (2012-2014)
C
1
star
44

cvra.github.io

The website of the club
SCSS
1
star
45

ugfx

Mirror of https://git.ugfx.io/uGFX/uGFX
C
1
star
46

doc-elec

Documentation for the various electronics of the club
1
star
47

simplerpc

Simple Remote Procedure Call protocol
Python
1
star
48

packager

Build system used for embedded software at CVRA
Python
1
star
49

can-io-board-fw

C
1
star
50

watchdog

A software watchdog implementation
C++
1
star
51

serializer

A simple data serialization library based on MessagePack
C++
1
star