Commit graph

24882 commits

Author SHA1 Message Date
Jorge Guzman
b7ce3cbf20 arch/sim: report the keyboard the way the contract says
The X11 keyboard reported any keysym that its translation table did not
know as an ordinary key press carrying the raw keysym.  An application
looking for a byte of text got 65307 for Escape and 65289 for Tab, and
the modifiers arrived as 65505 and friends.

That is not a character, so it cannot be a KEYBOARD_PRESS.  NXDoom on
the simulator has therefore had no menu, no map and no fire, which is
most of the game.

Escape and Tab are control characters and are reported as such.  The
eight modifiers get the keycodes that the codec now has for them.  And a
keysym above the Latin-1 range that no table knows is not reported at
all, which closes the case rather than the three instances of it.

Verified by dumping the events while typing:  Escape arrives as 27, Tab
as 9, the modifiers as keycodes 88 to 95, and the game plays.

Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>
2026-07-31 11:02:20 -03:00
dechao_gong
d960bc39ee arch/arm/rtl8721f: add GPIO character driver support
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
Wire the shared Ameba GPIO driver into the RTL8721F (amebagreen2) build and
add the EVB board glue:

  - arch/arm/src/rtl8721f: build ameba_gpio.c (CMake/Make.defs), source the
    common Ameba Kconfig, and add ameba_gpio_chip.h describing the chip's
    three GPIO ports (A/B/C), their IRQs and the APBPeriph clock bit.
  - arch/arm/src/common/ameba: teach the driver that amebagreen2's ROM
    GPIO_Init does not call PAD_PullCtrl or GPIO_INTMode, so call both
    explicitly after GPIO_Init; on RTL8721Dx (ram_common) these are harmless
    redundant writes.  Add the AMEBA_PORT_C / AMEBA_PC() helpers.
  - boards/arm/rtl8721f/rtl8721f_evb: register output/input/interrupt demo
    pins, add the bringup hook, and provide a minimal 'gpio' NSH defconfig.
  - Documentation: add a GPIO section for the RTL8721F EVB and fix a
    rising/falling typo in the PKE8721DAF page.

Hardware-verified on the RTL8721F EVB: output, input, and all interrupt
trigger/polarity combinations (rising/falling edge, level high/low).

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
2026-07-31 08:49:23 +02:00
dechao_gong
a6a5c8aff2 arch/arm/common/ameba: fix level-triggered GPIO interrupt storm
The shared port ISR clears interrupt status with GPIO_INTStatusClearEdge(),
which only clears edge latches.  For a level-triggered pin the status stays
asserted as long as the level is active, so the ISR re-enters forever once
the level fires -- the system hangs before the application can even service
the event.

Remember at configure time whether a pin is level-triggered, and in the ISR
mask such a pin (GPIO_INTConfig DISABLE) before invoking the callback.  The
application re-enables it via go_enable() after servicing.  Edge pins are
left unmasked, so their behaviour is unchanged.

This fixes a hang reproducible on RTL8721Dx and RTL8721F when a
level-high/level-low interrupt pin is used.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Assisted-by: Claude <noreply@anthropic.com>
2026-07-31 08:49:23 +02:00
Javier Alonso
ec83d9a3a7 Review: Address @raiden00pl comments
The fix was ported from the STM32G0 to all the STM32 platforms,
as the code is mostly the same hence presents the same failure

Signed-off-by: Javier Alonso <javieralonso@geotab.com>
2026-07-31 08:10:01 +02:00
Javier Alonso
cacf519a96 stm32: Detach GPIO IRQ callbacks upon clearing "setevent"
When the interrupts get disabled, the callback(s) are still attached.
That structure is never cleared, causing several calls to attach/detach
to eventually fail as the callback queue gets full.

When the error occurs, the registration fails with error 12 (ENOMEM).
By detaching the IRQ and clearing the callbacks, this error doesn't
happen again

Signed-off-by: Javier Alonso <javieralonso@geotab.com>
2026-07-31 08:10:01 +02:00
dechao_gong
3dbd62e256 arch/arm/rtl8721f: enable on-chip flash filesystem and WiFi networking
Bring up the last two RTL8721F feature blocks and wire them into the
nsh board configuration:

- littlefs on the on-chip flash MTD region (P2).
- WHC/INIC WiFi with the on-chip IPC control plane, NuttX net stack,
  DHCP client and the wapi command tool (P3).

Two porting fixes were required for the WiFi control plane:

- ameba_ipc.c: the AP IPC device base (IPCAP_DEV) was carried over
  verbatim from the RTL8720F template (0x40804000).  On this SoC IPC0
  lives at 0x40815000; using the wrong base makes ipc_table_init()
  program the RX-full mask in the wrong register block, so the NP->AP
  interrupt never fires and WiFi bring-up hangs waiting for the device
  to answer.  Point IPCAP_DEV at the correct 0x40815000 base.

- ameba_board.mk: the EVB silicon is B-cut, so link against the
  ameba_rom_symbol_bcut*.ld ROM symbol tables (the A-cut tables resolve
  the WiFi ROM helpers to the wrong addresses and fault at run time).

Validated on hardware: NSH comes up, wapi scan lists real APs, a WPA2
connect succeeds, the DHCP client obtains a lease and ICMP to the
public internet round-trips.

The board defconfig keeps SSID/passphrase as placeholders; real
credentials are supplied at run time via the wapi commands.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
2026-07-30 17:04:14 +08:00
dechao_gong
a85db6d28f arch/arm/rtl8721f: bring up minimal NSH (P1)
Wire the RTL8721F km4tz core up to a working NuttShell:

- irq.h: renumber the KM4TZ external vector table to the RTL8721F
  APIRQn map (UART_LOG=24, IPC=5, +GPIOB/C, TIMER7/8, ...).
- ameba_loguart.c: fix the LOG-UART base to 0x40810000.  The former
  0x401C6000 belongs to a different Ameba part; the wrong base bus-
  faulted on the RX interrupt-enable write while TX still worked
  (LOGUART_PutChar uses its own ROM-internal base).
- ameba_app_start.c: adjust the MPU read-only / RAM regions for the
  RTL8721F memory map and seed the RTC on first power-on so the
  SDM32K-clocked SYSTIMER comes up (mirrors the SDK app_rtc_init).
- ameba_ipc.c: move the km4tz<->km4ns IPC to APIRQn 5 (IPC_CPU0).
- ameba_board.mk: pull in fwlib ameba_rtc.c for the RTC_* symbols.
- defconfig: RTL8721F RAM map, enable TIMER/TIMER_ARCH/ARMV8M_SYSTICK
  for a live system tick, and drop the WiFi/NET stack for now.
- scripts/Make.defs: use the RTL8721F_NOR flash profile.

Boots cleanly to nsh> on hardware; tick, RX and builtin apps verified.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
2026-07-30 17:04:14 +08:00
dechao_gong
d584142cf4 arch/arm/rtl8721f: add RTL8721F (Green2) chip and EVB board skeleton
Add a P0 skeleton port for the Realtek RTL8721F (SDK codename Green2 /
amebagreen2).  Structurally the RTL8721F is a twin of the RTL8720F -- the
AP/host core is km4tz (ARMv8-M.main, TrustZone secure) and the WiFi MAC/PHY
runs on the km4ns network-processor core -- so this port is modelled on the
RTL8720F one and shares the IC-agnostic ameba glue in
arch/arm/src/common/ameba.

This is the "configures and links" skeleton (rtl8721f_evb:nsh builds an
image end to end).  Four differences from the RTL8720F template were needed
to make the empty shell link against amebagreen2:

  * km4tz has no FPU (cmsis_cpu.h defines __FPU_PRESENT 0), so the chip does
    not select ARCH_HAVE_FPU and the image is built soft-float.
  * ameba_app_start.c matches amebagreen2's ram_km4tz silicon init: the
    nocache MPU map, the non-secure ROM BSS clear, OSC4M (not OSC2M)
    calibration gated on EFUSE cut >= B and CHIP_TYPE_ASIC_POSTSIM.
  * amebagreen2 ships no lib_rom.a, so the ROM archive whole-archive link is
    dropped; the WiFi/OS/non-secure ROM symbols come from the SDK
    ameba_rom_symbol_acut{,_wifi,_os}.ld maps appended to the image2 linker
    script, exactly as green2's own image2 link does.
  * the AP WiFi security lib is lib_wifi_common.a (was lib_wifi_com_sec.a).

The per-chip IRQ vector table (irq.h) and the RAM_START/RAM_SIZE layout
still carry RTL8720F values and are refined in the follow-up bring-up work.

Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-30 17:04:14 +08:00
Pavel Pisa
ab4890df16 drivers/input: partial fix of indistinguishable ASCII and special keycodes
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
As analyzed, the NuttX initial keyboard API design uses event
type KBD_SPECPRESS/KBD_SPECREL to deliver special keys
and KBD_PRESS/KBD_RELEASE to deliver ASCII codes.

But it seems that this design choice has not been followed
in virtio-input, goldfish_events and sim_keyboard designs
and result is that external keyboard special keys events
are mapped to KEYCODE_xxx values which start from 0 and
overlaps with ASCII keys.

The issue is tracked under #19527 number.

This set of changes correct events reporting for mentioned
keyboards to report right event type for special keys.

The solution is only partial at this phase.

Virtual and more complex keyboards usually deliver
key pressures as scancodes (key position on keyboard)
and mapping to ASCII for keys which corresponds to letter
and other similar keys lacks mapping of national alphabets,
second row symbols and switch to capital letter according
to modifiers.

Signed-off-by: Pavel Pisa <pisa@fel.cvut.cz>
2026-07-29 22:51:15 -03:00
Ricard Rosson
a85b28bc2c rp2040/rp23xx: order the USB BUFF_STATUS clear before the AVAILABLE re-arm
rp2040_update_buffer_control()/rp23xx_update_buffer_control() re-arm an
endpoint buffer by setting the AVAILABLE bit in the buffer-control word,
which lives in DPSRAM.  When a buffer is re-armed from the completion
path (rp2040_usbintr_buffstat/rp23xx_usbintr_buffstat), that runs after
the handler has cleared the endpoint's bit in BUFF_STATUS, which lives in
the USB controller register block -- a different peripheral region.

The bus fabric may reorder those two stores.  If the controller observes
the AVAILABLE re-arm before the BUFF_STATUS clear lands, it can transmit
the next IN packet and latch its completion in BUFF_STATUS before the
clear arrives; the late clear then wipes that just-set completion bit.
The lost completion edge stops all further buffer interrupts for the
endpoint, so the class driver's write-complete callback never runs and
TX wedges permanently.

This is most visible on RP2350 (Cortex-M33) under dense/bursty IN traffic
such as CDC-NCM with TCP write buffers.  Add a UP_DMB() at the top of the
AVAILABLE re-arm so the preceding BUFF_STATUS clear is ordered ahead of
it.  (Non-SMP builds reduce spin_lock_irqsave to a barrier-free
up_irq_save, so nothing else orders these two stores.)

Assisted-by: Claude (Anthropic Claude Code)
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
2026-07-29 23:51:56 +08:00
Eren Terzioglu
9c96d876d1 arch/risc-v/espressif: Add SW LP Mailbox support
Add software lp mailbox support

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
2026-07-29 09:53:59 +08:00
Eren Terzioglu
ee0d00f494 arch/risc-v/espressif: Add build customization options for ULP build system
Add customization options for ULP build system

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
2026-07-29 09:53:59 +08:00
Alan Carvalho de Assis
c027e7c3e4 tools: fix stale archive members surviving a Kconfig-driven CSRCS change
During the Toybox port to NuttX, Claude noticed that changes in the
menuconfig weren't taking affect. This issue exists for a long time on
NuttX, in fact BayLibre's presentation from 2017 make jokes about our
building system not been reliable:
https://www.youtube.com/watch?v=XUJK2htXxKw&t=320s

Stale archive members from $(AR)'s additive-only behavior can linger
after Kconfig toggles change which files provide a symbol, causing dead
weight or "multiple definition" link errors on incremental builds.
Fixed by splitting ARCHIVE into two macros: ARCHIVE keeps the original
additive behavior for apps/libapps.a, which many independent
subdirectories contribute to across a build, while the new
ARCHIVE_REBUILD deletes then archives for the far more common case
of a single Makefile building its own self-contained $(OBJS)
- all 39 such call sites now use it.

Assisted-By: Claude Sonnet 5
Signed-off-by: Alan C. Assis <acassis@gmail.com>
2026-07-28 21:26:03 -03:00
Marco Casaroli
e499b9f174 arch/arm: carry CONTROL over to the fork child on Cortex-M
In a protected build arm_svcall.c treats the caller's CONTROL as part of
the saved system call state: it stores it in xcp.syscall[].ctrlreturn on
entry and restores it from there on SYS_syscall_return.  All three
Cortex-M profiles do this -- armv6-m, armv7-m and armv8-m each define the
field in arch/arm/include/<arch>/irq.h and use it symmetrically.

arm_fork_direct() copied sysreturn and excreturn to the child but not
ctrlreturn.  The child's TCB comes from kmm_zalloc(), so the field was
zero, and CONTROL == 0 is nPRIV clear: the child returned to user space
privileged while its parent returned unprivileged.  The child ran out its
life with the MPU restrictions its parent is under silently lifted, which
is the isolation BUILD_PROTECTED exists to provide.

Nothing faults, and that is why this survived.  CONTROL == 0 also selects
MSP, which sounds like it should crash immediately, but NuttX already
runs Cortex-M threads on MSP -- the parent's saved value is 0x1, nPRIV
set and SPSEL clear -- so the two differ only in the privilege bit and
there is no stack change to trip over.  Privileged code then passes every
test unprivileged code passes, so ostest cannot see it either.

Measured on an RP2350 (Cortex-M33) in BUILD_PROTECTED, breaking at the
nxtask_start_fork() call in arm_fork_direct() during task_fork_test:
parent ctrlreturn 0x00000001, child ctrlreturn 0x00000000.  With this
change both read 0x00000001.

BUILD_FLAT is unaffected: without CONFIG_LIB_SYSCALL, nsyscalls is 0 and
the whole block is skipped.  armv7-a and armv7-r are unaffected too; they
carry cpsr instead, and that is already copied.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-28 20:30:51 +08:00
Ricard Rosson
cfeca506f8 rp2040/rp23xx: implement stall queueing and GET STATUS responses
Two device-controller defects that break standard host error recovery,
found while root-causing why macOS never mounts a NuttX mass-storage
function (full analysis and host traces in apache/nuttx#19435):

1. epsubmit() aborted (-EBUSY) any IN request submitted while the
   endpoint was halted.  The mass storage class halts bulk-IN for a
   failed device-to-host command (BOT-legal) and then submits the CSW;
   the CSW was dropped on the floor, so after the host's Clear-Halt the
   endpoint NAKed forever and the host timed out (macOS: 30 s, then a
   Bulk-Only-reset/device-reset spiral until it disables the port).
   This is exactly the race documented for years in the usbmsc_scsi.c
   header (David Hewson's analysis); the USBMSC_STALL_RACEWAR sleep
   workaround only survives hosts that clear the halt within 100 ms --
   Linux does, macOS does not, which is why Linux testing never saw it.

   Implement the stall-queueing contract instead: requests submitted
   while an endpoint is halted are queued without arming the hardware
   (arming rewrites the buffer control word and would silently clear
   the STALL bit); a halt terminates any in-flight IN transfer (its
   hardware buffer is disarmed by the STALL write and would never
   complete); clearing the halt resets the data toggle and re-arms the
   head of the queue; stale buffer completions latched for transfers
   aborted by a halt are ignored.  RP2040/RP23XX now select
   ARCH_USBDEV_STALLQUEUE, which also retires the RACEWAR's two 100 ms
   sleeps per failed command.

2. The USB_REQ_GETSTATUS handler in ep0setup() validated the request
   but never queued the two-byte response, for all three recipients
   (device/interface/endpoint), so EP0 NAKed the host's data stage
   forever and every GET STATUS timed out.  macOS issues GetPipeStatus
   = GET STATUS(endpoint) on a halted pipe before running Bulk-Only
   reset recovery and hit this on every probe; lsusb -v's device-status
   query hangs on it as well.  Send the response: endpoint recipient
   reports the halt bit, device recipient reports self-powered,
   interface reports zeros; the status stage is armed by handle_zlp()
   exactly as for class-dispatched IN transfers.

Validated on RP2350 silicon (Raspberry Pi Pico 2 W, composite
CDC-ACM + CDC-NCM + USBMSC): pre-fix, a raw-usbfs replay of macOS's
sequence and timing reproduced both defects deterministically (CSW read
ETIMEDOUT after a delayed clear-halt; all GET STATUS variants
ETIMEDOUT).  Post-fix: the CSW survives the halt and is delivered after
Clear-Halt with correct tag/status/residue across a post-stall delay
sweep of 0-1000 ms; all GET STATUS variants answer immediately with
correct halt reporting; no regressions in the exact-length SCSI suite,
Bulk-Only reset, FAT mount and full reads, CDC-NCM/ACM, or warm
reboots; and macOS now mounts the volume (together with the companion
usbmsc fixes).  The rp2040 driver shares the code and receives the
identical fix (build-tested).

Assisted-by: Claude (Anthropic Claude Code)
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
2026-07-28 12:40:25 +02:00
Marco Casaroli
d5e6cd3aa5 arch/x86: default CROSSDEV on a macOS host
arch/x86 set CROSSDEV only under Cygwin, so everywhere else the build used
the bare tool names and got the host compiler.  On Linux that is a native
gcc which can produce i486 ELF objects, which is what the board README
assumes.  On macOS it is Apple clang, and on Apple Silicon that cannot
target i386 in any form -- so there is no configuration in which the default
works and a cross toolchain is not optional.

Default it to i686-elf-, which Homebrew packages and which accepts the
-march=i486 -mtune=i486 already in ARCHCPUFLAGS.  arch/x86_64 has had
exactly this stanza for its own toolchain all along; this is the same shape.

The Cygwin assignment becomes ?= to match, so that a CROSSDEV passed in from
the environment or the command line is honoured rather than overridden.

Note for anyone tempted by the toolchain they already have: a 64-bit x86
compiler with -m32 is not a substitute unless it was built with multilib.
Homebrew's x86_64-elf-gcc compiles 32-bit objects perfectly happily and has
no 32-bit libgcc to link them against, so the entire build succeeds and only
the final link fails, on __udivdi3, __divdi3, __moddi3 and __udivmoddi4.
`x86_64-elf-gcc -print-multi-lib' prints just `.;', which is the toolchain
saying so up front.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 12:38:02 +02:00
hanzhijian
634d8a1272 arch/sim: register RTC after clock initialization
Registering /dev/rtc0 from up_rtc_initialize() creates the pseudofs inode before clock_inittime() synchronizes CLOCK_REALTIME. Its timestamp is consequently zero and omitted by ls -l.

Keep lower-half setup in early RTC initialization, but defer character-device registration to up_initialize(), which runs after clock initialization.

Fixes #19504

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
2026-07-28 09:49:58 +02:00
hanzhijian
93b2798e30 arch/sim: Track sim_head dependencies
sim_head.c is linked separately from libarch, so it was omitted from the
source and dependency lists. Track its source independently so
configuration and header changes rebuild sim_head.o while preserving its
link behavior.

Assisted-by: Codex:gpt-5.6 Sol
Signed-off-by: hanzhijian <hanzhijian@zepp.com>
2026-07-28 10:17:04 +08:00
Marco Casaroli
7fd17c9d7c arch/x86_64: do not wrap the HPET oneshot on a deadline that has passed.
Some checks failed
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
Docker-Linux / push (push) Has been cancelled
intel64_timer_start_absolute() computed "expected - current_us" unsigned.  A
watchdog started with a delay of zero asks for a deadline that is already
current, the subtraction wraps to nearly 2^64, and the comparator is set so
far ahead that the timer never fires.  The CONFIG_INTEL64_HPET_MIN_DELAY
clamp in intel64_oneshot_start() cannot help: the wrapped value is enormous,
not small.

Ask for the shortest delay the hardware can take instead of wrapping, and let
that existing minimum-delay logic pick it.

It presents as ostest hanging in wdog_test with no output and no fault.
apps/testing/ostest/wdog.c:281 calls wdtest_once(&test_wdog, param, 0), and
NSEC2TICK() takes the next few delays (1ns, 10ns, ...) to zero ticks as well;
wdtest_once() then spins forever in its "wait until the callback is triggered
exactly once" loop.

Impact: runtime, ARCH_INTEL64_HPET_ALARM only.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 18:24:47 -03:00
Marco Casaroli
97dcbc010b arch/x86_64: inherit the kernel low memory mapping in an address environment.
copy_kernel_mappings() copies exactly one PDPT entry, the 1GB linear window
that maps physical 0-1GB at 4GB-5GB.  The boot identity mapping of the low
4GB, which lives in PDPT entries 0-3 of g_pdpt_low (intel64_head.S:756, one
page directory per 1GB) and is where every MMIO register is reached, is not
carried over.

A kernel thread never gets an address environment of its own and
addrenv_switch() leaves the last one in place for it, so as soon as any
process exists, kernel code touching MMIO faults.  The HPET at 0xfed00000
finds it immediately -- CR2=fed000f0, in intel64_hpet_getreg() under
clock_systime_ticks() on the lpwork thread -- and any MMIO driver would.

Inherit the four boot PDPT entries.  They point at the boot page directories
rather than at copies, so anything intel64_map_region() adds later is
inherited too, and they carry no X86_PAGE_USER, so user code still cannot
reach them.

Impact: runtime, CONFIG_ARCH_ADDRENV builds only.  User-space access is
unchanged; the entries added are supervisor-only.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 18:24:47 -03:00
Marco Casaroli
a8ed107fa0 arch/x86_64: give the page allocator the physical page pool base.
mm_pginitialize() documents heap_start as "the physical address of the start
of memory region", and every x86_64 consumer of mm_pgalloc() agrees:
create_spgtables(), x86_64_get_pgtable() and up_addrenv_create() all put the
result through x86_64_pgvaddr() before touching it.  x86_64_pgvaddr() in turn
range-checks against CONFIG_ARCH_PGPOOL_PBASE (arch/x86_64/src/common/
pgalloc.h:67).  arm64's equivalent passes CONFIG_ARCH_PGPOOL_PBASE.

up_allocate_pgheap() passed CONFIG_ARCH_PGPOOL_VBASE instead, and in the
other branch X86_64_PGPOOL_BASE + X86_64_LOAD_OFFSET, which is the same
mistake spelled out.  Every page handed out was therefore a virtual address
that fell outside the pool's physical window, x86_64_pgvaddr() returned 0,
and the first x86_64_pgwipe() memset NULL.

It presents as a page fault in memset() under create_spgtables() the first
time a process address environment is created, which is loading the init
program.  qemu-intel64:knsh_romfs sets PGPOOL_PBASE=0x00c000000 and
PGPOOL_VBASE=0x10c000000, so the value passed was off by the 4GB load
offset.

Impact: runtime, CONFIG_ARCH_ADDRENV builds only (CONFIG_MM_PGALLOC).

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 18:24:47 -03:00
Marco Casaroli
59b47cf3f4 arch/x86_64: define the missing CONFIG_ARCH_HAVE_SYSCALL.
794c325947 ("arch/x64:Syscall support is enabled by default", 2025-05-27)
changed nine guards from CONFIG_LIB_SYSCALL to CONFIG_ARCH_HAVE_SYSCALL but
never added the Kconfig symbol.  Only ARCH_HAVE_SYSCALL_HOOKS exists in tree;
ARCH_HAVE_SYSCALL itself is defined nowhere, so it is always unset and since
that commit x86_64 has had no x86_64_syscall_entry(), no x86_64_syscall(), no
IA32_LSTAR/IA32_STAR programming and no syscall stub layer in any
configuration:

  arch/x86_64/src/common/Make.defs:37     x86_64_syscall.c not compiled
  arch/x86_64/src/common/CMakeLists.txt:41           likewise
  arch/x86_64/include/irq.h:86
  arch/x86_64/src/intel64/intel64_cpu.c:247, :386
  arch/x86_64/src/intel64/intel64_head.S:83, :351, :538
  arch/x86_64/src/intel64/intel64_saveusercontext.S:108

qemu-intel64:knsh_romfs and qemu-intel64:knsh_romfs_pci are the two
CONFIG_BUILD_KERNEL configurations in tree, and neither can have worked in
that time.  They still link -- nothing references the missing pieces, so
libstubs.a is simply never pulled in -- and then die the first time user code
executes SYSCALL.

Define the symbol with the condition the code had before that commit, which
is LIB_SYSCALL:  every protected and every kernel build needs the interface,
and a flat build is left exactly as it is today.

Impact: restores the system call interface for CONFIG_BUILD_KERNEL and
CONFIG_BUILD_PROTECTED on x86_64.  CONFIG_BUILD_FLAT is unaffected --
qemu-intel64:nsh still builds with ARCH_HAVE_SYSCALL unset.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 18:24:47 -03:00
Marco Casaroli
caa700c138 arch/x86_64: do not demand a TSC frequency for a clock that has none.
g_x86_64_timer_freq is assigned only under ARCH_INTEL64_TSC_DEADLINE or
ARCH_INTEL64_TSC, and is read only by the two intel64_tsc_*.c files those
options build.  With the HPET as the system clock it stays 0, which is
correct and harmless -- but x86_64_timer_calibrate_freq() panics on 0
unconditionally, so the board dies during x86_64_lowsetup().

Require a frequency only where something needs one, which is
ARCH_INTEL64_HAVE_TSC.

The failure mode is worth recording, because it gives nothing to work from:
the PANIC() happens before x86_64_earlyserialinit(), and the panic handler
itself then triple-faults, because _assert() reads up_interrupt_context() --
a %gs-relative load -- and the GS base is not programmed until
x86_64_cpu_priv_set().  The console stays completely empty and the machine
resets.

Impact: runtime, ARCH_INTEL64_HPET_ALARM only.  Configurations with a TSC
are unchanged -- the PANIC() is still compiled for them.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 18:24:47 -03:00
Marco Casaroli
b11c31ba8a arch/x86_64: make ARCH_INTEL64_HPET_ALARM buildable.
ARCH_INTEL64_HPET_ALARM is one of the three members of the "System Timer
Source" choice, but selecting it does not build.  Taking qemu-intel64:nsh on
master and moving the choice off ARCH_INTEL64_TSC_DEADLINE onto it:

  intel64/intel64_hpet_alarm.c:41:24: error:
      'CONFIG_ARCH_INTEL64_HPET_ALARM_CHAN' undeclared

ARCH_INTEL64_HPET_ALARM_CHAN lives inside "if INTEL64_HPET" and nothing
selects INTEL64_HPET.  Enabling that by hand moves the failure to link time,
because intel64_oneshot_lower.c is built only when INTEL64_ONESHOT is set:

  undefined reference to `oneshot_initialize'

Enabling INTEL64_ONESHOT as well finally reaches the real problem.
intel64_oneshot_lower.c implements the counter flavour of struct
oneshot_operations_s, which exists only with ONESHOT_COUNT:

  intel64_oneshot_lower.c: error: 'const struct oneshot_operations_s' has no
      member named 'start_absolute'
  intel64_oneshot_lower.c: error: implicit declaration of function
      'oneshot_count_init'
  intel64_oneshot_lower.c: error: initialization of
      'int (*)(struct oneshot_lowerhalf_s *, const struct timespec *)' from
      incompatible pointer type ... (four more of these)

ONESHOT, ONESHOT_COUNT and ONESHOT_FAST_DIVISION were selected by
ARCH_INTEL64_TSC_DEADLINE and by nothing else, so the other members of the
same choice could never be built.

Select the four from ARCH_INTEL64_HPET_ALARM as well.  INTEL64_ONESHOT
selects INTEL64_HPET in turn, which is what brings
ARCH_INTEL64_HPET_ALARM_CHAN into existence, so one added select closes all
three stages.

Impact: build only, and only for a configuration that could not be built
before.  No existing defconfig selects ARCH_INTEL64_HPET_ALARM.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 18:24:47 -03:00
Matteo Golin
35354473c6 arm64/bcm2711/pwm: Fix PWM defconfigs
Fix build error where PWM0 pinout selection checks would still be
compiled even when PWM0 was not enabled.

Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
2026-07-28 02:46:42 +08:00
Ricard Rosson
2330e39546 arch/arm/rp23xx: harden the TRNG against health-test failures
The TRNG driver waited for EHR_VALID and copied the block out without
checking the CryptoCell health-test result, so a sample that failed the
on-chip von-Neumann, CRNGT or autocorrelation test was served as entropy.

Check RNG_ISR before consuming a block: on a health-test error, discard
the block and re-arm the source; only a block that passed is returned.
Add a small startup self-test that draws a few conditioned blocks and, if
the source is stuck (identical blocks), latches /dev/random and /dev/urandom
to fail with -EIO rather than emit predictable output that would silently
weaken every derived key.

Builds on the driver added in 52e84e0c0a.

Signed-off-by: Ricard Rosson <ricard@groundbits.com>
Assisted-by: Claude (Anthropic Claude Code)
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
2026-07-28 02:46:02 +08:00
dechao_gong
d76c2a3efe arch/arm/rtl8721dx: move Ameba UART per-chip wiring into a chip header
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
Extract the chip-specific UART constants (controller count, register
bases, NVIC vectors, APBPeriph function/clock masks and crossbar TX/RX
pad-mux codes) out of the shared driver into a new per-chip header,
arch/arm/src/rtl8721dx/ameba_uart_chip.h, and include it from
arch/arm/src/common/ameba/ameba_uart.c.  This drops the
#if CONFIG_ARCH_CHIP_RTL8721DX block from the shared source: other Ameba
ARM chips port UART by supplying a same-named header on their chip
include path.

The RCC clock argument is split from a single "clk" into separate
"periph" and "clk" APBPeriph masks so RCC_PeriphClockCmd() gets its two
distinct arguments; the two lists are equal on RTL8721Dx but differ on
chips such as amebasmart.

No functional change: the macros expand to the same values previously
hard-coded in the driver.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
2026-07-27 09:31:37 -03:00
dechao_gong
f8d6160022 arch/arm/rtl8721dx: add shared Ameba UART driver.
Add a shared Ameba high-speed UART driver on top of the GPIO driver's
common/ameba/ infrastructure, exposing UART0/UART1 through the NuttX
serial upper half.

- arch/arm/src/common/ameba/ameba_uart.c/.h: serial lower-half driver
  built on the SDK fwlib UART register layer (ROM symbol table).  RX/TX
  dispatch through NuttX-native interrupts; TERMIOS get/set supported.
  The pins are muxed to the direction-specific UART crossbar function
  codes (TXD/RXD per controller) required by the amebadplus pinmux, and
  RX is pulled high through the SDK ROM.
- arch/arm/src/common/ameba/Kconfig: AMEBA_UART option (selects SERIAL
  and ARCH_HAVE_SERIAL_TERMIOS) plus RX/TX buffer-size knobs.
- arch/arm/src/rtl8721dx: wire ameba_uart.c into the Make/CMake builds
  and pull the fwlib ram_common UART table into the fwlib link set.
- boards/arm/rtl8721dx/pke8721daf: board UART port table registering
  UART0 at /dev/ttyS1 (PB18/PB19, 115200), bring-up hook, and a uart
  NSH config with the serialrx/serialblaster examples.
- Documentation: describe the driver and the uart board config.

Verified on hardware (PKE8721DAF): pinmux routing, TX/RX and interrupt
paths, and the TERMIOS ioctl path via loopback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
2026-07-27 09:31:37 -03:00
liang.huang
57c7e47a6b arch/risc-v: fix up_backtrace() bugs and rework stack splicing
Bugs fixed:
1. BUILD_FLAT/BUILD_PROTECTED: the interrupt-context self backtrace
   printed the same frames twice.
2. BUILD_KERNEL: a cross-tcb backtrace never included the target
   task's kernel stack, so frames on it were missing.

Also reworked the implementation around a list of independent
starting points, each carrying every stack range its fp chain may
cross into, splicing them into one backtrace.

Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: liang.huang <liang.huang@houmo.ai>
2026-07-27 09:30:10 -03:00
liang.huang
ed368470d1 arch/risc-v: dump backtrace when killing a task with SIGSEGV
When riscv_fault_handler() kills a user task with SIGSEGV, it previously
produced no stack trace, making the crash hard to diagnose.  Call
sched_dumpstack() on the killed task when SCHED_BACKTRACE is enabled.

Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: liang.huang <liang.huang@houmo.ai>
2026-07-27 09:30:10 -03:00
liang.huang
7c75dbae2b arch/risc-v: preserve ra in up_idle() for fp-chain backtrace
up_idle() is a leaf function; with frame pointers enabled the compiler
skips spilling ra, corrupting the fp chain.  Clobber "ra" in the WFI
inline asm so backtrace can walk past the idle frame correctly.

Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: liang.huang <liang.huang@houmo.ai>
2026-07-27 09:30:10 -03:00
Marco Casaroli
4cb00df87a arch/arm/rp23xx: Add gSPI driver for the Infineon CYW43439.
Provide the transport half of the bcmf FullMAC driver on RP2350, so that
boards carrying an Infineon CYW43439 (or the Raspberry Pi RM2 module that
houses one) can bring up a wlan0 interface.  The chip's half-duplex gSPI bus
is driven by a six-instruction PIO program with DMA in both directions, and
the driver fills in the gspi_dev_t operations that bcmf_gspi_initialize()
expects.

This is a port of the equivalent rp2040 driver.  Three differences in the
RP2350 hardware and its NuttX support had to be accounted for:

  - The GPIO_STATUS register no longer has an OEFROMPERI field, so the wait
    for the PIO program to release the shared data line watches OETOPAD
    instead.  No override is configured on that pad, so the two fields carry
    the same value.

  - rp23xx GPIO interrupt modes are enumerated as indices rather than as the
    bitmask rp2040 uses, so passing the rp2040 constant would have selected
    the wrong trigger.

  - RP23XX_PIO_NUM is three, and the DREQ definitions live in
    hardware/rp23xx_dreq.h.

The data and clock lines are also explicitly pulled down rather than left on
the reset default.  The data line doubles as the chip's active-high interrupt
request and is serviced with a level-high interrupt, so it must read low
whenever the CYW43439 has released it.

Finally, the state machine returned by rp23xx_pio_claim_unused_sm() is
collected in a signed temporary before being stored, so that the "no state
machine available" test is not defeated by an unsigned comparison.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 09:29:06 -03:00
Marco Casaroli
7fc26fd50c rp23xx: Add an OTP driver on the efuse interface.
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
The rp2350 holds 4096 rows of 24 bit one-time-programmable memory, which
the port did not expose at all.  This adds a driver on the NuttX efuse
interface, registered by the common board bringup as /dev/efuse.

The driver uses the ECC interpretation of a row, in which 16 bits carry
data and the remaining 8 carry a Hamming code, so the OTP appears as a
flat space of 4096 * 16 bits for the efuse field descriptors to index: a
descriptor at bit offset N refers to bit N % 16 of row N / 16.  That
matches the row numbers already listed in hardware/rp23xx_otp_data.h.

Reads come from the chip's ECC-translated window and have no side
effects.  Rows are locked in pages of 64; a page locked against reads
would raise a bus fault, so the lock is checked first and reported as an
error instead.

Programming needs the separate RP23XX_OTP_WRITE option, which defaults to
off; without it a write returns EPERM and no programming code is built at
all.  When enabled, a row is programmed as a whole through the bootrom,
since the ECC bits cover the whole row.  For the same reason a row that
already holds data cannot be modified, and such a write is rejected
rather than left to corrupt the row's ECC.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-27 10:33:13 +08:00
raiden00pl
57d384f466 arch/arm/nrf52,nrf53: don't pass HCI messages under the lock
on_hci() ran the host upcall with g_sdc_dev.lock held. On nrf53 this
deadlocks the BLE link: the upcall waits for the app core,
which cannot answer while bt_hci_send() blocks on the same lock.

nrf52 modified for consistency, deadlock is not possible there.

Signed-off-by: raiden00pl <raiden00@railab.me>
Assisted-by: Claude Code
2026-07-27 10:16:22 +08:00
simbit18
c92db4440e arch/tricore: nxstyle fix Relative files path
- fix Relative file path does not match actual file.

Signed-off-by: simbit18 <simbit18@gmail.com>
2026-07-27 09:44:30 +08:00
simbit18
a3c0272674 arch/arm64: nxstyle fix Relative files path
- fix Relative file path does not match actual file.

Signed-off-by: simbit18 <simbit18@gmail.com>
2026-07-27 09:44:30 +08:00
Marco Casaroli
11d1965cc0 arch/rp23xx: Fix six register/bit macro name clashes.
The rp23xx hardware headers define a register address macro for every
register, then a block of register bit definitions.  In three headers a bit
definition reuses the name of a register address macro, so the register
address is silently redefined as a bit mask:

  RP23XX_POWMAN_BADPASSWD           address 0x40100000 -> (1 << 0)
  RP23XX_POWMAN_BOD_CTRL            address 0x40100018 -> (1 << 12)
  RP23XX_POWMAN_DBG_PWRCFG          address 0x401000a4 -> (1 << 0)
  RP23XX_BUSCTRL_BUS_PRIORITY_ACK   address 0x40068004 -> (1 << 0)
  RP23XX_BUSCTRL_PERFCTR_EN         address 0x40068008 -> (1 << 0)
  RP23XX_PADS_QSPI_VOLTAGE_SELECT   address 0x40040000 -> (1 << 0)

None of these headers has an in-tree user yet, which is why this has gone
unnoticed; each clash appears as a "macro redefined" warning as soon as a
driver includes the header.  Code that included one of them and used the
register by name would have dereferenced 1 or 0x1000 instead of the register.

Two of the POWMAN clashes were plain duplicates.  Per the RP2350 datasheet
BOD_CTRL bit 12 is ISOLATE and DBG_PWRCFG bit 0 is IGNORE, and the correctly
named RP23XX_POWMAN_BOD_CTRL_ISOLATE and RP23XX_POWMAN_DBG_PWRCFG_IGNORE were
already defined with the same values on the following lines, so the bare names
are simply removed.  The blank line separating the VREG_LP_EXIT and BOD_CTRL
groups is restored at the same time; its absence is what let the duplicate
hide inside the preceding group.

The other four are single field registers whose field carries no separate name
(the datasheet and the SDK describe each as a one bit register), so their bit
definitions are renamed to <REGISTER>_MASK, following the _MASK spelling these
headers already use for a field extent, and written in hex like their peers.

The rp23xx-rv copies of the three headers are identical to the arm ones and
carry the same clashes, so they get the same change and stay in sync.

No functional change: none of the six names has any user in the tree.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-26 21:13:07 -03:00
Andrey Sobol
9bf825fd4f stm32h7/dac: add DMA stream mode with ioctl-driven double-buffering
Add DMA support for DAC output with configurable double-buffering
via ioctl interface:

- ANIOC_DAC_DMABUFF_INIT: Copy full buffer into DMA buffer (memcpy)
- ANIOC_DAC_DMA_START: Start DMA with optional half-transfer interrupts
- ANIOC_DAC_DMA_STOP: Stop DMA and timer
- ANIOC_DAC_DMA_GET_EVENT: Wait for half-transfer complete event
- ANIOC_DAC_DMA_WRITE_HBUF: Write half-buffer into DMA buffer
- ANIOC_DAC_INFO: Query DAC capabilities (resolution, DMA, buffer size)

Stream mode: when halfint=1, both HTIF and TCIF generate events
via a ring buffer and semaphore. User writes the completed half
while DMA fills the other half. TCIF indicates h=1, HTIF h=0.

DMA priority is configurable per-channel via Kconfig choice
(Low/Medium/High/VeryHigh), defaulting to Medium.

Signed-off-by: Andrey Sobol <andrey.sobol.nn@gmail.com>
2026-07-26 14:26:47 -03:00
Andrey Sobol
85041e1699 stm32h7: added stm32-dac driver
+ added dac driver
* modified Kconfig for DAC, DAC_DMA, TMX_DAC
* checked DMA+DAC/DAC only
* checked DCASH/wo DCASH
* checked TIM 1,2,4,5,6,7,8,15

Signed-off-by: Andrey Sobol <andrey.sobol.nn@gmail.com>
2026-07-26 14:26:47 -03:00
Marco Casaroli
3b1aea4bb0 sim/alsa: Use bundled codec headers.
Expose the bundled LAME and libmad headers to the sim:alsa arch target and include LAME through its installed public header name. This lets the CMake build compile sim_offload.c without relying on host codec development packages.

Assisted-by: Zed:GPT-5.6 Terra
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-26 22:35:30 +08:00
Jorge Guzman
5ecdf31364 risc-v/gd32vw55x: fix ADC reopen and add gd32vw553k-start adc example
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
adc_shutdown() gates the ADC clock (RCU_APB2EN.ADCEN) when the device is
closed, but the one-shot adc_reset() that first enabled it only runs at
registration and adc_setup() never re-enabled it. A second open() then drove
a clock-gated peripheral whose conversions never completed, so a second run of
a reader such as the adc example hung after opening the device. adc_setup()
now re-enables the ADC clock; clock gating preserves the register
configuration, so nothing else has to be re-programmed.

Add an "adc" configuration that exercises the driver. It is the nsh base plus
the ADC driver, registered as /dev/adc0 and read by the adc example. ADC
channel 8 (ADC_IN8) is routed to PB0 on the J1 header so an analog voltage
applied there is sampled. The board bringup samples that channel when the pin
is routed, and PB0 is only claimed for the ADC when SPI is off (with SPI on it
belongs to the I2C0 fallback), so the periph configuration is unaffected.

The GD32VW55x ADC converts on demand rather than continuously, so the example
uses the software trigger (CONFIG_EXAMPLES_ADC_SWTRIG) and is bounded to 20
sample groups so it returns to the prompt.

Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>
2026-07-26 13:24:12 +02:00
Jorge Guzman
30735584a4 risc-v/gd32vw55x: fix I2C master and add gd32vw553k-start sht3x example
The GD32VW55x I2C master (the STM32-style "v2" IP) never completed a real
transfer. Two bugs:

1. Wrong kernel clock. The protocol state machine is clocked by the I2C
   kernel clock selected in RCU_CFG1.I2C0SEL, not by the APB1 bus clock that
   only feeds the register interface. The driver left it at the APB1 default
   and computed TIMING for PCLK1 (~80 MHz); the resulting prescaled period is
   so short that the SDADEL/SCLDEL setup and hold times fall below the
   analog-filter minimum of the IP, so the master latches START but never
   drives SCL (STAT stuck with BUSY set). Route I2C0 to IRC16M (16 MHz) and
   use it as clk_freq, and never let the prescaler drop below the value that
   keeps the prescaled clock at/under 4 MHz (250 ns) so SDADEL/SCLDEL stay in
   spec. This matches the vendor BSP (IRC16M, PSC=3).

2. Transfer timeout was zero. CONFIG_GD32VW55X_I2C_TIMEOTICKS has a Kconfig
   default of 0 ("override when non-zero"), but the driver derived the timeout
   with a plain #ifndef, which never triggers because the symbol is always
   defined. The polled wait loop therefore ran a single iteration and gave
   up. Address probes (NACK on the first pass) still worked and masked it;
   only multi-byte transfers exercised the loop. Honour the "0 means derive
   from seconds/milliseconds" contract.

Also make the interrupt wait immune to the ISR completing between startmsg()
and the wait (do not clobber a posted DONE), and drop a redundant cast.

To exercise this on hardware, add an "sht3x" configuration to the
gd32vw553k-start: the nsh base plus I2C0, the i2ctool and the Sensirion SHT3x
temperature/humidity driver, registered as /dev/i2c0 and /dev/temp0. I2C0 is
routed to PA2 (SCL) / PA3 (SDA) on AF4, the pins broken out on the J1 header
(datasheet Table 2-5); when SPI is enabled it claims PA2, so I2C0 falls back
to PB0/PB1, whose SDA pin is not broken out (the periph case).

Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>
2026-07-26 13:24:12 +02:00
Marco Casaroli
f0e4f61add arch/arm/rp23xx: Add RTC using the POWMAN always-on timer.
The RP2350 has no dedicated RTC block (the RP2040 one was removed).  Use the
POWMAN always-on timer instead: a 64-bit millisecond counter clocked from the
low-power oscillator, so it keeps running across warm resets.

Enabling CONFIG_RP23XX_RTC selects CONFIG_RTC and builds the driver, which
implements the simple up_rtc_initialize()/up_rtc_time()/up_rtc_settime()
interface backing the system clock (seconds resolution).  up_rtc_initialize()
sources the timer from the low-power oscillator at a 1 kHz tick and starts it,
preserving the value when the timer is already running.  POWMAN register writes
carry the required 0x5afe password.

Document the RTC on the rp23xx platform page: an "RTC" section explaining how
the POWMAN always-on timer is used (LPOSC clocking, the 0x5afe password and the
four 16-bit time registers, stopping the counter to reload it), with reference
links to the RP2350 datasheet Power chapter and the pico-sdk hardware_powman /
pico_aon_timer implementation the driver mirrors.  The same references are
noted in the driver header.

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-26 19:21:34 +08:00
simbit18
216edd74db arch/arm: Fix Kconfig style
- Remove spaces from Kconfig

- Add TABs

Signed-off-by: simbit18 <simbit18@gmail.com>
2026-07-25 14:08:18 -03:00
Marco Casaroli
8770fbea0f rp23xx: Add external QSPI PSRAM (APS6404) support for the Pimoroni Pico Plus 2.
Adds a driver for the external QSPI PSRAM hanging off QMI chip select 1,
such as the 8 MiB APS6404 fitted on the Pimoroni Pico Plus 2.

rp23xx_psramconfig() assigns the CS1 pin, reads the device ID over the QMI
direct interface to confirm an APS6404-family part (KGD 0x5D), resets it
into quad mode and programs the QMI M1 timing/read/write formats so the
region at 0x11000000 becomes directly addressable and writable.  Because
driving the QMI in direct mode stalls execute-in-place from the flash, the
detection and (re)configuration code runs from RAM (.time_critical) with
interrupts disabled; the command bytes are selected with immediates rather
than a .rodata table for the same reason.  The register values follow the
Raspberry Pi Pico SDK setup_psram().

The detection routine only keeps the QMI DIRECT_CSR synchronization that is
strictly necessary.  Each candidate busy-wait was removed one at a time and
re-verified on hardware: the post-enable "cooldown" waits, the READ_ID
TXEMPTY wait (redundant with the BUSY wait after it), and a fixed nop delay
proved unnecessary and are omitted.  The three BUSY waits that remain -- after
the quad-mode nudge, after each READ_ID byte, and after each reset/quad-enable
command -- are required and carry a comment explaining that the frame must
finish shifting before the chip select is deasserted, and what breaks
otherwise (garbage ID reads, or the shared QMI bus wedging).

rp23xx_psram_restore() re-applies the M1 configuration and is meant to be
called from the flash write path, which goes through the bootrom and
reconfigures the shared QMI for chip select 0.

rp23xx_heaps.c is wired into the build and now uses the detected size, so
the PSRAM is exposed to the memory manager (added to the main heap, used as
a separate heap, or as the user heap) and is skipped cleanly when no PSRAM
is present.

Enabled by default on the pimoroni-pico-2-plus:nsh configuration, where it
adds the 8 MiB to the main heap.  A documentation page for the Pimoroni Pico
Plus 2 is added alongside the other rp23xx boards, covering its serial
console, LED, the external PSRAM and how it is exposed to the heap, the
supported capabilities and the available configurations, with a photo of the
board.

Tested on Pimoroni Pico Plus 2 hardware: detection reports the 8 MiB
APS6404, the region is read/write across its whole range (ramtest word,
half-word and byte passes, marching/pattern/address-in-address), and the
heap reports the extra 8 MiB.

Assisted-by: Claude Code:claude-opus-4-8
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-25 13:49:05 -03:00
Marco Casaroli
5fd518a27c rp23xx: Add tickless OS support using the RP2350 hardware TIMER.
The port could only run with a periodic ARM SysTick tick.  Add an alarm/
oneshot lower-half backed by an RP2350 system timer block so the scheduler
can run tickless, waking the CPU only when a timer actually expires.

rp23xx_oneshot.c implements the ONESHOT_COUNT lower-half (mirroring the
RISC-V mtimer driver).  A timer block is a free-running 64-bit microsecond
counter (clocked by the TICKS block, independent of the SysTick), which serves
directly as the monotonic time base returned by current(), so timekeeping is
exact to 1 us.  The one adaptation versus a full 64-bit compare timer is that
the RP2350 ALARM registers match only the low 32 bits of the counter:
max_delay() is therefore capped below 2^32 counts (~71.5 minutes) so the
scheduler never asks for a longer interval, and any deadline that is already
due -- or that the counter reaches while the alarm is being armed -- is
raised immediately through the INTF force register instead of waiting a full
32-bit wrap for the compare to match again.

Enabled with CONFIG_RP23XX_SYSTIMER_TICKLESS (mutually exclusive with
RP23XX_SYSTIMER_SYSTICK), which selects ONESHOT, ONESHOT_COUNT and
ALARM_ARCH; up_timer_initialize() then hands the oneshot to
up_alarm_set_lowerhalf().  ARCH_CHIP_RP23XX now selects ARCH_HAVE_TICKLESS.
The block is selectable with CONFIG_RP23XX_SYSTIMER_TICKLESS_TIMER0 (default)
or _TIMER1; the chosen block is claimed exclusively by the scheduler and is
excluded from the /dev/timer driver (CONFIG_RP23XX_TIMER) in Kconfig, so the
tickless clock and a /dev/timer device can coexist on different blocks.

Tested on Pimoroni Pico Plus 2 (RP2350B) hardware with CONFIG_SCHED_TICKLESS
and CONFIG_SCHED_TICKLESS_ALARM: the image boots to nsh and keeps accurate
time -- "uptime" advances at real-time rate (17 s over a measured 17.4 s) and
"sleep 4" blocks for 4.25 s of wall time -- confirming the oneshot both drives
the scheduler and provides a correct 1 MHz monotonic clock.

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-25 12:58:40 -03:00
Marco Casaroli
b00d7005b0 rp23xx: Add /dev/timer driver on the TIMER0/TIMER1 blocks.
The RP2350 has two system timer blocks (TIMER0, TIMER1), each a free-running
64-bit counter incremented once per microsecond by the TICKS block (set up in
rp23xx_clock.c).  They are independent of the ARM SysTick that drives the OS
tick, so they are free for application use, but the port had no driver for
them.

Add rp23xx_timer.c, a NuttX timer lower-half that binds a block to a
/dev/timerN device.  It uses ALARM0 of the block, which matches the low 32
bits of the microsecond counter, to implement single-shot and periodic
timeouts with 1 us resolution and a maximum interval of 2^32 - 1 us (~71.5
minutes).  Periodic reloads are scheduled relative to the previous expiry to
avoid drift, but never behind the counter (an alarm set in the past would not
match until the 32-bit counter wraps).

Enable with CONFIG_RP23XX_TIMER (which selects CONFIG_TIMER), then turn on each
block independently: CONFIG_RP23XX_TIMER0 registers /dev/timer0 and
CONFIG_RP23XX_TIMER1 registers /dev/timer1.  A block claimed by the tickless
oneshot (CONFIG_RP23XX_SYSTIMER_TICKLESS) is excluded from these choices in
Kconfig, so the two features can be enabled together without colliding on the
same block or its alarm IRQ.

Tested on Pimoroni Pico Plus 2 (RP2350B) hardware with examples/timer and a
CMSIS-DAP probe.  The device registers as /dev/timer0; the ALARM0 interrupt
fires at the programmed period (verified over SWD at the configured 1 s
interval, not a busy loop), and the full path -- alarm match, the driver ISR,
the timer notification and delivery of the SIGNO to user space -- reaches the
example's signal handler and increments its counter.

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-25 12:58:40 -03:00
Marco Casaroli
8c94a72657 rp23xx: Add an MTD driver over the unused QSPI flash.
The rp2350 executes in place from external QSPI flash, and a NuttX image
normally leaves most of that flash unused.  This exposes the unused region
as an MTD device so it can carry a filesystem, mirroring what the rp2040
port already provides with rp2040_flash_mtd.c.

The region is given by RP23XX_FLASH_MTD_OFFSET and RP23XX_FLASH_MTD_SIZE,
both multiples of the 4096 byte erase sector.  Initialization fails rather
than corrupting the running image if the region would overlap the NuttX
binary, checked against __flash_binary_end.

Erase and program use the bootrom flash routines.  Those stall instruction
fetch from the same flash, so they run from SRAM with interrupts disabled
and, on SMP builds, the other core parked; afterwards the QSPI interface is
returned to execute-in-place mode.  By default that restores the fast read
mode the bootrom configured at boot; RP23XX_FLASH_MTD_SAFE_XIP instead
always uses the bootrom flash_enter_cmd_xip routine, which is slower to
execute from but depends only on the documented bootrom entry point.

The driver answers BIOC_XIPBASE with the memory-mapped address of the
region, so a filesystem supporting execute in place can hand out real flash
pointers rather than copying into RAM.

The common board bringup registers the device as /dev/rpflash.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-25 19:53:34 +08:00
Marco Casaroli
52e84e0c0a arch/arm/rp23xx: Add hardware TRNG driver for /dev/random.
Add a driver for the rp2350 hardware true random number generator.

Enabling CONFIG_RP23XX_RNG selects ARCH_HAVE_RNG and builds the driver,
which registers /dev/random (and /dev/urandom when CONFIG_DEV_URANDOM
selects the architecture source, DEV_URANDOM_ARCH).  Each read enables
the entropy source, waits for a valid 192-bit entropy holding register
(EHR) sample, reads the six 32-bit EHR words, and repeats until the
request is satisfied.

Document the TRNG on the rp23xx platform page.

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-25 15:06:56 +08:00
Lingao Meng
aa3157e234 arch/sim: Add PTY mode for simulated UART
The simulated UART driver currently opens the host path configured by
CONFIG_SIM_UARTx_NAME directly. This requires the host-side serial endpoint
to exist before NuttX opens the UART, so users and CI jobs need an external
setup step such as socat to create a PTY pair. It also means the host
endpoint path is effectively a build-time choice: changing the host device
path requires changing configuration and rebuilding, which is inconvenient
for tests that allocate a fresh PTY path on each run.

Add CONFIG_SIM_UART_PTY for Linux sim builds. When enabled, non-console
simulated UART ports allocate a host pseudoterminal from /dev/ptmx, put the
host master side in raw mode, and print the host slave path when the NuttX
UART is opened. The NuttX-side device name remains CONFIG_SIM_UARTx_NAME,
for example /dev/ttySIM0, so applications continue to use the normal NuttX
serial API.

Keep the option disabled by default so existing configurations still open
the configured host path directly. Console UART handling is also left on the
existing host-open path.

Also make host_uart_checkin() and host_uart_checkout() check the actual
POLLIN/POLLOUT bits returned by poll(). This avoids treating error-only or
unrelated poll events as readable or writable serial readiness.

The main benefit is simpler and more deterministic simulator integration: a
simulated UART can expose a real host-visible /dev/pts/N endpoint by itself,
without pre-creating a matching host device and without rebuilding NuttX
when the host PTY path changes. This is useful for host-side test scripts
and external protocol tools while keeping application code on the standard
NuttX UART interface.

Companion apps-side test branch:

  https://github.com/LingaoM/nuttx-apps/tree/sim_uart_tester

Testing:

  Host:

    Ubuntu 22.04 x86_64

  Board/config:

    sim:nsh

  Apps test code:

    https://github.com/LingaoM/nuttx-apps/tree/sim_uart_tester

  Common test configuration:

    CONFIG_NSH_BUILTIN_APPS=y
    CONFIG_EXAMPLES_HELLO=y
    CONFIG_SIM_UART_NUMBER=1
    CONFIG_SIM_UART0_NAME="/dev/ttySIM0"
    CONFIG_SIM_UART_PTY=y

  DMA-mode build and test:

    1. Configure sim:nsh with the companion apps tree:

         ./tools/configure.sh -a ../nuttx-apps sim:nsh

    2. Enable the common test configuration above and keep DMA enabled:

         CONFIG_SIM_UART_DMA=y
         CONFIG_SERIAL_TXDMA=y
         CONFIG_SERIAL_RXDMA=y

    3. Build:

         make clean
         make -j16

    4. Start NuttX:

         ./nuttx

    5. In NSH, run the hello test app:

         nsh> hello
         /dev/ttySIM0 connected to pseudotty: /dev/pts/73

    6. In another terminal, run the host-side tester from the companion apps
       branch with the printed PTY path:

         cd ../nuttx-apps
         ./examples/hello/test_sim_uart_pty.py /dev/pts/73

    7. The host-side tester sends 32768 bytes from the host to NuttX and
       receives 49152 bytes from NuttX to the host. The payload includes
       non-text binary bytes. Both sides validate deterministic payload
       contents and checksums, then exchange an ACK.

    8. Observed host-side output:

         HOST_OPEN: /dev/pts/73
         HOST_TX: 32768 bytes checksum=0x1f9989f4
         HOST_RX: 49152 bytes checksum=0x06a45c69
         HOST_TX: ACK
         TEST PASSED

    9. Observed NuttX output:

         sim_uart_pty_test: binary RX 32768 TX 49152 passed

  Non-DMA build and test:

    1. Disable DMA for the same sim:nsh configuration:

         # CONFIG_SIM_UART_DMA is not set
         # CONFIG_SERIAL_TXDMA is not set
         # CONFIG_SERIAL_RXDMA is not set

    2. Refresh the configuration and rebuild. On this host, the installed
       Python olddefconfig shim is broken, so I refreshed Kconfig directly
       with kconfig-conf and the same environment that the NuttX Makefile
       passes to Kconfig:

         APPSDIR=/mnt/ssd/code/code/nuttx-apps \
         APPSBINDIR=/mnt/ssd/code/code/nuttx-apps \
         BINDIR=/mnt/ssd/code/code/nuttx \
         EXTERNALDIR=/mnt/ssd/code/code/nuttx/dummy \
           kconfig-conf --olddefconfig Kconfig

         make clean
         make -j16

    3. Repeated the same runtime steps as the DMA test:

         ./nuttx
         nsh> hello
         cd ../nuttx-apps
         ./examples/hello/test_sim_uart_pty.py /dev/pts/73

    4. Observed the same successful binary transfer result:

         HOST_TX: 32768 bytes checksum=0x1f9989f4
         HOST_RX: 49152 bytes checksum=0x06a45c69
         HOST_TX: ACK
         TEST PASSED
         sim_uart_pty_test: binary RX 32768 TX 49152 passed

  After the non-DMA test, I restored the default DMA configuration, rebuilt,
  and reran the same binary PTY test successfully so the final local build
  state was back on CONFIG_SIM_UART_DMA=y.

Assisted-by: Claude:Claude-Fable-5
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-07-25 15:03:56 +08:00