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
30 changes: 15 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
branches: [main]

jobs:
sim-tests:
core-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build and run sim tests
working-directory: tests/sim
- name: Build and run core tests
working-directory: tests/core
run: make run

cross-compile:
Expand All @@ -24,18 +24,18 @@ jobs:
- name: Install ARM toolchain
run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi

- name: Build STM32WB example
working-directory: examples/stm32wb
run: make
- name: Build blinky (STM32WB)
working-directory: examples/blinky
run: make BOARD=stm32wb55xx_nucleo

- name: Build STM32WB hardware tests
working-directory: tests/stm32wb
run: make
- name: Build blinky (PIC32CZ)
working-directory: examples/blinky
run: make BOARD=pic32cz_curiosity_ultra

- name: Build PIC32CZ example
working-directory: examples/pic32cz
run: make
- name: Build tests (STM32WB)
working-directory: tests
run: make BOARD=stm32wb55xx_nucleo

- name: Build PIC32CZ hardware tests
working-directory: tests/pic32cz
run: make
- name: Build tests (PIC32CZ)
working-directory: tests
run: make BOARD=pic32cz_curiosity_ultra
35 changes: 35 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# wolfHAL Examples

## Building

From an example directory:

```
cd blinky
make BOARD=<board>
```

The output binary is placed in `build/<board>/`.

## Example Structure

Each example is self-contained with its own board support:

```
<example>/
main.c
Makefile
boards/
<board>/
board.c # Device instances and Board_Init
board.h # Externs and board constants
Makefile.inc
linker.ld
... # Additional board-specific source files
```

## Adding a New Board

1. Create `boards/<board_name>/` with `board.c`, `board.h`, `Makefile.inc`, `linker.ld`, and any additional board-specific source files.
2. Define the device instances and `Board_Init` needed by the example in `board.c`.
3. Build with `make BOARD=<board_name>`.
37 changes: 37 additions & 0 deletions examples/blinky/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
WHAL_DIR = $(CURDIR)/../..

BOARD ?= stm32wb55xx_nucleo
BOARD_DIR = boards/$(BOARD)
BUILD_DIR = build/$(BOARD)

INCLUDE = -I$(WHAL_DIR) -I$(BOARD_DIR)

include $(BOARD_DIR)/Makefile.inc

SOURCE = main.c
SOURCE += $(BOARD_SOURCE)

OBJECTS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(SOURCE))
DEPENDS = $(OBJECTS:.o=.d)

LINKER_SCRIPT = $(BOARD_DIR)/linker.ld

all: $(BUILD_DIR)/$(notdir $(CURDIR)).bin

$(BUILD_DIR)/%.o: %.c Makefile
@mkdir -p $(dir $@)
$(GCC) $(CFLAGS) -c -o $@ $<

.SECONDARY:
$(BUILD_DIR)/%.elf: $(OBJECTS) $(LINKER_SCRIPT)
@mkdir -p $(dir $@)
$(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ $(OBJECTS)

$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf
$(OBJCOPY) $^ -O binary $@

.PHONY: clean
clean:
rm -rf build

-include $(DEPENDS)
22 changes: 22 additions & 0 deletions examples/blinky/boards/pic32cz_curiosity_ultra/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PLATFORM = pic32cz

GCC = $(GCC_PATH)arm-none-eabi-gcc
LD = $(GCC_PATH)arm-none-eabi-ld
OBJCOPY = $(GCC_PATH)arm-none-eabi-objcopy

CFLAGS += -Wall -Werror $(INCLUDE) -g3 \
-ffreestanding -nostdlib -mcpu=cortex-m7 \
-MMD -MP
LDFLAGS = --omagic -static

BOARD_SOURCE = $(BOARD_DIR)/ivt.c
BOARD_SOURCE += $(BOARD_DIR)/board.c
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/gpio.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/clock.c)
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/*/pic32cz_*.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/systick.c)
Original file line number Diff line number Diff line change
@@ -1,10 +1,124 @@
#include <wolfHAL/wolfHAL.h>
#include <stdint.h>
#include <stddef.h>
#include "board.h"
#include <wolfHAL/platform/microchip/pic32cz.h>

whal_Supply g_whalSupply = {
/* Forward declarations for static device instances */
static whal_Supply g_whalSupply;

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

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

void Board_WaitMs(size_t ms)
{
size_t startCount = g_tick;
g_waiting = 1;
while (1) {
size_t currentCount = g_tick;
if (g_tickOverflow) {
if ((SIZE_MAX - startCount) + currentCount > ms) {
break;
}
} else if (currentCount - startCount > ms) {
break;
}
}

g_waiting = 0;
g_tickOverflow = 0;
}

whal_Error Board_Init(void)
{
whal_Error err;

err = whal_Supply_Init(&g_whalSupply);
if (err) {
return err;
}

err = whal_Clock_Init(&g_whalClock);
if (err) {
return err;
}

err = whal_Gpio_Init(&g_whalGpio);
if (err) {
return err;
}

err = whal_Uart_Init(&g_whalUart);
if (err) {
return err;
}

err = whal_Timer_Init(&g_whalTimer);
if (err) {
return err;
}

err = whal_Timer_Start(&g_whalTimer);
if (err) {
return err;
}

return WHAL_SUCCESS;
}

whal_Error Board_Deinit(void)
{
whal_Error err;

err = whal_Timer_Stop(&g_whalTimer);
if (err) {
return err;
}

err = whal_Timer_Deinit(&g_whalTimer);
if (err) {
return err;
}

err = whal_Uart_Deinit(&g_whalUart);
if (err) {
return err;
}

err = whal_Gpio_Deinit(&g_whalGpio);
if (err) {
return err;
}

err = whal_Clock_Deinit(&g_whalClock);
if (err) {
return err;
}

err = whal_Supply_Deinit(&g_whalSupply);
if (err) {
return err;
}

return WHAL_SUCCESS;
}

/* Supply */
static whal_Supply g_whalSupply = {
WHAL_PIC32CZ_SUPPLY_DEVICE,
};

/* Clock */
whal_Clock g_whalClock = {
WHAL_PIC32CZ_CLOCK_PLL_DEVICE,

Expand Down Expand Up @@ -42,9 +156,10 @@ whal_Clock g_whalClock = {
},
};

/* GPIO */
whal_Gpio g_whalGpio = {
WHAL_PIC32CZ_GPIO_DEVICE,

.cfg = &(whal_Pic32czGpio_Cfg) {
.pinCfgCount = 3,
.pinCfg = (whal_Pic32czGpio_PinCfg[]) {
Expand All @@ -70,6 +185,7 @@ whal_Gpio g_whalGpio = {
},
};

/* UART */
static whal_Pic32czClock_Clk uartClk = {
.gclkPeriphChannel = 25, /* SERCOM 4 */
.gclkPeriphSrc = 0, /* GEN 0 */
Expand All @@ -90,6 +206,7 @@ whal_Uart g_whalUart = {
},
};

/* Timer */
whal_Timer g_whalTimer = {
WHAL_CORTEX_M7_SYSTICK_DEVICE,

Expand All @@ -99,7 +216,3 @@ whal_Timer g_whalTimer = {
.tickInt = WHAL_SYSTICK_TICKINT_ENABLED,
},
};

whal_Flash g_whalFlash = {
WHAL_PIC32CZ_FLASH_DEVICE,
};
18 changes: 18 additions & 0 deletions examples/blinky/boards/pic32cz_curiosity_ultra/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef BOARD_H
#define BOARD_H

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

extern whal_Clock g_whalClock;
extern whal_Gpio g_whalGpio;
extern whal_Timer g_whalTimer;
extern whal_Uart g_whalUart;

#define BOARD_LED_PIN 0

whal_Error Board_Init(void);
whal_Error Board_Deinit(void);
void Board_WaitMs(size_t ms);

#endif /* BOARD_H */
File renamed without changes.
56 changes: 56 additions & 0 deletions examples/blinky/boards/pic32cz_curiosity_ultra/jlink/target.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<target version="1.0">
<architecture>arm</architecture>
<feature name="org.gnu.gdb.arm.m-profile">
<reg name="r0" bitsize="32" type="uint32"/>
<reg name="r1" bitsize="32" type="uint32"/>
<reg name="r2" bitsize="32" type="uint32"/>
<reg name="r3" bitsize="32" type="uint32"/>
<reg name="r4" bitsize="32" type="uint32"/>
<reg name="r5" bitsize="32" type="uint32"/>
<reg name="r6" bitsize="32" type="uint32"/>
<reg name="r7" bitsize="32" type="uint32"/>
<reg name="r8" bitsize="32" type="uint32"/>
<reg name="r9" bitsize="32" type="uint32"/>
<reg name="r10" bitsize="32" type="uint32"/>
<reg name="r11" bitsize="32" type="uint32"/>
<reg name="r12" bitsize="32" type="uint32"/>
<reg name="sp" bitsize="32" type="data_ptr"/>
<reg name="lr" bitsize="32"/>
<reg name="pc" bitsize="32" type="code_ptr"/>
<reg name="xpsr" bitsize="32" regnum="25"/>
</feature>
<feature name="org.gnu.gdb.arm.m-system">
<reg name="msp" bitsize="32" type="data_ptr"/>
<reg name="psp" bitsize="32" type="data_ptr"/>
<reg name="primask" bitsize="32" type="uint32"/>
<reg name="basepri" bitsize="32" type="uint32"/>
<reg name="faultmask" bitsize="32" type="uint32"/>
<reg name="control" bitsize="32" type="uint32"/>
<reg name="apsr" bitsize="32" type="uint32"/>
<reg name="epsr" bitsize="32" type="uint32"/>
<reg name="ipsr" bitsize="32" type="uint32"/>
<reg name="iapsr" bitsize="32" type="uint32"/>
<reg name="eapsr" bitsize="32" type="uint32"/>
<reg name="iepsr" bitsize="32" type="uint32"/>
</feature>
<feature name="org.gnu.gdb.arm.vfp">
<reg name="d0" bitsize="64" type="ieee_double"/>
<reg name="d1" bitsize="64" type="ieee_double"/>
<reg name="d2" bitsize="64" type="ieee_double"/>
<reg name="d3" bitsize="64" type="ieee_double"/>
<reg name="d4" bitsize="64" type="ieee_double"/>
<reg name="d5" bitsize="64" type="ieee_double"/>
<reg name="d6" bitsize="64" type="ieee_double"/>
<reg name="d7" bitsize="64" type="ieee_double"/>
<reg name="d8" bitsize="64" type="ieee_double"/>
<reg name="d9" bitsize="64" type="ieee_double"/>
<reg name="d10" bitsize="64" type="ieee_double"/>
<reg name="d11" bitsize="64" type="ieee_double"/>
<reg name="d12" bitsize="64" type="ieee_double"/>
<reg name="d13" bitsize="64" type="ieee_double"/>
<reg name="d14" bitsize="64" type="ieee_double"/>
<reg name="d15" bitsize="64" type="ieee_double"/>
<reg name="fpscr" bitsize="32" type="int" group="float"/>
</feature>
</target>
15 changes: 15 additions & 0 deletions examples/blinky/boards/stm32wb55xx_nucleo/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PLATFORM = stm32wb

GCC = $(GCC_PATH)arm-none-eabi-gcc
LD = $(GCC_PATH)arm-none-eabi-ld
OBJCOPY = $(GCC_PATH)arm-none-eabi-objcopy

CFLAGS += -Wall -Werror $(INCLUDE) -g3 \
-ffreestanding -nostdlib -mcpu=cortex-m4 \
-MMD -MP
LDFLAGS = --omagic -static

BOARD_SOURCE = $(BOARD_DIR)/ivt.c
BOARD_SOURCE += $(BOARD_DIR)/board.c
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*.c)
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/*.c)
Loading