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
20 changes: 14 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,26 @@ jobs:
working-directory: tests
run: CFLAGS="${{ matrix.extra_cflags }}" make BOARD=${{ matrix.board }}

peripheral-drivers:
peripheral-tests:
runs-on: ubuntu-latest
strategy:
matrix:
source:
- src/block/sdhc_spi.c
- src/flash/spi_nor.c
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: Compile ${{ matrix.source }}
run: arm-none-eabi-gcc -c -I. -Wall -Werror ${{ matrix.source }} -o /dev/null
- name: Build tests
working-directory: tests
run: make BOARD=${{ matrix.board }} PERIPHERALS="${{ matrix.peripherals }}" TESTS="${{ matrix.tests }}"
11 changes: 9 additions & 2 deletions boards/peripheral/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ _PERIPHERAL_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

BOARD_SOURCE += $(_PERIPHERAL_DIR)/peripheral.c

ifdef PERIPHERAL_SDHC_SPI_SDCARD32GB
ifneq ($(filter sdhc_spi_sdcard32gb,$(PERIPHERALS)),)
CFLAGS += -DPERIPHERAL_SDHC_SPI_SDCARD32GB
BOARD_SOURCE += $(_PERIPHERAL_DIR)/block/sdhc_spi_sdcard32gb.c
BOARD_SOURCE += $(WHAL_DIR)/src/block/sdhc_spi.c
endif

ifdef PERIPHERAL_SPI_NOR_W25Q64
ifneq ($(filter spi_nor_w25q64,$(PERIPHERALS)),)
CFLAGS += -DPERIPHERAL_SPI_NOR_W25Q64
BOARD_SOURCE += $(_PERIPHERAL_DIR)/flash/spi_nor_w25q64.c
BOARD_SOURCE += $(WHAL_DIR)/src/flash/spi_nor.c
endif

ifneq ($(filter bmi270,$(PERIPHERALS)),)
CFLAGS += -DPERIPHERAL_BMI270
BOARD_SOURCE += $(_PERIPHERAL_DIR)/sensor/imu/bmi270.c
BOARD_SOURCE += $(WHAL_DIR)/src/sensor/imu/bmi270.c
BOARD_SOURCE += $(WHAL_DIR)/src/sensor/imu/bmi270_config_data.c
endif
30 changes: 30 additions & 0 deletions boards/peripheral/peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "flash/spi_nor_w25q64.h"
#endif

#ifdef PERIPHERAL_BMI270
#include "sensor/imu/bmi270.h"
#endif

whal_PeripheralBlock_Cfg g_peripheralBlock[] = {
#ifdef PERIPHERAL_SDHC_SPI_SDCARD32GB
{
Expand All @@ -33,6 +37,16 @@ whal_PeripheralFlash_Cfg g_peripheralFlash[] = {
{0}, /* sentinel */
};

whal_PeripheralSensor_Cfg g_peripheralSensor[] = {
#ifdef PERIPHERAL_BMI270
{
.name = "bmi270",
.dev = &g_whalBmi270,
},
#endif
{0}, /* sentinel */
};

whal_Error Peripheral_Init(void)
{
whal_Error err;
Expand All @@ -49,13 +63,29 @@ whal_Error Peripheral_Init(void)
return err;
}

#if PERIPHERAL_SENSOR_COUNT > 0
for (size_t i = 0; g_peripheralSensor[i].dev; i++) {
err = whal_Sensor_Init(g_peripheralSensor[i].dev);
if (err)
return err;
}
#endif

return WHAL_SUCCESS;
}

whal_Error Peripheral_Deinit(void)
{
whal_Error err;

#if PERIPHERAL_SENSOR_COUNT > 0
for (size_t i = 0; g_peripheralSensor[i].dev; i++) {
err = whal_Sensor_Deinit(g_peripheralSensor[i].dev);
if (err)
return err;
}
#endif

for (size_t i = 0; g_peripheralFlash[i].dev; i++) {
err = whal_Flash_Deinit(g_peripheralFlash[i].dev);
if (err)
Expand Down
16 changes: 16 additions & 0 deletions boards/peripheral/peripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <wolfHAL/wolfHAL.h>
#include <wolfHAL/block/block.h>
#include <wolfHAL/flash/flash.h>
#include <wolfHAL/sensor/sensor.h>
#include <stddef.h>
#include <stdint.h>

Expand All @@ -24,9 +25,24 @@ typedef struct {
size_t sectorSz; /* Sector (erase) size in bytes */
} whal_PeripheralFlash_Cfg;

/* Peripheral sensor device test configuration */
typedef struct {
const char *name;
whal_Sensor *dev;
} whal_PeripheralSensor_Cfg;

extern whal_PeripheralBlock_Cfg g_peripheralBlock[];
extern whal_PeripheralFlash_Cfg g_peripheralFlash[];

enum {
#ifdef PERIPHERAL_BMI270
PERIPHERAL_SENSOR_BMI270,
#endif
PERIPHERAL_SENSOR_COUNT,
};

extern whal_PeripheralSensor_Cfg g_peripheralSensor[];

whal_Error Peripheral_Init(void);
whal_Error Peripheral_Deinit(void);

Expand Down
29 changes: 29 additions & 0 deletions boards/peripheral/sensor/imu/bmi270.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "bmi270.h"
#include <wolfHAL/sensor/imu/bmi270.h>
#include <wolfHAL/sensor/imu/bmi270_config_data.h>
#include "board.h"

/*
* Bosch BMI270 — 6-axis IMU (accelerometer + gyroscope)
*
* - I2C address: 0x68 (SDO low)
* - Standard mode (100 kHz) or Fast mode (400 kHz)
* - Requires 8192-byte config blob upload during init
*/

whal_I2c_ComCfg g_bmi270ComCfg = {
.freq = 400000, /* 400 kHz fast mode */
.addr = WHAL_BMI270_ADDR_LOW,
.addrSz = 7,
};

whal_Sensor g_whalBmi270 = {
.driver = &whal_Bmi270_Driver,
.cfg = &(whal_Bmi270_Cfg) {
.i2c = &g_whalI2c,
.comCfg = &g_bmi270ComCfg,
.configData = whal_bmi270_config_data,
.configDataSz = WHAL_BMI270_CONFIG_DATA_SZ,
.DelayMs = Board_WaitMs,
},
};
10 changes: 10 additions & 0 deletions boards/peripheral/sensor/imu/bmi270.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef BOARD_SENSOR_IMU_BMI270_H
#define BOARD_SENSOR_IMU_BMI270_H

#include <wolfHAL/wolfHAL.h>
#include <wolfHAL/sensor/sensor.h>
#include <wolfHAL/sensor/imu/bmi270.h>

extern whal_Sensor g_whalBmi270;

#endif /* BOARD_SENSOR_IMU_BMI270_H */
2 changes: 2 additions & 0 deletions boards/stm32wb55xx_nucleo/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/timer.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/supply.c)
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/*/rng.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/crypto.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/block.c)
Expand Down
64 changes: 42 additions & 22 deletions boards/stm32wb55xx_nucleo/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@

/* SysTick timing */
volatile uint32_t g_tick = 0;
volatile uint8_t g_waiting = 0;
volatile uint8_t g_tickOverflow = 0;

void SysTick_Handler()
void SysTick_Handler(void)
{
uint32_t tickBefore = g_tick++;
if (g_waiting) {
if (tickBefore > g_tick)
g_tickOverflow = 1;
}
g_tick++;
}

uint32_t Board_GetTick(void)
Expand Down Expand Up @@ -64,6 +58,7 @@ static const whal_Stm32wbRcc_Clk g_clocks[] = {
{WHAL_STM32WB55_SPI1_CLOCK},
{WHAL_STM32WB55_RNG_CLOCK},
{WHAL_STM32WB55_AES1_CLOCK},
{WHAL_STM32WB55_I2C1_CLOCK},
};
#define CLOCK_COUNT (sizeof(g_clocks) / sizeof(g_clocks[0]))

Expand Down Expand Up @@ -135,11 +130,39 @@ whal_Gpio g_whalGpio = {
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_UP,
},
[I2C_SCL_PIN] = { /* I2C1 SCL */
.port = WHAL_STM32WB_GPIO_PORT_B,
.pin = 8,
.mode = WHAL_STM32WB_GPIO_MODE_ALTFN,
.outType = WHAL_STM32WB_GPIO_OUTTYPE_OPENDRAIN,
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_UP,
.altFn = 4,
},
[I2C_SDA_PIN] = { /* I2C1 SDA */
.port = WHAL_STM32WB_GPIO_PORT_B,
.pin = 9,
.mode = WHAL_STM32WB_GPIO_MODE_ALTFN,
.outType = WHAL_STM32WB_GPIO_OUTTYPE_OPENDRAIN,
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_UP,
.altFn = 4,
},
},
.pinCount = PIN_COUNT,
},
};

/* I2C */
whal_I2c g_whalI2c = {
WHAL_STM32WB55_I2C1_DEVICE,

.cfg = &(whal_Stm32wbI2c_Cfg) {
.pclk = 64000000,
.timeout = &g_whalTimeout,
},
};

/* SPI */
whal_Spi g_whalSpi = {
WHAL_STM32WB55_SPI1_DEVICE,
Expand Down Expand Up @@ -259,20 +282,7 @@ whal_Crypto g_whalCrypto = {
void Board_WaitMs(size_t ms)
{
uint32_t startCount = g_tick;
g_waiting = 1;
while (1) {
uint32_t currentCount = g_tick;
if (g_tickOverflow) {
if ((UINT32_MAX - startCount) + currentCount > ms) {
break;
}
} else if (currentCount - startCount > ms) {
break;
}
}

g_waiting = 0;
g_tickOverflow = 0;
while (g_tick - startCount < ms);
}

whal_Error Board_Init(void)
Expand Down Expand Up @@ -347,6 +357,11 @@ whal_Error Board_Init(void)
return err;
}

err = whal_I2c_Init(&g_whalI2c);
if (err) {
return err;
}

err = whal_Flash_Init(&g_whalFlash);
if (err) {
return err;
Expand Down Expand Up @@ -414,6 +429,11 @@ whal_Error Board_Deinit(void)
return err;
}

err = whal_I2c_Deinit(&g_whalI2c);
if (err) {
return err;
}

err = whal_Spi_Deinit(&g_whalSpi);
if (err) {
return err;
Expand Down
3 changes: 3 additions & 0 deletions boards/stm32wb55xx_nucleo/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern whal_Spi g_whalSpi;
extern whal_Flash g_whalFlash;
extern whal_Rng g_whalRng;
extern whal_Crypto g_whalCrypto;
extern whal_I2c g_whalI2c;
extern whal_Irq g_whalIrq;

extern whal_Timeout g_whalTimeout;
Expand All @@ -26,6 +27,8 @@ enum {
SPI_MISO_PIN,
SPI_MOSI_PIN,
SPI_CS_PIN,
I2C_SCL_PIN,
I2C_SDA_PIN,
PIN_COUNT,
};

Expand Down
Loading
Loading