avr/avrdx: Fixup contributions from KR to NuttX V13#19113
Open
acassis wants to merge 5 commits into
Open
Conversation
added 5 commits
June 10, 2026 14:07
This patch amends commit f077c03 which is a part of series that changed (in commit 48db502) default value of BOARD_LATE_INITIALIZE to yes. With this change, the boards are required to provide board_late_initialize function. Commit f077c03 added this function to many AVR boards but not to this one, making the build with default configuration fail. This patch rectifies that and provides an empty function. With this patch applied, the build no longer fails. Signed-off-by: Kerogit <kr.git@kerogit.eu>
This patch amends commit dfd3426 which added support for running with some signals disabled to AVR architecture. AVR DA/DB architecture was not covered by the commit and failed to build with CONFIG_ENABLE_ALL_SIGNALS unset (which includes building with CONFIG_ENABLE_PARTIAL_SIGNALS, the default value.) Change is replicated from the commit and tested by a custom stress application which spawns some always-busy threads and uses preemptive multitasking to switch between them. Additionally, ability to sleep in the application was tested by a simple LED blinking application. Signed-off-by: Kerogit <kr.git@kerogit.eu>
While attempting to create architecture-specific implementation of up_udelay, it was discovered that the overriding function is not included in the final binary, the weak implementation was used instead. Further investigation and experimentation showed that the linker only overrides the weak implementation with the custom one if the custom one is present in a .c source file that contains at least one other function that is called from somewhere. Some additional testing revealed that at least one other already present up_udelay override (rv32m1-vega:nsh) is affected by this. In a short mailing list discussion it was determined that this is a likely result of using static libraries during the build process and it was suggested to introduce configuration option that will exclude weak implementations of the function from the build altogether. This patch does that. This patch does not enable this configuration option for any existing board/chip because doing so would change its behaviour and needs to be tested by users of the hardware. Also changed is the static assertion in sched/clock/clock_delay.c to not prevent building the code when architecture declares that it does not use BOARD_LOOPSPERMSEC to determine required loop count. Patch was tested by building breadxavr:nsh (identical binary by SHA256), rv32m1-vega:nsh (identical text section) and rv-virt:nsh (text section differs because of different ordering of functions in the binary, ostest passed though.) Signed-off-by: Kerogit <kr.git@kerogit.eu>
This patch adds support for reading CPU clock frequency when the MCU is driven by clock source other than high frequency oscillator. Signed-off-by: Kerogit <kr.git@kerogit.eu>
NuttX builtin up_udelay function uses BOARD_LOOPSPERMSEC configuration value to determine how many loops need to be done to cause requested delay. This does not match well with AVR DA/DB microcontrollers because the CPU clock frequency is configurable. A board configuration could therefore provide BOARD_LOOPSPERMSEC valid for one frequency but for other frequencies, the user would be required to calibrate the value and would still get incorrect result when changing the clock speed during runtime. This patch therefore implements dynamic architecture-specific up_udelay function which determines current clock settings and infers required loop count from that. New function was tested by simple application that used up_udelay to put delays between printf calls. Signed-off-by: Kerogit <kr.git@kerogit.eu>
Contributor
Author
|
@jerpelea please include these PR from KR to V13 |
|
|
||
| #ifndef CONFIG_ARCH_HAVE_UDELAY | ||
|
|
||
| void weak_function up_udelay(useconds_t microseconds) |
Contributor
There was a problem hiding this comment.
let's remove weak_function in all places
| "new value to apache/nuttx." | ||
| #endif | ||
|
|
||
| #ifndef CONFIG_ARCH_HAVE_DYNAMIC_UDELAY |
Contributor
There was a problem hiding this comment.
let's make BOARD_LOOPSPERMSEC depends on !ARCH_HAVE_DYNAMIC_UDELAY
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.
Summary
Adapt AVR DA/DB family architecture code and breadxavr board to recent
changes in NuttX (which prevent current code from building
out-of-the-box.)
Impact
(patch 1) Amends commit f077c03 which did not add
board_late_initialize function to breadxavr board after commit
48db502 changed BOARD_EARLY_INITIALIZE to default yes. This caused
build failure with default configuration (the patch adds the function.)
(patch 2) Amends commit dfd3426 which is needed to support
configuration with some or all signal-related functionality removed (the
commit skipped this chip family.)
To comply with commit 2d768c2:
(patch 3) Adds new configuration option that excludes default up_udelay
function from the build. That allows creation of custom implementation
(see the second commit description why weak attribute was found
insufficient. Related mailing list discussion is
https://lists.apache.org/thread/bd30lljl0kcknllrcv23gqzgg2wktq1q )
Skips static assertion of BOARD_LOOPSPERMSEC != -1 if the architecture
declares that it is not using the value.
(patches 4 and 5) Implement up_udelay function specific to AVR DA/DB
family - one which does not use BOARD_LOOPSPERMSEC (unless configured to
do so.)
Users: currently unable to build AVR DA/DB in default configuration,
will be able to do so with the patches. New implementation of up_udelay
activates automatically.
Users of other architectures are not affected.
Build:
up_udelay from building if set
custom implementation of up_udelay does not use BOARD_LOOPSPERMSEC.
Both unset by default except AVR DA/DB.
Documentation: updated, describes up_udelay behaviour for AVR DA/DB chip
family
Compatibility: no functional change except AVR DA/DB. New implementation
of up_udelay for this chip family may behave differently in corner cases
(very low clock speeds and/or long delays causing overflow during
calculations etc.)
Note that there are other custom implementations of up_udelay in the
source tree and from testing it seems they too are affected by problem
described in patch 3. No change was done for those (as the author of the
series does not have means to test them.)
Testing
The first patch was simply tested by building breadxavr:nsh. Does not
build without the patch, builds with it. Same for the second.
The third patch was tested by building the code with and without it for
breadxavr:nsh (identical binary by SHA256), rv32m1-vega:nsh (identical
text section) and rv-virt:nsh (text section partially differs because of
different ordering of functions in the binary, ostest passed though.)
Patches four and five were tested by running it on hardware in multiple
configurations and delay durations - application simply used printf to
output "tick/tock" on serial port; timestamps are added on the PC side.
Example output:
I, [2026-03-06T10:32:35.965235 #59953] INFO -- : tick
I, [2026-03-06T10:32:36.065227 #59953] INFO -- : tock
I, [2026-03-06T10:32:36.166234 #59953] INFO -- : tick
I, [2026-03-06T10:32:36.266215 #59953] INFO -- : tock
I, [2026-03-06T10:32:36.368224 #59953] INFO -- : tick
I, [2026-03-06T10:32:36.468156 #59953] INFO -- : tock
I, [2026-03-06T10:32:36.568209 #59953] INFO -- : tick
I, [2026-03-06T10:32:36.669204 #59953] INFO -- : tock
I, [2026-03-06T10:32:36.769213 #59953] INFO -- : tick
I, [2026-03-06T10:33:40.963365 #60055] INFO -- : tick
I, [2026-03-06T10:33:41.464356 #60055] INFO -- : tock
I, [2026-03-06T10:33:41.965337 #60055] INFO -- : tick
I, [2026-03-06T10:33:42.466337 #60055] INFO -- : tock
I, [2026-03-06T10:33:42.969307 #60055] INFO -- : tick
I, [2026-03-06T10:33:43.470287 #60055] INFO -- : tock
I, [2026-03-06T10:33:43.971281 #60055] INFO -- : tick
I, [2026-03-06T10:33:44.474258 #60055] INFO -- : tock
Documentation changes tested using make html.