Implemented load of OSCCAL value (draft) #343
Open
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.
Based on discussion with @ondrej-stanek-ozobot , this is attempt at implementing osccal in the bootloader. Would solve issue #87 The idea is originally by @WestfW in #342 (comment), this is the implementation i came up with:
rjmp start_main
andOSCCAL
is not applied (MCU core loads factory default at startup and we don't touch it). This make sure the cpu can start up before the calibration is performed, and for example run a calibration program.0x05 0xc0
, where0x05
is the offset.ldi r24,0xFF
instruction is patched to replace0xFF
with the new osccal valuerjmp start_main
torjmp set_osccal
. This can be patched, as set osccal has relative address0x05
only needs to modify 1s to 0s to become set_osccal0x01
.OSCCAL
valueret
andrjmp
instructions are the same length, so it should work both withAPP_NOSPM
and without. But withNOSPM
, it's probably necessary to flash it using a programmer, as there is no access to this region from program.Caveats:
NOP
, as I needed to be able to rewrite the address from0x05
to0x01
. Makingsts
andldi
combo shorter would also help, the address just needs to be an even number. Or therjmp
instruction replaced for a different instruction? Not sure about that.We will test on our platform and report if it works as expected. For now, we can have a discussion if this approach on the bootloader side is OK-ish and what more needs to be done.
Feel free to discuss, modify and reject if necessary :-)
Edit: formating.