arduino / arduino/ArduinoCore-megaavr

Save some space in MuxTO

Open
#147 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
111
Forks
65
PR merge metrics
No merged PRs in 30d

Description

Space in MuxTO is very tight; depending on compiler version, it can't be built to fit into the available 12k of flash.
This piece of code is (should be) a drop-in replacement for the CRC function in crc16.cpp. It does bitwise calculation of the CRC instead of the table-driven byte-at-a-time algorithm that is currently used. This is presumably about 8x slower (which I believe shouldn't matter), but it eliminates the 512byte crc_table, making it about 1/40th the flash size.

(CRC Algorithm tested on a desktop, and code compiles in Arduino. Not yet tested in an actual Nano every...)

```
/*
* "reflected" (LSB first) CCITT CRC-16
*/
uint16_t POLY = 0x8408; // bit reversed 0x1021

uint16_t CRC::next(uint8_t newchar, uint16_t crc) {
int j;
uint_fast16_t crcshadow = crc ^ newchar; // move some uxth instructions outside the bit loop.
for (j = 0; j < 8; j++) {
if (crcshadow & 1) { // Check if LSB is set
crcshadow = (crcshadow >> 1) ^ POLY;
} else {
crcshadow >>= 1;
}
}
return crcshadow;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in crc16.cpp and compare the current table-driven CRC function with the bitwise replacement shown in the issue. Confirm it compiles for Arduino, then test it on an actual Nano Every and verify that the CRC remains correct while the 512-byte table is eliminated so the core fits within the available 12k of flash.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
embedded-iot, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.