From 6551a31a4ccf7b59ee7e5cf8f498efe3ebde408f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Thu, 30 Sep 2021 18:44:05 +0200 Subject: [PATCH] Fixed variable overflow while flashing addresses bigger than 0xFFFF Also added some docs and fixed spelling issues --- README.md | 24 +++++++++++++----------- src/bootloader.cpp | 2 +- src/bootloader.h | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9ee9877..0b6019a 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ CAN bus bootloader for **AVR microcontrollers** attached to an **MCP2515** CAN c * Use Extended Frame Format (EFF, default) or Standard Frame Format (SFF) CAN-IDs * Very low impact on active CAN systems which enables to flash MCUs in active networks +## Used frameworks and libraries + +*MCP-CAN-Boot* is made as a [PlatformIO](https://platformio.org/) project. +It uses parts of the [Arduino](https://www.arduino.cc/) framework. + +For controlling the MCP2515 a modified version of the [Arduino MCP2515 CAN interface library](https://github.com/autowp/arduino-mcp2515) is used. + ## Currently supported AVR controllers * [ATmega32](http://ww1.microchip.com/downloads/en/devicedoc/doc2503.pdf) @@ -39,8 +46,11 @@ To flash the _MCP-CAN-Boot_ bootloader you need to use an ISP programmer. Make sure to set the fuse bits correctly for a 2048 words bootloader and boot resest vector enabled. Otherwise the bootloader will not work. -Examples for each supported controller are in `platformio.ini` (commented out by default). -To set the fuse bits, enable the lines starting with `board_fuses.` for your controller. _Always check/edit the fuses values to fit your needs!_ +### Set the fuse bits + +Examples for each supported controller are in `platformio.ini` (commented out by default). + +To set the fuse bits, enable the lines starting with `board_fuses.*` for your controller. _Always check/edit the fuses values to fit your needs!_ If you set the correct values, you may run `pio run --target fuses` to program the fuses on your controller. ## CAN bus communication @@ -54,7 +64,7 @@ The whole communication via the CAN bus uses only two CAN-IDs. Using this two IDs nearly at the end of CAN-ID range with the lowest priority there will be almost none interference flashing an MCU in a active CAN system. -Each CAN message consists of fixed eight data bytes. +Each CAN message consists of eight data bytes. The first four bytes are used for MCU identification, commands, data lengths and data identification. The other four bytes contain the data to read or write. ## Flash-App @@ -337,14 +347,6 @@ Additionally a *start app* command may be send at any time by the flash applicat ![Communication example](./doc/flash-sequence.svg) -## Used frameworks and libraries - -*MCP-CAN-Boot* is made as a [PlatformIO](https://platformio.org/) project. - -It uses parts of the [Arduino](https://www.arduino.cc/) framework. - -For controlling the MCP2515 a modified version of the [Arduino MCP2515 CAN interface library](https://github.com/autowp/arduino-mcp2515) is used. - ## License **CC BY-NC-SA 4.0** diff --git a/src/bootloader.cpp b/src/bootloader.cpp index 9875de2..7da2650 100644 --- a/src/bootloader.cpp +++ b/src/bootloader.cpp @@ -453,7 +453,7 @@ void boot_program_page (uint16_t page, uint8_t *buf) { uint16_t i; uint8_t sreg; - uint32_t addr = page * SPM_PAGESIZE; + uint32_t addr = ((uint32_t)page) * SPM_PAGESIZE; // type cast of `page` to support addresses bigger than 0xFFFF // Disable interrupts sreg = SREG; diff --git a/src/bootloader.h b/src/bootloader.h index 358d8ee..d776049 100644 --- a/src/bootloader.h +++ b/src/bootloader.h @@ -21,7 +21,7 @@ /** * Command set version of this bootloader. - * Used to identify a possibly incompatilbe flash application on remote. + * Used to identify a possibly incompatible flash application on remote. */ #define BOOTLOADER_CMD_VERSION 0x01