Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/boards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Board Builds

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
boards:
runs-on: ubuntu-latest
strategy:
matrix:
board: [stm32wb55xx_nucleo, pic32cz_curiosity_ultra, stm32h563zi_nucleo, stm32f411_blackpill, stm32c031_nucleo]
extra_cflags: ["", "-DWHAL_CFG_NO_TIMEOUT"]
include:
- board: stm32wb55xx_nucleo
extra_cflags: "-DBOARD_DMA"
steps:
- uses: actions/checkout@v4

- name: Install ARM toolchain
run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi

- name: Build blinky
working-directory: examples/blinky
run: CFLAGS="${{ matrix.extra_cflags }}" make BOARD=${{ matrix.board }}

- name: Build tests
working-directory: tests
run: CFLAGS="${{ matrix.extra_cflags }}" make BOARD=${{ matrix.board }}
67 changes: 0 additions & 67 deletions .github/workflows/ci.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/core-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Core Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
core-tests:
runs-on: ubuntu-latest
strategy:
matrix:
extra_cflags: ["", "-DWHAL_CFG_NO_TIMEOUT"]
steps:
- uses: actions/checkout@v4

- name: Build and run core tests
working-directory: tests/core
run: CFLAGS="${{ matrix.extra_cflags }}" make run
32 changes: 32 additions & 0 deletions .github/workflows/peripheral-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Peripheral Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
peripheral-tests:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- board: stm32wb55xx_nucleo
peripherals: bmi270
tests: bmi270
- board: stm32wb55xx_nucleo
peripherals: spi_nor_w25q64
tests: flash
- board: stm32wb55xx_nucleo
peripherals: sdhc_spi_sdcard32gb
tests: block
steps:
- uses: actions/checkout@v4

- name: Install ARM toolchain
run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi

- name: Build tests
working-directory: tests
run: make BOARD=${{ matrix.board }} PERIPHERALS="${{ matrix.peripherals }}" TESTS="${{ matrix.tests }}"
27 changes: 27 additions & 0 deletions .github/workflows/watchdog-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Watchdog Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
watchdog-tests:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- board: stm32wb55xx_nucleo
watchdog: iwdg
- board: stm32wb55xx_nucleo
watchdog: wwdg
steps:
- uses: actions/checkout@v4

- name: Install ARM toolchain
run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi

- name: Build tests
working-directory: tests
run: make BOARD=${{ matrix.board }} TESTS=watchdog WATCHDOG=${{ matrix.watchdog }}
5 changes: 4 additions & 1 deletion boards/stm32wb55xx_nucleo/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ OBJCOPY = $(GCC_PATH)arm-none-eabi-objcopy
CFLAGS += -Wall -Werror $(INCLUDE) -g3 \
-ffreestanding -nostdlib -mcpu=cortex-m4 \
-DPLATFORM_STM32WB -MMD -MP \
$(if $(DMA),-DBOARD_DMA)
$(if $(DMA),-DBOARD_DMA) \
$(if $(filter iwdg,$(WATCHDOG)),-DBOARD_WATCHDOG_IWDG) \
$(if $(filter wwdg,$(WATCHDOG)),-DBOARD_WATCHDOG_WWDG)
LDFLAGS = --omagic -static

LINKER_SCRIPT ?= $(_BOARD_DIR)/linker.ld
Expand All @@ -29,6 +31,7 @@ BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/flash.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/spi.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/i2c.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/sensor.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/watchdog.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/rng.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/crypto.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/block.c)
Expand Down
40 changes: 40 additions & 0 deletions boards/stm32wb55xx_nucleo/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ static const whal_Stm32wbRcc_Clk g_clocks[] = {
{WHAL_STM32WB55_RNG_CLOCK},
{WHAL_STM32WB55_AES1_CLOCK},
{WHAL_STM32WB55_I2C1_CLOCK},
#ifdef BOARD_WATCHDOG_WWDG
{WHAL_STM32WB55_WWDG_CLOCK},
#endif
};
#define CLOCK_COUNT (sizeof(g_clocks) / sizeof(g_clocks[0]))

Expand Down Expand Up @@ -244,6 +247,28 @@ whal_Crypto g_whalCrypto = {
},
};

#ifdef BOARD_WATCHDOG_IWDG
whal_Watchdog g_whalWatchdog = {
WHAL_STM32WB55_IWDG_DEVICE,

.cfg = &(whal_Stm32wbIwdg_Cfg) {
.prescaler = WHAL_STM32WB_IWDG_PR_32,
.reload = 100,
.timeout = &g_whalTimeout,
},
};
#elif defined(BOARD_WATCHDOG_WWDG)
whal_Watchdog g_whalWatchdog = {
WHAL_STM32WB55_WWDG_DEVICE,

.cfg = &(whal_Stm32wbWwdg_Cfg) {
.prescaler = WHAL_STM32WB_WWDG_TB_128,
.window = 0x7F,
.counter = 0x7F,
},
};
#endif

void Board_WaitMs(size_t ms)
{
uint32_t startCount = g_tick;
Expand Down Expand Up @@ -276,6 +301,14 @@ whal_Error Board_Init(void)
return err;
}

#ifdef BOARD_WATCHDOG_IWDG
/* Enable LSI osc required by the IWDG */
err = whal_Stm32wbRcc_Ext_EnableLsi(&g_whalClock, 1);
if (err) {
return err;
}
#endif

/* Enable clocks */
for (size_t i = 0; i < CLOCK_COUNT; i++) {
err = whal_Clock_Enable(&g_whalClock, &g_clocks[i]);
Expand Down Expand Up @@ -445,6 +478,13 @@ whal_Error Board_Deinit(void)
return err;
}

#ifdef BOARD_WATCHDOG_IWDG
err = whal_Stm32wbRcc_Ext_EnableLsi(&g_whalClock, 0);
if (err) {
return err;
}
#endif

err = whal_Clock_Deinit(&g_whalClock);
if (err) {
return err;
Expand Down
1 change: 1 addition & 0 deletions boards/stm32wb55xx_nucleo/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern whal_Rng g_whalRng;
extern whal_Crypto g_whalCrypto;
extern whal_I2c g_whalI2c;
extern whal_Irq g_whalIrq;
extern whal_Watchdog g_whalWatchdog;

extern whal_Timeout g_whalTimeout;
extern volatile uint32_t g_tick;
Expand Down
11 changes: 11 additions & 0 deletions docs/adding_a_board.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,18 @@ whal_Error Board_Init(void)

return WHAL_SUCCESS;
}
```

The watchdog is intentionally excluded from `Board_Init()` and `Board_Deinit()`.
Once started, most watchdog peripherals cannot be stopped — if `Board_Init()`
starts the watchdog, any delay before the application begins refreshing it will
cause an unexpected reset. The application or test should call
`whal_Watchdog_Init()` directly when it is ready to begin refreshing. The board
still defines the `g_whalWatchdog` instance and enables any required clocks
(e.g., WWDG APB clock, IWDG LSI oscillator) so the watchdog is ready to be
started.

```c
whal_Error Board_Deinit(void)
{
whal_Error err;
Expand Down
44 changes: 44 additions & 0 deletions docs/writing_a_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,50 @@ a transfer needs to be cancelled.

---

## Watchdog

Header: `wolfHAL/watchdog/watchdog.h`

The watchdog driver provides access to hardware watchdog timers that reset the
system if not periodically refreshed. On most hardware, the watchdog cannot be
stopped once started — only a system reset clears it.

### Init

Configure and start the watchdog. This typically involves:

- Setting the prescaler and reload/counter values from the configuration
- Enabling the watchdog peripheral

On some hardware (e.g., STM32 IWDG), the watchdog must be started before its
configuration registers can be written. The driver should handle this ordering
internally.

The board must enable any required clocks before calling Init. For example, the
STM32 WWDG requires an APB clock, while the IWDG requires the LSI oscillator.

The watchdog is NOT initialized in `Board_Init` — the test or application
controls when it starts, since once started it cannot be stopped.

### Deinit

Shut down the watchdog. On hardware where the watchdog cannot be stopped (e.g.,
STM32 IWDG), this function is a no-op.

### Refresh

Reload the watchdog counter to prevent a reset. Must be called periodically
within the configured timeout window. The exact mechanism is hardware-specific
(e.g., writing a reload key to IWDG_KR, or writing the counter value back to
WWDG_CR).

For window watchdogs, the refresh must occur within the valid window — refreshing
too early or too late triggers a reset. The driver does not enforce window timing;
it writes the reload value unconditionally and relies on the hardware to enforce
the window.

---

## EthPhy

Header: `wolfHAL/eth_phy/eth_phy.h`
Expand Down
28 changes: 28 additions & 0 deletions src/clock/stm32wb_rcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
#define RCC_APB1ENR2_LPTIM2EN_Pos 5 /* LPTIM2 clock enable */
#define RCC_APB1ENR2_LPTIM2EN_Msk (1UL << RCC_APB1ENR2_LPTIM2EN_Pos)

/* Control/Status Register - LSI oscillator control */
#define RCC_CSR_REG 0x094
#define RCC_CSR_LSI1ON_Pos 0 /* LSI1 oscillator enable */
#define RCC_CSR_LSI1ON_Msk (1UL << RCC_CSR_LSI1ON_Pos)

#define RCC_CSR_LSI1RDY_Pos 1 /* LSI1 oscillator ready */
#define RCC_CSR_LSI1RDY_Msk (1UL << RCC_CSR_LSI1RDY_Pos)

/* Clock Recovery RC Register - HSI48 oscillator control */
#define RCC_CRRCR_REG 0x098
#define RCC_CRRCR_HSI48ON_Pos 0 /* HSI48 oscillator enable */
Expand Down Expand Up @@ -361,6 +369,26 @@ whal_Error whal_Stm32wbRcc_Ext_EnableHsi48(whal_Clock *clkDev, uint8_t enable)
return WHAL_SUCCESS;
}

whal_Error whal_Stm32wbRcc_Ext_EnableLsi(whal_Clock *clkDev, uint8_t enable)
{
if (!clkDev) {
return WHAL_EINVAL;
}

whal_Reg_Update(clkDev->regmap.base, RCC_CSR_REG, RCC_CSR_LSI1ON_Msk,
whal_SetBits(RCC_CSR_LSI1ON_Msk, RCC_CSR_LSI1ON_Pos, enable));

if (enable) {
size_t rdy;
do {
whal_Reg_Get(clkDev->regmap.base, RCC_CSR_REG,
RCC_CSR_LSI1RDY_Msk, RCC_CSR_LSI1RDY_Pos, &rdy);
} while (!rdy);
}

return WHAL_SUCCESS;
}

const whal_ClockDriver whal_Stm32wbRccPll_Driver = {
.Init = whal_Stm32wbRccPll_Init,
.Deinit = whal_Stm32wbRccPll_Deinit,
Expand Down
Loading
Loading