Micro CAN Bootloader

From OpenMotics
Jump to navigation Jump to search

Introduction

This Section describes the Bootloader of the Micro CAN Modules equipped with a Microchip 18F46K80.

Bootloading is made possible by creating a channel between the Master and the Micro CAN over the CAN Control in other words, direct communication has been setup without interaction of any of components in between.

Typical Bootload sequence:

  1. The BB knows the ID's of the connected CAN Controls, this information is needed in the bootload process.
  2. Request the number of Micro CAN's of a CAN Control (instruction "FS")
  3. Request the ID's (ID0.ID1.ID2) of the different Micro CAN's connected to a CAN Control (instruction "FS")
  4. Set the ID of the CAN Control to which it will communicate (instruction "Fm")
  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)
  6. 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)
  7. Set the Bootloader Mode so the processor knows, after next startup, he needs to remain in bootloader mode (instruction "FM", CAN Communication protocol Byte0/1=0/123)
  8. Reset the Micro CAN (instruction "FM", CAN Communication protocol Byte0/1=0/94)
  9. After reset, the Micro CAN remains in Bootloader mode
  10. 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)
  11. Start Bootload sequence (see separate section)
  12. Reset the Micro CAN (instruction "FM", CAN Communication protocol Byte0/1=0/94)
  13. 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)
  14. 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)
  15. Go to STEP3 if other Micro Modules needs an update
  16. Go to STEP2 when the installation has more CAN Controls
  17. Copy all eeprom settings to RAM by performing an eeprom activate instruction (instruction "AE")

API instruction used

FS -> Request information from a CAN control to prepare boot loading of a Micro CAN

This instruction will request information from the CAN control like the number of Micro CAN's are connected to a certain CAN control as well as the ID's of the Micro CAN.

Request G->M
' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
STR F S CID ID0 ID1 ID2 ID3 Instr can_nr 0 0 0 0 C CRC.Byte1 CRC.Byte0 13 10
  • ID0..3 =ID of the CAN Control Module
  • CID: Byte 2 will always contain the Communication ID. When the Gateway sends a request to the Master, the Gateway will add the communication ID (communication sequence) in byte2. The Master will always answer the request of the Gateway with the same communication ID. CID is set between 1 and 255. When CID is set to 0, it is not used.
  • Instr: If Instr=0 -> Request number of connected Micro CAN's (can_nr is ignored), If instr=1 -> Request ID of Micro CAN with can_nr
  • If for example the received number of connected Micro CAN's is 7, the software should request the ID of can_nr 0 to 6.
Response M->G
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
F S CID ID0 ID1 ID2 ID3 Instr can_nr data0 data1 data2 0 C CRC.Byte1 CRC.Byte0 13 10
  • data0..2: These are the 3 data bytes containing the requested information:
    • Instr=0: data0 contains the number of Micro CAN's connected to the CAN Control with ID0..3. data1 and data2 can be ignored.
    • Instr=1: data0 contains ID0 of the requested Micro CAN, data1 contains ID1, data2 contains ID2

Fm -> Set the ID of the CAN Control module

To be able to use instruction "FM", first the instruction "Fm" must be used to set the ID of the CAN Control.

Request G->M
' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
STR F m CID ID0 ID1 ID2 ID3 0 0 0 0 0 0 C CRC.Byte1 CRC.Byte0 13 10
  • ID0..3 =ID of the CAN Control Module
  • CID: Byte 2 will always contain the Communication ID. When the Gateway sends a request to the Master, the Gateway will add the communication ID (communication sequence) in byte2. The Master will always answer the request of the Gateway with the same communication ID. CID is set between 1 and 255. When CID is set to 0, it is not used.
  • Instr: If Instr=0 -> Request number of connected Micro CAN's (can_nr is ignored), If instr=1 -> Request ID of Micro CAN with can_nr
  • If for example the received number of connected Micro CAN's is 7, the software should request the ID of can_nr 0 to 6.
Response M->G
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
F m CID ID0 ID1 ID2 ID3 Instr can_nr data0 data1 data2 C CRC.Byte1 CRC.Byte0 0 13 10
  • data0..2: These are the 3 data bytes containing the requested information:
    • Instr=0: data0 contains the number of Micro CAN's connected to the CAN Control with ID0..3. data1 and data2 can be ignored.
    • Instr=1: data0 contains ID0 of the requested Micro CAN, data1 contains ID1, data2 contains ID2

FM -> Put messages on the CAN bus

This instruction will forward messages through the CAN control directly on the connected CAN bus. The response will return through the CAN control towards the Master.

SID is a message identifier used for message on the CAN bus. In the Openmotics environment, 3 different SID values are used:

  • SID=6: All normal communication uses this SID so all messages generated by the CAN control will be with this SID. These message will not be tunnelled to the Master.
  • 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 Master without any interpretation of the CAN Control.
  • SID=5: This SID is used to prepare the Micro CAN for bootloading. All messages with SID=5 will be tunnelled to the Master without any interpretation of the CAN Control.

The SID used in this instruction should be the following:

  • When sending instruction from the CAN Communication Protocol, always use SID=5
  • When sending pallets (when the Micro CAN is in Bootloading mode), always use SID=0
Request G->M
' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
STR F M CID nr_of_bytes SID C_Byte0 C_Byte1 C_Byte2 C_Byte3 C_Byte4 C_Byte5 C_Byte6 C_Byte7 C CRC.Byte1 CRC.Byte0 13 10
  • Nr Of Bytes: These are the number of bytes that will be sent on the CAN Bus (Min 2, Max 8)
  • C_Byte0..C_Byte7: These are the bytes that will be put on the CAN bus
  • Before using this instruction, instruction "fm" must be used to set the CAN Control ID's so the Master knows with which CAN control the communication must be done
  • CRC=sum of Byte0 to Byte12
Response M->G
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
F M CID nr_of_bytes SID C_Byte0 C_Byte1 C_Byte2 C_Byte3 C_Byte4 C_Byte5 C_Byte6 C_Byte7 C CRC.Byte1 CRC.Byte0 13 10
  • Nr Of Bytes: These are the number of bytes that the Micro CAN responded (Min 2, Max 8)
  • C_Byte0..C_Byte7: These are the bytes that the Micro CAN has been sending back

Example instruction to prepare Bootloading 1 Micro CAN

In this below example, the CAN Control has ID 67.121.30.104

Request the number of Micro CAN's of a CAN Control

Request G->M
' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
STR 70 83 5 67 121 30 104 0 0 0 0 0 0 67 1 224 13 10
Response M->G
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
70 83 5 67 121 30 104 0 0 2 0 0 0 67 1 226 13 10

So with the above response, we know that 2 Micro CAN's are connected to this CAN Control. Next instruction is to know the ID's of the connected Micro CAN's.

Slave Eeprom table for a Micro CAN module

The Micro CAN Module is equipped with a Microchip 18F46K80 with a built-in eeprom of 1k. A few eeprom byte 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
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
Successful app launch : If Byte 129=1 then the application has been started successfully (app will write 1 in this byte, bootloader will write 0 after flashing a new app)