Fix three core/library bugs affecting all AVR - #650
Open
ws-asahi wants to merge 3 commits into
Open
Conversation
`!ADC0.CTRLA & 0x01` evaluates as `(!ADC0.CTRLA) & 0x01`, so the early return for a disabled ADC never fired as intended. Parenthesize the mask. The same expression appears twice (analogRead paths for the two ADC generations); the other checks in this file already had the parentheses right.
`(chan + 1) < 3` promotes chan to int, so the documented auto-select value chan = 255 evaluated as 256 < 3 and could never take this path. Compare explicitly instead.
…ost data pointer Three bugs in the unaligned/odd-length paths: - the unaligned leading byte was written without advancing the data pointer, so the rest of the buffer was written shifted by one - writeWords was called without afterwards advancing tAddress/data/ length, so the odd-byte epilogue used stale values - the trailing byte was written to tAddress + length - 2 with a recomputed data offset, landing on the wrong address and corrupting the neighbouring byte while dropping the intended one Rewrite the function to advance state explicitly at each stage. Also return early on a zero-length request (FLASHWRITE_0LENGTH).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three small, unrelated bug fixes.
None are part-specific - they affectcurrent master as-is.
1. wiring_analog.c
if (!ADC0.CTRLA & 0x01)evaluates as(!ADC0.CTRLA) & 0x01, so the "ADC disabled" early return never fired.Parenthesized (both occurrences).
2. wiring_extra.cpp
(chan + 1) < 3promotes to int,so the documented auto-select value
chan = 255became256 < 3and could never take this path.Compare explicitly.
3. Flash.cpp / writeBytes
on unaligned/odd-length requests the leading byte was written without advancing the data pointer (shifting the rest by one),
state wasn't advanced after writeWords, and the trailing byte landed on the wrong address.
Rewritten to advance state explicitly at each stage; also returns FLASHWRITE_0LENGTH on zero length.
Verified to compile for AVR128DA48.
(core changes via a standard sketch; Flash via FlashDemo and a minimal writeBytes sketch, with "Write to flash from app" enabled)
These were found while working on AVR-DU support (#637).
with these fixes applied, everything runs fine on an AVR64DU32 on CuriosityNano.