Skip to content

Commit

Permalink
Fixed variable overflow while flashing addresses bigger than 0xFFFF
Browse files Browse the repository at this point in the history
Also added some docs and fixed spelling issues
  • Loading branch information
crycode-de committed Sep 30, 2021
1 parent d79d901 commit 6551a31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion src/bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6551a31

Please sign in to comment.