Skip to content

W5500 ethernet driver - #381

Open
xaelsouth wants to merge 195 commits into
ChibiOS:chibios-21.11.xfrom
xaelsouth:chibios-21.11.x
Open

xaelsouth wants to merge 195 commits into
ChibiOS:chibios-21.11.xfrom
xaelsouth:chibios-21.11.x

Conversation

@xaelsouth

Copy link
Copy Markdown

W5500 ethernet driver for ChibiOS. W5500 is initialized in in Ethernet Mode and requires LWIP to communicate. No built-in TCP/IP stack is used.

@fpoussin

fpoussin commented Dec 5, 2023

Copy link
Copy Markdown
Member

is mbedtls required for a simple example?

@xaelsouth

Copy link
Copy Markdown
Author

mbedtls ist not really neccessary, but nice to have, because it can be seen how mbedtls can be used.

@fpoussin

Copy link
Copy Markdown
Member

Could you strip it down to the bare minimum for a working tcp/ip example?
It's really big as of now.

@xaelsouth
xaelsouth force-pushed the chibios-21.11.x branch 6 times, most recently from 96064ba to 8be9d00 Compare November 15, 2026 04:56
xaelsouth and others added 30 commits November 24, 2026 23:58
… (LETIMER) and SYSTICKv4 (BURTC); BURTCv1 un-coupled (calendar only)

SYSRTC0 gives a native 32-bit counter on an LF clock (keeps running in
EM2/EM3/EM4) with two compare channels and its own SEQ vector, so there
is no conflict with the BURTC calendar. LETIMER0 (24-bit, needed SW
extension) stays free for LETIMERv1/GPT; BURTC is used purely as the
backup-domain timekeeper (BURTCv1), its EFR32_ST_OWNS_BURTC sharing
guards removed. SYSTICKv1 (core SysTick) remains available as an
optional build (EFR32_USE_SYSTICKV1=yes). All FG23 mcuconf.h drop
EFR32_ST_USE_TIMER; testhal readmes updated. 35/35 projects build;
SYSTICKv1/v2, RTC, BURAM, LETIMER-GPT pass on DK2600A.
… reads, BURAM magic)

testhal BURTC covers what the RTC calendar test does not: BURAM retention
across a warm reset (self-resetting magic-word test) and the 32-bit
overflow path — CNT set near the top, OF must fire after exactly 32768
ticks (= 1.0 s at 32768 Hz, measured against the SYSRTC systick) and
ovf_counter in BURAM must increment. On-target: ALL PASS.

Hardware finding: raw BURTC->CNT reads on this FG23B010 lag the real
counter (reads advance ~0.4% of the true rate while OF timing proves
32768 Hz; CNT writes and OF/COMP interrupts are exact). The driver now
reads CNT with a read-until-two-consecutive-equal loop and documents the
issue; BURAM state is validated with a magic word (garbage after backup-
domain power-on previously produced year 2069). 36/36 projects build.
… gains LESENSE scan-hz setter and I2C pin routing

BURTCv1: the calendar is now driven by the COMP interrupt (1 s period,
comp_cnt in BURAM) plus OF for the 64-bit extension; rtcGetTime reads only
BURAM words, never CNT — on FG23B010 CNT reads lag the real counter unless
the LF domain is periodically active, which made the old CNT-read calendar
drift. Side effect: with COMP ticking, CNT reads are fresh again (verified
on target: 3279/3278/32770 ticks per 100 ms/1 s). Alarm channel removed
(EFR32_RTC_NUM_ALARMS=0) since BURTC has a single COMP. Resolution: 1 s.

LESENSEv1: new lesense_lld_set_scan_hz() owns the TIMCTRL/SYNCBUSY handling
for runtime scan-rate changes. I2Cv1: I2CConfig gains sda/scl port+pin;
GPIO->I2CxROUTE is programmed by the LLD on start/cleared on stop.

application/SiliconLabs now uses LLD only — no direct register access
(coil.c -> lesense_lld_set_scan_hz, main.c -> I2CConfig routing,
temp_sensor.c -> EFL BaseFlash API instead of raw MSC). 36/36 build;
RTC and BURTC tests ALL PASS on DK2600A.
…0, COMP owned by calendar)

The RTC_ALARMS>0-guarded rtc_lld_set_alarm/get_alarm and the RTCAlarm
typedef are dead code for this port: BURTC has a single COMP channel, now
owned by the COMP-driven calendar tick. The core hal_rtc.c already guards
all alarm APIs with RTC_ALARMS>0, so nothing references them. If an alarm
is ever needed, SYSRTC CMP1 (free next to the SYSTICKv2 tick on CMP0) is
the right place. RTC/BURTC tests still ALL PASS on DK2600A; 36/36 build.
…tick)

rtcSetAlarm/rtcGetAlarm are back (EFR32_RTC_NUM_ALARMS=1) but implemented in
BURTCv1 on SYSRTC group0 CMP1: set_alarm arms CMP1 = CNT + offset (CNT ticks
at CH_CFG_ST_FREQUENCY under SYSTICKv2); the shared SYSRTC SEQ vector is
forwarded by SYSTICKv2 to sysrtc_lld_serve_interrupt(), which dispatches
CMP1 to the RTCD1 alarm callback (one-shot, channel disabled on fire).
CMP0 stays the system tick. Requires EFR32_SYSRTC_USE_SYSRTC=TRUE +
EFR32_ST_USE_SYSRTC=TRUE in halconf_community.h (set in RTC/BURTC tests,
BRD4001A demo, both apps). RTC test extended: alarm readback + fired-after
2004 ms for +2 s PASS on DK2600A; BURTC test still ALL PASS; 36/36 build.
…SUBSECONDS

Seconds still come from BURAM only (comp_cnt/OF interrupts); the
millisecond field of rtcGetTime is now taken from one CNT read, guarded by
EFR32_RTC_HAS_SUBSECONDS (set FALSE for 1 s resolution). Safe because the
1 Hz COMP calendar tick keeps the LF sync path warm — CNT reads track the
real 32768 Hz rate again (verified earlier on target). A COMP firing
mid-read is detected by re-reading comp_cnt so seconds and ms stay
consistent. RTC test on DK2600A: ms advances, seconds exact, alarm PASS;
36/36 build.
…ctrl config; ringbuf.c include fix

letimer_lld_window_start(ticks, cb) arms LETIMER0 in REPMODE_ONESHOT with
PRS start (channel via SIGROUTE_CON_LETIMER0_START): each PRS pulse starts
the window, further starts while running are ignored (no retrigger); on
underflow the UF IRQ calls cb from ISR context — the place to snapshot a
pulse counter + system time into a ring buffer. Works without HAL_USE_GPT
(EFR32_LETIMER_WIN_USE_LETIMER0 in halconf_community.h); #error if both
GPT and window claim LETIMER0. LESENSEConfig gains prsctrl (PRSCTRL write
in lesense_lld_start). ringbuf.c now includes hal.h (osalSysLockFromISR).
36/36 build; PULSECAP and LESENSE tests PASS on DK2600A.
…ow that lost the UF race

A PRS START arriving in the same LF cycle as the underflow can be ignored
(timer still looked RUNNING). The window-end callback now double-reads the
pulse counter; if it moved after the snapshot, it calls window_kick(), which
issues CMD START only when the timer is stopped (START while running is a
hardware no-op), so a late pulse is captured by a fresh window. 36/36 build;
PULSECAP PASS on DK2600A.
…y with callback) + LETIMERv1 self-re-arming window chain with set_period
…able) + LETIMERv1 window_restart for immediate period switch
…0PRSEN before PCNT clock-domain switch; use thread-class dmaStreamAlloc/Free in LLD start/stop
The EUSART branch of sio_lld_set_baud() tested only siop->usart != NULL,
so SIOD4 (USART0) was programmed through the EUSART register layout and
the USART branch was never reached. Exclude USART instances explicitly.

Also drop the now-redundant usart != NULL guards: _sio_lld_is_usart()
only compares the SIODriver pointer, so the dispatch branches can key off
it alone.
PRS SWPULSE does reach PCNT0 S0IN, but the CMU glitch-free switch to
PCNTS0 (CMU_PCNT0CLKCTRL.CLKSEL) needs wide S0 edges around the switch:
ASYNC_SWPULSE produces only a one-EM01GRPACLK-cycle (~50 ns) pulse, which
the CMU mux synchronizer swallows, so switching CLKSEL while S0 is idle
never completes and the PCNT LF domain stays dead (SYNCBUSY stuck,
qeiStart hangs). Pump ASYNC_SWLEVEL with ~1 ms high/low toggles before the
clock switch and while waiting for SYNCBUSY. Verified on BRD2600A:
PULSECAP testhal passes (7 injected pulses counted, CNT=7).
…ine SPI_SUPPORTS_CIRCULAR

The field-expansion macros (efl/rtc/spi/adc/dac/uart/gpt/sio) ended without
a semicolon, producing 'no semicolon at end of struct or union' warnings in
the core hal_efl.h/hal_rtc.h/hal_spi_v1.h structs. SPIv1 also never defined
SPI_SUPPORTS_CIRCULAR, which hal_spi_v1.h tests with #if (-Wundef).
DK2600A is the dev-kit part number; the board itself is BRD2600A (rev A03).
All Makefiles (apps, demo, testhal) now include the
SILABS_EFR32FG23_BRD2600A_REVA03 board dir, whose board.c/board.h were
already identical. The duplicate board dir is removed.
The DK2600A is the dev-kit part number; the radio board is BRD2600A, and
the board dir/demos were already renamed to SILABS_EFR32FG23_BRD2600A_REVA03
/ RT-EFR32FG23B010F512-BRD2600A. Drop the redundant DK2600A-named demo and
point the port readme audit note at the BRD2600A demo.
…ar shadow-only

On FG23 the display pipeline only loads SEGD registers into the panel on an
explicit LCD_CMD_LOAD (UPDATECTRL.AUTOLOAD defaults to MANUAL), so updates
after the first never reached the glass. lcd_lld_write_segd_regs() now issues
CMD.LOAD and waits (bounded) for LOADBUSY to clear. lcd_lld_clear() now only
clears the shadow, matching the hal_lcd.h contract (a direct SEGD write there,
immediately followed by the update write, left the panel blank).
…ibiOS#5)

The map rows were ordered ChibiOS#1..ChibiOS#5 while lcd_write_number() treats model index
0 as the leftmost digit, so numbers rendered digit-reversed on the glass
(64 showed as 46000). Rows now match the SDK EFM_DISPLAY_DEF order.
…he kernel on NACK); mask it in the ISR

testhal EFR32FG23x0xx/LCD: visual pattern demo (DEGC/dots/walking-8/all-on with blanks)
…or driver

- i2c_lld_start/stop now use dmaStreamAllocI/dmaStreamFreeI (they run under
  i2cStart/i2cStop's lock; the locking variants double-lock -> SV#4 panic)
- pure reads send the address with the R bit; combined TX+RX issues a
  repeated START (CMD=START before TXDATA, per em_i2c) with address|R;
  per-byte ACK/NACK/STOP driven from RXDATAV; RXDATAV IF cleared by SW
  (Series 2 requirement); ABORT only on timeout/error
- devices_lib/sensors: new si7021.c/.h (Si7021/Si7020/Si7013 @0x40) using
  finite config-provided I2C timeouts instead of TIME_INFINITE
- testhal I2C: acquire the bus before scanning; probe 0x40 TX/RX/TX+RX
  with state dump (verified on BRD2600A: Si7021 ID read returns 0x15)
…e lld_start/stop run under the HAL lock

Static audit of the whole SILABS LLD tree for lock-class misuse:
adcStart() (hal_adc.c) and sioStart() (hal_sio.c) call *_lld_start/stop
under osalSysLock(), so the locking dmaStreamAlloc/Free there double-lock
(SV#4 panic, same as the I2C case). SPI/DAC are xhal (start runs unlocked),
LCD/LESENSE/EFL are lock-free macros/direct calls, AES sem use is correct
(SignalI in ISR, Wait in thread) — those keep the locking variants.
… LLD: per-channel TIMING/OFFSET, ACMP0/1 POSSEL setup for MUXTHRES, DECODE-aware channels
…tation setup (clock, TRIGMODE=LESENSE, EN before OUTCTRL, CH0EN, ABUS route via cfg->dac_port/pin)
- hal_lld: wait (bounded, generous) for LFXO RDY|ENS after FORCEEN; a cold
  32 kHz crystal can exceed the old 4M-cycle spin, and LF clock trees
  (LCDCLK, EM23GRPACLK, SYSRTCCLK) latch a dead mux if selected before RDY
- LCD LLD: wait for LFXO ready before selecting it as LCDCLK (fall back to
  ULFRCO); panel stayed blank otherwise even though LFXO later reported RDY
- BRD2600A board_lcd_config: frame_rate (FRDIV) 1 -> 90; with the 32.768 kHz
  LCDCLK, FRDIV=1 gives a far-too-high frame rate and the CE322-1002 glass
  looks faint/blank; FRDIV=90 is bright and steady (verified on target)
…or used channel pins and the DAC excite pin

On xG23 a pad only connects to the analog bus when the *BUSALLOC field
allocates it (RM 24.6.22-24). Without this, ACMP inputs and VDAC outputs
stay tristated and LESENSE never sees a signal. Allocate each used channel
pin to its ACMP (ch0-7 -> ACMP0, ch8-15 -> ACMP1) and dac_port/dac_pin to
VDAC0CH0.
Correct peripheral handling and ring buffer synchronization, and update board tests and coverage notes. ADC scanning and DAC DMA streaming remain incomplete.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants