Skip to content

Commit 84fd7ce

Browse files
committed
[examples, tests] Refactor examples and tests directory
1 parent eb73b08 commit 84fd7ce

59 files changed

Lines changed: 2207 additions & 1228 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ on:
77
branches: [main]
88

99
jobs:
10-
sim-tests:
10+
core-tests:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
1414

15-
- name: Build and run sim tests
16-
working-directory: tests/sim
15+
- name: Build and run core tests
16+
working-directory: tests/core
1717
run: make run
1818

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

27-
- name: Build STM32WB example
28-
working-directory: examples/stm32wb
29-
run: make
27+
- name: Build blinky (STM32WB)
28+
working-directory: examples/blinky
29+
run: make BOARD=stm32wb55xx_nucleo
3030

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

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

39-
- name: Build PIC32CZ hardware tests
40-
working-directory: tests/pic32cz
41-
run: make
39+
- name: Build tests (PIC32CZ)
40+
working-directory: tests
41+
run: make BOARD=pic32cz_curiosity_ultra

examples/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# wolfHAL Examples
2+
3+
## Building
4+
5+
From an example directory:
6+
7+
```
8+
cd blinky
9+
make BOARD=<board>
10+
```
11+
12+
The output binary is placed in `build/<board>/`.
13+
14+
## Example Structure
15+
16+
Each example is self-contained with its own board support:
17+
18+
```
19+
<example>/
20+
main.c
21+
Makefile
22+
boards/
23+
<board>/
24+
board.c # Device instances and Board_Init
25+
board.h # Externs and board constants
26+
Makefile.inc
27+
linker.ld
28+
... # Additional board-specific source files
29+
```
30+
31+
## Adding a New Board
32+
33+
1. Create `boards/<board_name>/` with `board.c`, `board.h`, `Makefile.inc`, `linker.ld`, and any additional board-specific source files.
34+
2. Define the device instances and `Board_Init` needed by the example in `board.c`.
35+
3. Build with `make BOARD=<board_name>`.

examples/blinky/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
WHAL_DIR = $(CURDIR)/../..
2+
3+
BOARD ?= stm32wb55xx_nucleo
4+
BOARD_DIR = boards/$(BOARD)
5+
BUILD_DIR = build/$(BOARD)
6+
7+
INCLUDE = -I$(WHAL_DIR) -I$(BOARD_DIR)
8+
9+
include $(BOARD_DIR)/Makefile.inc
10+
11+
SOURCE = main.c
12+
SOURCE += $(BOARD_SOURCE)
13+
14+
OBJECTS = $(patsubst %.c,$(BUILD_DIR)/%.o,$(SOURCE))
15+
DEPENDS = $(OBJECTS:.o=.d)
16+
17+
LINKER_SCRIPT = $(BOARD_DIR)/linker.ld
18+
19+
all: $(BUILD_DIR)/$(notdir $(CURDIR)).bin
20+
21+
$(BUILD_DIR)/%.o: %.c Makefile
22+
@mkdir -p $(dir $@)
23+
$(GCC) $(CFLAGS) -c -o $@ $<
24+
25+
.SECONDARY:
26+
$(BUILD_DIR)/%.elf: $(OBJECTS) $(LINKER_SCRIPT)
27+
@mkdir -p $(dir $@)
28+
$(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ $(OBJECTS)
29+
30+
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf
31+
$(OBJCOPY) $^ -O binary $@
32+
33+
.PHONY: clean
34+
clean:
35+
rm -rf build
36+
37+
-include $(DEPENDS)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PLATFORM = pic32cz
2+
3+
GCC = $(GCC_PATH)arm-none-eabi-gcc
4+
LD = $(GCC_PATH)arm-none-eabi-ld
5+
OBJCOPY = $(GCC_PATH)arm-none-eabi-objcopy
6+
7+
CFLAGS += -Wall -Werror $(INCLUDE) -g3 \
8+
-ffreestanding -nostdlib -mcpu=cortex-m7 \
9+
-MMD -MP
10+
LDFLAGS = --omagic -static
11+
12+
BOARD_SOURCE = $(BOARD_DIR)/ivt.c
13+
BOARD_SOURCE += $(BOARD_DIR)/board.c
14+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*.c)
15+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/gpio.c)
16+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/clock.c)
17+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/uart.c)
18+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/timer.c)
19+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/supply.c)
20+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/flash.c)
21+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/pic32cz_*.c)
22+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/systick.c)

examples/pic32cz/pic32cz_curiosity_ultra.c renamed to examples/blinky/boards/pic32cz_curiosity_ultra/board.c

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,124 @@
1-
#include <wolfHAL/wolfHAL.h>
1+
#include <stdint.h>
2+
#include <stddef.h>
3+
#include "board.h"
24
#include <wolfHAL/platform/microchip/pic32cz.h>
35

4-
whal_Supply g_whalSupply = {
6+
/* Forward declarations for static device instances */
7+
static whal_Supply g_whalSupply;
8+
9+
/* SysTick timing */
10+
volatile size_t g_tick = 0;
11+
volatile uint8_t g_waiting = 0;
12+
volatile uint8_t g_tickOverflow = 0;
13+
14+
void SysTick_Handler()
15+
{
16+
size_t tickBefore = g_tick++;
17+
if (g_waiting) {
18+
if (tickBefore > g_tick)
19+
g_tickOverflow = 1;
20+
}
21+
}
22+
23+
void Board_WaitMs(size_t ms)
24+
{
25+
size_t startCount = g_tick;
26+
g_waiting = 1;
27+
while (1) {
28+
size_t currentCount = g_tick;
29+
if (g_tickOverflow) {
30+
if ((SIZE_MAX - startCount) + currentCount > ms) {
31+
break;
32+
}
33+
} else if (currentCount - startCount > ms) {
34+
break;
35+
}
36+
}
37+
38+
g_waiting = 0;
39+
g_tickOverflow = 0;
40+
}
41+
42+
whal_Error Board_Init(void)
43+
{
44+
whal_Error err;
45+
46+
err = whal_Supply_Init(&g_whalSupply);
47+
if (err) {
48+
return err;
49+
}
50+
51+
err = whal_Clock_Init(&g_whalClock);
52+
if (err) {
53+
return err;
54+
}
55+
56+
err = whal_Gpio_Init(&g_whalGpio);
57+
if (err) {
58+
return err;
59+
}
60+
61+
err = whal_Uart_Init(&g_whalUart);
62+
if (err) {
63+
return err;
64+
}
65+
66+
err = whal_Timer_Init(&g_whalTimer);
67+
if (err) {
68+
return err;
69+
}
70+
71+
err = whal_Timer_Start(&g_whalTimer);
72+
if (err) {
73+
return err;
74+
}
75+
76+
return WHAL_SUCCESS;
77+
}
78+
79+
whal_Error Board_Deinit(void)
80+
{
81+
whal_Error err;
82+
83+
err = whal_Timer_Stop(&g_whalTimer);
84+
if (err) {
85+
return err;
86+
}
87+
88+
err = whal_Timer_Deinit(&g_whalTimer);
89+
if (err) {
90+
return err;
91+
}
92+
93+
err = whal_Uart_Deinit(&g_whalUart);
94+
if (err) {
95+
return err;
96+
}
97+
98+
err = whal_Gpio_Deinit(&g_whalGpio);
99+
if (err) {
100+
return err;
101+
}
102+
103+
err = whal_Clock_Deinit(&g_whalClock);
104+
if (err) {
105+
return err;
106+
}
107+
108+
err = whal_Supply_Deinit(&g_whalSupply);
109+
if (err) {
110+
return err;
111+
}
112+
113+
return WHAL_SUCCESS;
114+
}
115+
116+
/* Supply */
117+
static whal_Supply g_whalSupply = {
5118
WHAL_PIC32CZ_SUPPLY_DEVICE,
6119
};
7120

121+
/* Clock */
8122
whal_Clock g_whalClock = {
9123
WHAL_PIC32CZ_CLOCK_PLL_DEVICE,
10124

@@ -42,9 +156,10 @@ whal_Clock g_whalClock = {
42156
},
43157
};
44158

159+
/* GPIO */
45160
whal_Gpio g_whalGpio = {
46161
WHAL_PIC32CZ_GPIO_DEVICE,
47-
162+
48163
.cfg = &(whal_Pic32czGpio_Cfg) {
49164
.pinCfgCount = 3,
50165
.pinCfg = (whal_Pic32czGpio_PinCfg[]) {
@@ -70,6 +185,7 @@ whal_Gpio g_whalGpio = {
70185
},
71186
};
72187

188+
/* UART */
73189
static whal_Pic32czClock_Clk uartClk = {
74190
.gclkPeriphChannel = 25, /* SERCOM 4 */
75191
.gclkPeriphSrc = 0, /* GEN 0 */
@@ -90,6 +206,7 @@ whal_Uart g_whalUart = {
90206
},
91207
};
92208

209+
/* Timer */
93210
whal_Timer g_whalTimer = {
94211
WHAL_CORTEX_M7_SYSTICK_DEVICE,
95212

@@ -99,7 +216,3 @@ whal_Timer g_whalTimer = {
99216
.tickInt = WHAL_SYSTICK_TICKINT_ENABLED,
100217
},
101218
};
102-
103-
whal_Flash g_whalFlash = {
104-
WHAL_PIC32CZ_FLASH_DEVICE,
105-
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef BOARD_H
2+
#define BOARD_H
3+
4+
#include <stddef.h>
5+
#include <wolfHAL/wolfHAL.h>
6+
7+
extern whal_Clock g_whalClock;
8+
extern whal_Gpio g_whalGpio;
9+
extern whal_Timer g_whalTimer;
10+
extern whal_Uart g_whalUart;
11+
12+
#define BOARD_LED_PIN 0
13+
14+
whal_Error Board_Init(void);
15+
whal_Error Board_Deinit(void);
16+
void Board_WaitMs(size_t ms);
17+
18+
#endif /* BOARD_H */

examples/pic32cz/ivt.c renamed to examples/blinky/boards/pic32cz_curiosity_ultra/ivt.c

File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<target version="1.0">
3+
<architecture>arm</architecture>
4+
<feature name="org.gnu.gdb.arm.m-profile">
5+
<reg name="r0" bitsize="32" type="uint32"/>
6+
<reg name="r1" bitsize="32" type="uint32"/>
7+
<reg name="r2" bitsize="32" type="uint32"/>
8+
<reg name="r3" bitsize="32" type="uint32"/>
9+
<reg name="r4" bitsize="32" type="uint32"/>
10+
<reg name="r5" bitsize="32" type="uint32"/>
11+
<reg name="r6" bitsize="32" type="uint32"/>
12+
<reg name="r7" bitsize="32" type="uint32"/>
13+
<reg name="r8" bitsize="32" type="uint32"/>
14+
<reg name="r9" bitsize="32" type="uint32"/>
15+
<reg name="r10" bitsize="32" type="uint32"/>
16+
<reg name="r11" bitsize="32" type="uint32"/>
17+
<reg name="r12" bitsize="32" type="uint32"/>
18+
<reg name="sp" bitsize="32" type="data_ptr"/>
19+
<reg name="lr" bitsize="32"/>
20+
<reg name="pc" bitsize="32" type="code_ptr"/>
21+
<reg name="xpsr" bitsize="32" regnum="25"/>
22+
</feature>
23+
<feature name="org.gnu.gdb.arm.m-system">
24+
<reg name="msp" bitsize="32" type="data_ptr"/>
25+
<reg name="psp" bitsize="32" type="data_ptr"/>
26+
<reg name="primask" bitsize="32" type="uint32"/>
27+
<reg name="basepri" bitsize="32" type="uint32"/>
28+
<reg name="faultmask" bitsize="32" type="uint32"/>
29+
<reg name="control" bitsize="32" type="uint32"/>
30+
<reg name="apsr" bitsize="32" type="uint32"/>
31+
<reg name="epsr" bitsize="32" type="uint32"/>
32+
<reg name="ipsr" bitsize="32" type="uint32"/>
33+
<reg name="iapsr" bitsize="32" type="uint32"/>
34+
<reg name="eapsr" bitsize="32" type="uint32"/>
35+
<reg name="iepsr" bitsize="32" type="uint32"/>
36+
</feature>
37+
<feature name="org.gnu.gdb.arm.vfp">
38+
<reg name="d0" bitsize="64" type="ieee_double"/>
39+
<reg name="d1" bitsize="64" type="ieee_double"/>
40+
<reg name="d2" bitsize="64" type="ieee_double"/>
41+
<reg name="d3" bitsize="64" type="ieee_double"/>
42+
<reg name="d4" bitsize="64" type="ieee_double"/>
43+
<reg name="d5" bitsize="64" type="ieee_double"/>
44+
<reg name="d6" bitsize="64" type="ieee_double"/>
45+
<reg name="d7" bitsize="64" type="ieee_double"/>
46+
<reg name="d8" bitsize="64" type="ieee_double"/>
47+
<reg name="d9" bitsize="64" type="ieee_double"/>
48+
<reg name="d10" bitsize="64" type="ieee_double"/>
49+
<reg name="d11" bitsize="64" type="ieee_double"/>
50+
<reg name="d12" bitsize="64" type="ieee_double"/>
51+
<reg name="d13" bitsize="64" type="ieee_double"/>
52+
<reg name="d14" bitsize="64" type="ieee_double"/>
53+
<reg name="d15" bitsize="64" type="ieee_double"/>
54+
<reg name="fpscr" bitsize="32" type="int" group="float"/>
55+
</feature>
56+
</target>

examples/pic32cz/linker.ld renamed to examples/blinky/boards/pic32cz_curiosity_ultra/linker.ld

File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
PLATFORM = stm32wb
2+
3+
GCC = $(GCC_PATH)arm-none-eabi-gcc
4+
LD = $(GCC_PATH)arm-none-eabi-ld
5+
OBJCOPY = $(GCC_PATH)arm-none-eabi-objcopy
6+
7+
CFLAGS += -Wall -Werror $(INCLUDE) -g3 \
8+
-ffreestanding -nostdlib -mcpu=cortex-m4 \
9+
-MMD -MP
10+
LDFLAGS = --omagic -static
11+
12+
BOARD_SOURCE = $(BOARD_DIR)/ivt.c
13+
BOARD_SOURCE += $(BOARD_DIR)/board.c
14+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*.c)
15+
BOARD_SOURCE += $(wildcard $(WHAL_DIR)/src/*/*.c)

0 commit comments

Comments
 (0)