Bootloading uCAN's using the AIO

From OpenMotics
Jump to navigation Jump to search

Introduction

The AIO has a built-in CAN engine that is used to communicate and bootload the connected Micro CAN's. The Micro CAN understands a large set of instructions when in App mode (see CAN Communication Protocol) and a limited set when in Bootload mode (Bootload CAN Communication Protocol).

Micro CAN fundamentals

SID

Every CAN message has a SID identifier. 4 different SID's are used:

  • SID=0: This SID will only be used in bootloader mode of the Micro CAN. When the Micro CAN is in normal mode, those message will be ignored by the Micro CAN. All messages with SID 0 will be tunnelled towards the UART API without any interpretation of the DSPIC. Messages with SID 0 are used to transfer pallets.
  • SID=1: This SID will only be used in bootloader mode of the Micro CAN. When the Micro CAN is in normal mode, those message will be ignored by the Micro CAN. All messages with SID 0 will be tunnelled towards the UART API without any interpretation of the DSPIC. Messages with SID 1 are used to communicate with the bootloader.
  • SID=5: This SID is used to prepare the Micro CAN for bootloading. All messages with SID=5 will be sent to the Micro CAN and their response will be tunnelled over the DSPIC (=Master controller in AIO) directly to the UART API (see API Reference Guide AIO). In other words, when using SID=5 in communication towards a Micro CAN (using API instruction FM), the response of the Micro CAN will be sent directly to the UART API (FM) of the AIO without any interpretation nor any actions of the DSPIC.
  • SID=6: All normal communication uses this SID so all messages generated by the AIO will be using this SID. These messages will be interpreted by the DSPIC and will not be tunnelled to the UART API.

CAN Communication Protocol

Every Micro CAN has a 3 byte ID that is used to directly communicate with a specific Micro CAN. Micro CAN's will receive their ID from the factory. The full CAN Communition Protocol can be found here: CAN Communication Protocol.

Micro CAN Eeprom

The Micro CAN Module is equipped with a Microchip 18F46K80 with a built-in eeprom of 1k. A few eeprom bytes (ID and Bootloader Time) are used for bootloader purposes. Below you can find the eeprom table with some explanantion:

Eeprom address Description
0
Link of switch Nr 0
1
Link of switch Nr 1
2
Link of switch Nr 2
3
Link of switch Nr 3
4
Link of switch Nr 4
5
Link of switch Nr 5
6
Link of switch Nr 6
7
Link of switch Nr 7
8
Sensor Link of the first sensor
9
Sensor Link of the second sensor
10
Module Link
11
Indicate if the ID is newly generated ("N") or it's an existing ID ("E") -> ID_NE
12
ID0 of this Micro CAN module
13
ID1 of this Micro CAN module
14
ID2 of this Micro CAN module
15
Modbus address of the connected Modbus thermostat
16
Thermostat Type of the connected thermostat
17
Thermostat Model of the connected thermostat
18
Thermostat Speed of the connected thermostat
19
Thermostat Mode of the connected thermostat (Not implemented)
20
Status of 3color led and buzzer:.BIT0->Buzzer ON(1)/OFF(0) for all functions, .BIT1->Buzzer ON(1)/OFF(0) for non-linked switches, .BIT2->TriColor status led ON(1)/OFF(0)
21
CAN settings: If =255 -> std built-in CAN settings are used (125kbps, BRGCON1=79, BRGCON2=231, BRGCON3=1), If =1 -> Custom CAN settings are used (see byte 22, 23 and 24)
22
CAN setting: This byte represents Microcontroller (18F46K80) register BRGCON1. If Byte21=1, this value will be copied in the specified register at startup.
23
CAN setting: This byte represents Microcontroller (18F46K80) register BRGCON2. If Byte21=1, this value will be copied in the specified register at startup.
24
CAN setting: This byte represents Microcontroller (18F46K80) register BRGCON3. If Byte21=1, this value will be copied in the specified register at startup.
25
CAN setting: This byte represents the CRC8 of Byte22-24. If the calculated CRC8 value of Byte22-24 is not equal to Byte25, the values of Byte22-24 are ignored and the standard value is taken.
100
Bootloader Version: This byte represents the MSB of the bootloader version that is written in this location by the boot loader.
101
Bootloader Version: This byte represents the LSB of the bootloader version that is written in this location by the boot loader.
102
Bootloader Status feedback: This will indicate whether the bootloader will use the 6 feedback leds to show status (= 255) or leave the feedback leds off (= 0). The onboard RGB led will always show the bootloader status regardless of this setting.
128
Bootloader Time: This byte will indicate the number of seconds the Micro CAN will remain in bootloader after a reset. When Bootloader Time=0 then the Bootloader will jump to App mode immediately.
129
Bootloader Startup message: If Byte.BIT0=1 -> App mode will send CAN message after reset (CAN message Byte0/1=94/94), If Byte.BIT1=1 -> Bootloader will send CAN message after reset (CAN message Byte0/1=94/94)

RGB status led

Bootloader

In the bootloader, the RGB status led will indicate what's going on.

  • When entering the bootloader, the RGB led will turn yellow
  • As soon as the bootloader is started, the RGB led will start blinking yellow with an alternate color.
    • This color will indicate the reason why the bootloader is active.
      • Off: The application explicitly asked to enter bootloader
      • Turquoise: The firmware has a checksum (CRC) error
      • Purple: The application firmware did not start correctly
    • The blinking frequency shows what is going on
      • Steady ~1Hz blinking: The bootloader is idle (awaiting instructions)
      • Irregular faster blinking: The bootloader is active processing data (flashing)
    • If the feedback leds are also configured to show status, they will blink in the same frequency as the RGB led, but there is no color indication.

Communicate with the Micro CAN

To communicate with the Micro CAN, 2 UART instructions will be used:

  • FS: Request information like number of Micro CAN's on the CAN Bus and ID's of the connected Micro CAN's.
  • FM: This will generate messages on the CAN bus to ping Micro CAN's, Set Bootloader Time, Request current Firmware version, Reset and Flash the Micro CAN's with new firmware

See API Reference Guide AIO for more details

Bootloading a Micro CAN

Prepare Bootloading by requesting the necessary information

All the below instruction will be performed in App mode (the Micro CAN is not yet in bootload mode).

  1. Request the number of Micro CAN's connected on the AIO by using API instruction "FS"
  2. Request the ID's (ID0.ID1.ID2) of the different Micro CAN's connected on the AIO by using API instruction "FS"
  3. Ping the Micro CAN with ID0.ID1.ID2 to check if the Micro CAN is responding and is in app mode (instruction "FM", CAN Communication protocol Byte0/1=0/96, SID=5)
  4. Check the firmware version to see if this Micro CAN needs an update (2x instruction "FM" to get the FW version, CAN Communication protocol Byte0/1/5=0/198/5, CAN Communication protocol Byte0/1/5=0/198/6, SID=5)
  5. Set the Bootloader Time (>0) so the processor knows, after next startup, he needs to remain in bootloader mode (instruction "FM", CAN Communication protocol Byte0/1=0/123, SID=5)
  6. Reset the Micro CAN (instruction "FM", CAN Communication protocol Byte0/1=0/94, SID=5)

Once in Bootloader ...

After reset, the Micro CAN remains in Bootloader mode until the bootload time has expired without communicating with the Micro CAN.

  1. Ping the Micro CAN with ID0.ID1.ID2 to check if the Micro CAN is responding and is in bootload mode (instruction "FM", CAN Communication protocol Byte0/1=0/96, SID=1)
  2. Start Bootload sequence (Prepare boot loading, start sending pallets, instruction FM, SID=0/1)
  3. Once the pallets are being sent, CRC is checked, Set the Bootloader Time (=0) so the processor knows, after next startup, he doesn't need to remain in bootloader mode (instruction "FM", CAN Communication protocol Byte0/1=0/123, SID=1)
  4. Reset the Micro CAN (instruction "FM", CAN Communication protocol Byte0/1=0/94, SID=1)
  5. Ping the Micro CAN with ID0.ID1.ID2 to check if the Micro CAN is responding and is in app mode (instruction "FM", CAN Communication protocol Byte0/1=0/96, SID=5)
  6. Check the firmware version to see if this Micro CAN is updated to the correct version (2x instruction "FM" to get the FW version, CAN Communication protocol Byte0/1/5=0/198/5, CAN Communication protocol Byte0/1/5=0/198/6, SID=5)