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
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
working-directory: tests/core
run: CFLAGS="${{ matrix.extra_cflags }}" make run

cross-compile:
boards:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -38,3 +38,18 @@ jobs:
- name: Build tests
working-directory: tests
run: CFLAGS="${{ matrix.extra_cflags }}" make BOARD=${{ matrix.board }}

peripheral-drivers:
runs-on: ubuntu-latest
strategy:
matrix:
source:
- src/block/sdhc_spi.c
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
9 changes: 9 additions & 0 deletions boards/peripheral/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_PERIPHERAL_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

BOARD_SOURCE += $(_PERIPHERAL_DIR)/peripheral.c

ifdef PERIPHERAL_SDHC_SPI_SDCARD32GB
CFLAGS += -DPERIPHERAL_SDHC_SPI_SDCARD32GB
BOARD_SOURCE += $(_PERIPHERAL_DIR)/block/sdhc_spi_sdcard32gb.c
BOARD_SOURCE += $(WHAL_DIR)/src/block/sdhc_spi.c
endif
21 changes: 21 additions & 0 deletions boards/peripheral/block/sdhc_spi_sdcard32gb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "sdhc_spi_sdcard32gb.h"
#include <wolfHAL/block/sdhc_spi.h>
#include "board.h"

static whal_Spi_ComCfg g_sdcardComCfg = {
.freq = 25000000, /* 25 MHz */
.mode = WHAL_SPI_MODE_0,
.wordSz = 8,
.dataLines = 1,
};

whal_Block g_whalSdhcSpiSdcard32gb = {
.driver = &whal_SdhcSpi_Driver,
.cfg = &(whal_SdhcSpi_Cfg) {
.spiDev = &g_whalSpi,
.spiComCfg = &g_sdcardComCfg,
.gpioDev = &g_whalGpio,
.csPin = SPI_CS_PIN,
.timeout = &g_whalTimeout,
},
};
10 changes: 10 additions & 0 deletions boards/peripheral/block/sdhc_spi_sdcard32gb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef BOARD_SDHC_SPI_SDCARD32GB_H
#define BOARD_SDHC_SPI_SDCARD32GB_H

#include <wolfHAL/wolfHAL.h>
#include <wolfHAL/block/block.h>
#include <wolfHAL/block/sdhc_spi.h>

extern whal_Block g_whalSdhcSpiSdcard32gb;

#endif /* BOARD_SDHC_SPI_SDCARD32GB_H */
19 changes: 19 additions & 0 deletions boards/peripheral/peripheral.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "peripheral.h"

#ifdef PERIPHERAL_SDHC_SPI_SDCARD32GB
#include "block/sdhc_spi_sdcard32gb.h"
#endif

whal_PeripheralBlock_Cfg g_peripheralBlock[] = {
#ifdef PERIPHERAL_SDHC_SPI_SDCARD32GB
{
.name = "sdhc_spi_sdcard32gb",
.dev = &g_whalSdhcSpiSdcard32gb,
.blockSz = WHAL_SDHC_SPI_BLOCK_SZ,
.blockBuf = (uint8_t[WHAL_SDHC_SPI_BLOCK_SZ * 2]) {0},
.blockBufSz = WHAL_SDHC_SPI_BLOCK_SZ * 2,
.erasedByte = 0x00,
},
#endif
{0}, /* sentinel */
};
21 changes: 21 additions & 0 deletions boards/peripheral/peripheral.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef BOARD_PERIPHERAL_H
#define BOARD_PERIPHERAL_H

#include <wolfHAL/wolfHAL.h>
#include <wolfHAL/block/block.h>
#include <stddef.h>
#include <stdint.h>

/* Peripheral block device test configuration */
typedef struct {
const char *name;
whal_Block *dev;
uint8_t *blockBuf; /* Test buffer (must hold at least 2 blocks) */
size_t blockBufSz; /* Size of blockBuf in bytes */
size_t blockSz; /* Block size in bytes */
uint8_t erasedByte; /* Expected byte value after erase (0x00 or 0xFF) */
} whal_PeripheralBlock_Cfg;

extern whal_PeripheralBlock_Cfg g_peripheralBlock[];

#endif /* BOARD_PERIPHERAL_H */
1 change: 1 addition & 0 deletions boards/pic32cz_curiosity_ultra/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ 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/*/rng.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/block.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/pic32cz_*.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/systick.c)
6 changes: 3 additions & 3 deletions boards/pic32cz_curiosity_ultra/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static const whal_Pic32czClock_Clk g_peripheralClocks[] = {
.mclkEnablePos = 3,
},
};
#define PERIPHERAL_CLOCK_COUNT (sizeof(g_peripheralClocks) / sizeof(g_peripheralClocks[0]))
#define CLOCK_COUNT (sizeof(g_peripheralClocks) / sizeof(g_peripheralClocks[0]))

/* GPIO */
whal_Gpio g_whalGpio = {
Expand Down Expand Up @@ -168,7 +168,7 @@ whal_Error Board_Init(void)
}

/* Enable peripheral clocks */
for (size_t i = 0; i < PERIPHERAL_CLOCK_COUNT; i++) {
for (size_t i = 0; i < CLOCK_COUNT; i++) {
err = whal_Clock_Enable(&g_whalClock, &g_peripheralClocks[i]);
if (err)
return err;
Expand Down Expand Up @@ -232,7 +232,7 @@ whal_Error Board_Deinit(void)
}

/* Disable peripheral clocks */
for (size_t i = 0; i < PERIPHERAL_CLOCK_COUNT; i++) {
for (size_t i = 0; i < CLOCK_COUNT; i++) {
err = whal_Clock_Disable(&g_whalClock, &g_peripheralClocks[i]);
if (err)
return err;
Expand Down
9 changes: 7 additions & 2 deletions boards/stm32wb55xx_nucleo/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_BOARD_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

PLATFORM = stm32wb
TESTS ?= clock gpio flash timer rng crypto
TESTS ?= clock gpio flash timer rng crypto block

GCC = $(GCC_PATH)arm-none-eabi-gcc
LD = $(GCC_PATH)arm-none-eabi-ld
Expand All @@ -14,7 +14,7 @@ LDFLAGS = --omagic -static

LINKER_SCRIPT ?= $(_BOARD_DIR)/linker.ld

INCLUDE += -I$(_BOARD_DIR)
INCLUDE += -I$(_BOARD_DIR) -I$(WHAL_DIR)/boards/peripheral

BOARD_SOURCE = $(_BOARD_DIR)/ivt.c
BOARD_SOURCE += $(_BOARD_DIR)/board.c
Expand All @@ -25,7 +25,12 @@ BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/uart.c)
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/*/rng.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/crypto.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/block.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/stm32wb_*.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/systick.c)

# Peripheral devices
include $(WHAL_DIR)/boards/peripheral/Makefile.inc
100 changes: 83 additions & 17 deletions boards/stm32wb55xx_nucleo/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stddef.h>
#include "board.h"
#include <wolfHAL/platform/st/stm32wb55xx.h>
#include "peripheral.h"

/* SysTick timing */
volatile uint32_t g_tick = 0;
Expand All @@ -25,7 +26,7 @@ uint32_t Board_GetTick(void)
}

whal_Timeout g_whalTimeout = {
.timeoutTicks = 5, /* 5ms timeout */
.timeoutTicks = 1000, /* 1s timeout */
.GetTick = Board_GetTick,
};

Expand All @@ -50,26 +51,22 @@ whal_Clock g_whalClock = {

static const whal_Stm32wbRcc_Clk g_flashClock = {WHAL_STM32WB55_FLASH_CLOCK};

static const whal_Stm32wbRcc_Clk g_peripheralClocks[] = {
static const whal_Stm32wbRcc_Clk g_clocks[] = {
{WHAL_STM32WB55_GPIOA_CLOCK},
{WHAL_STM32WB55_GPIOB_CLOCK},
{WHAL_STM32WB55_UART1_CLOCK},
{WHAL_STM32WB55_SPI1_CLOCK},
{WHAL_STM32WB55_RNG_CLOCK},
{WHAL_STM32WB55_AES1_CLOCK},
};
#define PERIPHERAL_CLOCK_COUNT (sizeof(g_peripheralClocks) / sizeof(g_peripheralClocks[0]))
#define CLOCK_COUNT (sizeof(g_clocks) / sizeof(g_clocks[0]))

/* GPIO */
enum {
LED_PIN,
UART_TX_PIN,
UART_RX_PIN,
};

whal_Gpio g_whalGpio = {
WHAL_STM32WB55_GPIO_DEVICE,

.cfg = &(whal_Stm32wbGpio_Cfg) {
.pinCfg = (whal_Stm32wbGpio_PinCfg[3]) {
.pinCfg = (whal_Stm32wbGpio_PinCfg[PIN_COUNT]) {
[LED_PIN] = { /* LED */
.port = WHAL_STM32WB_GPIO_PORT_B,
.pin = 5,
Expand Down Expand Up @@ -97,8 +94,53 @@ whal_Gpio g_whalGpio = {
.pull = WHAL_STM32WB_GPIO_PULL_UP,
.altFn = 7,
},
[SPI_SCK_PIN] = { /* SPI1 SCK */
.port = WHAL_STM32WB_GPIO_PORT_A,
.pin = 5,
.mode = WHAL_STM32WB_GPIO_MODE_ALTFN,
.outType = WHAL_STM32WB_GPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_NONE,
.altFn = 5,
},
[SPI_MISO_PIN] = { /* SPI1 MISO */
.port = WHAL_STM32WB_GPIO_PORT_A,
.pin = 6,
.mode = WHAL_STM32WB_GPIO_MODE_ALTFN,
.outType = WHAL_STM32WB_GPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_NONE,
.altFn = 5,
},
[SPI_MOSI_PIN] = { /* SPI1 MOSI */
.port = WHAL_STM32WB_GPIO_PORT_A,
.pin = 7,
.mode = WHAL_STM32WB_GPIO_MODE_ALTFN,
.outType = WHAL_STM32WB_GPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_NONE,
.altFn = 5,
},
[SPI_CS_PIN] = { /* SPI CS */
.port = WHAL_STM32WB_GPIO_PORT_A,
.pin = 4,
.mode = WHAL_STM32WB_GPIO_MODE_OUT,
.outType = WHAL_STM32WB_GPIO_OUTTYPE_PUSHPULL,
.speed = WHAL_STM32WB_GPIO_SPEED_FAST,
.pull = WHAL_STM32WB_GPIO_PULL_UP,
},
},
.pinCount = 3,
.pinCount = PIN_COUNT,
},
};

/* SPI */
whal_Spi g_whalSpi = {
WHAL_STM32WB55_SPI1_DEVICE,

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

Expand Down Expand Up @@ -211,9 +253,9 @@ whal_Error Board_Init(void)
return err;
}

/* Enable peripheral clocks */
for (size_t i = 0; i < PERIPHERAL_CLOCK_COUNT; i++) {
err = whal_Clock_Enable(&g_whalClock, &g_peripheralClocks[i]);
/* Enable clocks */
for (size_t i = 0; i < CLOCK_COUNT; i++) {
err = whal_Clock_Enable(&g_whalClock, &g_clocks[i]);
if (err)
return err;
}
Expand All @@ -228,11 +270,23 @@ whal_Error Board_Init(void)
return err;
}

err = whal_Spi_Init(&g_whalSpi);
if (err) {
return err;
}

err = whal_Flash_Init(&g_whalFlash);
if (err) {
return err;
}

/* Initialize peripheral block devices */
for (size_t i = 0; g_peripheralBlock[i].dev; i++) {
err = whal_Block_Init(g_peripheralBlock[i].dev);
if (err)
return err;
}

err = whal_Rng_Init(&g_whalRng);
if (err) {
return err;
Expand Down Expand Up @@ -280,11 +334,23 @@ whal_Error Board_Deinit(void)
return err;
}

/* Deinitialize peripheral block devices */
for (size_t i = 0; g_peripheralBlock[i].dev; i++) {
err = whal_Block_Deinit(g_peripheralBlock[i].dev);
if (err)
return err;
}

err = whal_Flash_Deinit(&g_whalFlash);
if (err) {
return err;
}

err = whal_Spi_Deinit(&g_whalSpi);
if (err) {
return err;
}

err = whal_Uart_Deinit(&g_whalUart);
if (err) {
return err;
Expand All @@ -295,9 +361,9 @@ whal_Error Board_Deinit(void)
return err;
}

/* Disable peripheral clocks */
for (size_t i = 0; i < PERIPHERAL_CLOCK_COUNT; i++) {
err = whal_Clock_Disable(&g_whalClock, &g_peripheralClocks[i]);
/* Disable clocks */
for (size_t i = 0; i < CLOCK_COUNT; i++) {
err = whal_Clock_Disable(&g_whalClock, &g_clocks[i]);
if (err)
return err;
}
Expand Down
19 changes: 16 additions & 3 deletions boards/stm32wb55xx_nucleo/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ extern whal_Clock g_whalClock;
extern whal_Gpio g_whalGpio;
extern whal_Timer g_whalTimer;
extern whal_Uart g_whalUart;
extern whal_Spi g_whalSpi;
extern whal_Flash g_whalFlash;
extern whal_Rng g_whalRng;
extern whal_Crypto g_whalCrypto;

extern whal_Timeout g_whalTimeout;
extern volatile uint32_t g_tick;

#define BOARD_LED_PIN 0
#define BOARD_FLASH_TEST_ADDR 0x08080000
#define BOARD_FLASH_SECTOR_SZ 0x1000
enum {
LED_PIN,
UART_TX_PIN,
UART_RX_PIN,
SPI_SCK_PIN,
SPI_MISO_PIN,
SPI_MOSI_PIN,
SPI_CS_PIN,
PIN_COUNT,
};

#define BOARD_LED_PIN 0
#define BOARD_FLASH_TEST_ADDR 0x08080000
#define BOARD_FLASH_SECTOR_SZ 0x1000

enum {
BOARD_CRYPTO_AES_ECB,
Expand Down
1 change: 1 addition & 0 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ src/gpio/gpio.c
src/uart/uart.c
src/flash/flash.c
src/spi/spi.c
src/block/block.c
src/timer/timer.c
src/rng/rng.c
src/supply/supply.c
Expand Down
Loading
Loading