Repository navigation
Add SAMD21 support (example configs, SERCOM console and NVMCTRL fixes) - #960
Merged
Merged
Conversation
dgarske
force-pushed
the
samd21
branch
3 times, most recently
from
October 29, 2026 04:39
6cc2361 to
5f280ce
Compare
dgarske
force-pushed
the
samd21
branch
2 times, most recently
from
October 29, 2026 05:19
8771890 to
7b02878
Compare
mattia-moffa
requested changes
Nov 19, 2026
dgarske
requested review from
mattia-moffa
and
a balanced review from Copilot
November 19, 2026 04:21
mattia-moffa
previously approved these changes
Nov 19, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The UART implementation adds a second parameter to uart_rx, conflicting with the public one-argument declaration and its caller, creating incompatible function types across translation units.
1 open issue
What changed in this PR
This PR makes the existing SAM D21 / SAM R21 HAL usable through example configurations, console support, and build integration. It also improves flash programming and protection handling. Hardware validation remains outstanding.
Changes:
- Add configurations and CI builds for 128KB and 256KB SAMD21 parts, with configurable linker RAM size.
- Add a SERCOM console and firmware confirmation in the test application.
- Fix NVMCTRL clocking, page commits, error reporting, and protection handling, with expanded host tests and documentation.
| File | Description |
|---|---|
tools/unit-tests/unit-samr21-flash-protect.c |
Test lock-region calculations, PAC handling, and errors. |
tools/unit-tests/unit-flash-write-samr21.c |
Add multi-page data-path and controller-error tests. |
tools/unit-tests/Makefile |
Register protection tests and extend HAL extraction rules. |
tools/config.mk |
Preserve WOLFBOOT_RAM_SIZE during configuration generation. |
test-app/app_samr21.c |
Add LED status and confirm updated firmware. |
Makefile |
Substitute RAM size into linker scripts. |
hal/uart/uart_drv_samr21.c |
Add a configurable SERCOM USART driver. |
hal/samr21.ld |
Replace fixed RAM length with a configuration value. |
hal/samr21.c |
Correct flash operations and add region protection. |
docs/Targets.md |
Document configurations, memory layouts, console, and validation status. |
config/examples/samd21.config |
Add a 128KB flash / 16KB SRAM configuration. |
config/examples/samd21_j18.config |
Add a 256KB flash / 32KB SRAM configuration. |
arch.mk |
Default SAMR21-target RAM size to 16KB. |
.gitignore |
Ignore generated protection-test files and executable. |
.github/workflows/test-configs.yml |
Build both SAMD21 configurations in CI. |
Review effort: Balanced
mattia-moffa
approved these changes
Nov 19, 2026
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.

Description
hal/samr21.cis a SAM D21 HAL, clocked for a SAMD21G18A at 48MHz, but nothing could reach it: no example config, no docs, no CI build.Adds
config/examples/samd21.configandsamd21_j18.configfor the 128KB/16KB and 256KB/32KB parts, a SERCOM console, adocs/Targets.mdsection, CI jobs, andwolfBoot_success()in the test app so an A/B update confirms instead of rolling back.WOLFBOOT_RAM_SIZEis now a linker substitution, as the script hardcoded 16KB and capped the 32KB parts.Both layouts use a 32KB bootloader region, because the NVMCTRL
BOOTPROTfuse protects 8KB, 16KB or 32KB and nothing in between: any other boundary either leaves the bootloader writable or pushes the protected region into the boot partition, where it would block the swap.HAL fixes:
hal_init()andhal_prepare_boot()clearedAPBBMASK.NVMCTRL, set out of reset, gating the flash controller's clock off before any write or erase.PAC_WP_NVMCTLwas the DSU bit; NVMCTRL is peripheral 34 vs PAC1's base 32, so bit 2.hal_flash_write()issued one page-write per transfer; now setsCTRLB.MANWand commits each page.NVMCTRL.STATUSerrors.Testing
Not validated on hardware; the console pinout is from the Xplained Pro schematic. Both configs build, and
unit-samr21-erase-advanceandunit-flash-write-samr21cover the erase stride, a multi-page write and the error returns.