Skip to content

avr/avrdx: Fixup contributions from KR to NuttX V13#19113

Open
acassis wants to merge 5 commits into
apache:masterfrom
acassis:avr_fixes_v13
Open

avr/avrdx: Fixup contributions from KR to NuttX V13#19113
acassis wants to merge 5 commits into
apache:masterfrom
acassis:avr_fixes_v13

Conversation

@acassis

@acassis acassis commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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:

  • new configuration option ARCH_HAVE_UDELAY which prevents default
    up_udelay from building if set
  • new configuration option ARCH_HAVE_DYNAMIC_UDELAY that declares that
    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.

Kerogit 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>
@acassis

acassis commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@jerpelea please include these PR from KR to V13

@github-actions github-actions Bot added Arch: avr Issues related to all AVR(8-bit or 32-bit) architectures Area: Drivers Drivers issues Size: L The size of the change in this PR is large Board: avr labels Jun 10, 2026

#ifndef CONFIG_ARCH_HAVE_UDELAY

void weak_function up_udelay(useconds_t microseconds)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove weak_function in all places

Comment thread sched/clock/clock_delay.c
"new value to apache/nuttx."
#endif

#ifndef CONFIG_ARCH_HAVE_DYNAMIC_UDELAY

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make BOARD_LOOPSPERMSEC depends on !ARCH_HAVE_DYNAMIC_UDELAY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: avr Issues related to all AVR(8-bit or 32-bit) architectures Area: Drivers Drivers issues Board: avr Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants