Monday, September 1, 2014

Bootloader concept

Our CAN bus will work between 20 to max 100k baud rate. This limits me between 180 to max 900 CAN messages per second (given that each CAN message contains 8 bytes).

Any CAN-message consists of 47 bits overhead (including 3 bits 'Interframe Space') plus 0 to 8 bytes data (not taking into account the possibility of extra stuff-bits, which will increase the number of bits slightly). 

The used processor PIC24EP128 has 128kb of flash. In worst case, the entire flash has to be transmitted over the CAN bus for the firmware update. This means 88042 addresses of each 3 bytes will have to be transmitted. If we also include the flash address destination in each message, than again this would require 3 bytes.

With CAN, you can send 8 bytes maximum for each message. If we arrange it with 3 bytes FLASH address destination and 3 bytes FLASH data for destination, this means we can at most do 1 address for each can message thus we need to send 88042 CAN messages if the entire FLASH space is used.

With the maximum CAN bus messages per seconds that I've shown in the start, this leads to a firmware upload time between 489 seconds (8minutes) to 97 seconds. Of course, there are some optimizations reachable to reduce this.

Comm spec.
Each bracked equals a byte, max 8 byte for a CAN msg.

If mode = 255

[MODE=255][ADDR2][ADDR1][ADDR0][DATy2][DATy1][DATy0]

If mode = 254

In this mode the address will be automatically incremented. And each CAN frame will consist data for two FLASH data addresses.

[MODE=254][DATx2][DATx1][DATx0][DATy2][DATy1][DATy0]

Combining the above two methods almost reduces the time with 50%. Leaving 4 minutes as worst case scenario as wait time. For my project, this is acceptable.

If mode =  253

When all the firmware data has been transmitted, the PC will send a mode = 3 message with as data the start and end address of the FLASH memory.

[MODE=253][START_ADDR2][ADDR1][ADDR0][END_ADDR2][ADDR1][ADDR0]

This will request a CRC16 from the updated node. The CRC16 will be made up from the written data in the flash, not the received data. This is to prevent the possibility that there was a write error into the flash and to make sure that everything went fine.

If mode =  252

Erases the flash DST from start to end.

[MODE=252][START_ADDR2][ADDR1][ADDR0][END_ADDR2][ADDR1][ADDR0]

If mode =  251

Reads the flash DST and respond this on the CANbus network as a RTR

PC -> Embedded
[MODE=251][ADDR2][ADDR1][ADDR0]

Embedded -> PC
[MODE=251][ADDR2][ADDR1][ADDR0][DATy2][DATy1][DATy0]












No comments:

Post a Comment