-
Notifications
You must be signed in to change notification settings - Fork 139
[RFC] Integrate wolfHAL #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexLanzano
wants to merge
5
commits into
wolfSSL:master
Choose a base branch
from
AlexLanzano:wolfHAL-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e80589
Integrate wolfHAL
AlexLanzano 55979c2
Move wolfHAL board config and build file to hal/. Optimize wolfHAL bu…
AlexLanzano 9ede286
Update wolfHAL driver name. Add option to not compile in wolfhal gpio
AlexLanzano 54cdcf8
Add build test
AlexLanzano 10c437f
Address comments
AlexLanzano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| TARGET=wolfhal | ||
| SIGN=ECC256 | ||
| HASH=SHA256 | ||
| WOLFBOOT_SECTOR_SIZE=0x1000 | ||
| WOLFBOOT_PARTITION_SIZE=0x20000 | ||
| WOLFBOOT_PARTITION_BOOT_ADDRESS=0x08010000 | ||
| WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x08028000 | ||
| WOLFBOOT_PARTITION_SWAP_ADDRESS=0x08048000 | ||
| NVM_FLASH_WRITEONCE=1 | ||
| PKA=0 | ||
| WOLFHAL_TARGET=stm32wb | ||
| WOLFHAL_BOARD=stm32wb55_nucleo | ||
| WOLFHAL_FLASH_START=0x08000000 | ||
| WOLFHAL_FLASH_SIZE=0x100000 | ||
| WOLFHAL_NO_GPIO=1 | ||
dgarske marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* uart_drv_wolfhal.c | ||
| * | ||
| * A generic UART driver using the wolfHAL API module. | ||
| * | ||
| * Copyright (C) 2025 wolfSSL Inc. | ||
| * | ||
| * This file is part of wolfBoot. | ||
| * | ||
| * wolfBoot is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * wolfBoot is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA | ||
| */ | ||
|
|
||
| #ifdef TARGET_wolfhal | ||
|
|
||
| #include <stdint.h> | ||
| #include <wolfHAL/wolfHAL.h> | ||
|
|
||
| extern whal_Uart g_whalUart; | ||
|
|
||
| int uart_tx(const uint8_t c) | ||
| { | ||
| whal_Error err; | ||
| err = whal_Uart_Send(&g_whalUart, &c, 1); | ||
| if (err) { | ||
| return err; | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| int uart_rx(uint8_t *c) | ||
| { | ||
| whal_Error err; | ||
| err = whal_Uart_Recv(&g_whalUart, c, 1); | ||
| if (err) { | ||
| return err; | ||
| } | ||
| return 1; | ||
| } | ||
|
|
||
| int uart_init(uint32_t bitrate, uint8_t data, char parity, uint8_t stop) | ||
| { | ||
| /* Handle these configure options in the wolfHAL UART config */ | ||
| (void)bitrate; | ||
| (void)data; | ||
| (void)parity; | ||
| (void)stop; | ||
|
|
||
| whal_Error err; | ||
| err = whal_Uart_Init(&g_whalUart); | ||
| if (err) { | ||
| return err; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| #ifdef DEBUG_UART | ||
| void uart_write(const char *buf, unsigned int len) | ||
| { | ||
| whal_Uart_Send(&g_whalUart, (uint8_t *)buf, len); | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* TARGET_wolfhal */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #include <wolfHAL/platform/st/stm32wb55xx.h> | ||
|
|
||
| /* | ||
| * STM32WB55 Nucleo board configuration for wolfHAL. | ||
| * | ||
| * This file wires up the board-level clock, flash, GPIO, and optional UART | ||
| * instances used by wolfBoot. Most values are board defaults; override with | ||
| * build-time defines (e.g., DEBUG_UART/UART_FLASH) as needed. | ||
| */ | ||
|
|
||
| whal_Clock g_whalClock; | ||
| whal_Flash g_whalFlash; | ||
|
|
||
| /* Core clock controller (MSI -> PLL -> SYSCLK at 64 MHz). */ | ||
| whal_Clock g_whalClock = { | ||
| WHAL_STM32WB55_RCC_PLL_DEVICE, | ||
|
|
||
| .cfg = &(whal_Stm32wbRcc_Cfg) { | ||
| .flash = &g_whalFlash, | ||
| .flashLatency = WHAL_STM32WB_FLASH_LATENCY_3, | ||
|
|
||
| .sysClkSrc = WHAL_STM32WB_RCC_SYSCLK_SRC_PLL, | ||
| .sysClkCfg = &(whal_Stm32wbRcc_PllClkCfg) | ||
| { | ||
| .clkSrc = WHAL_STM32WB_RCC_PLLCLK_SRC_MSI, | ||
| /* 64 MHz */ | ||
| .n = 32, | ||
| .m = 0, | ||
| .r = 1, | ||
| .q = 0, | ||
| .p = 0, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| /* Internal flash mapping used by wolfBoot. */ | ||
| whal_Flash g_whalFlash = { | ||
| WHAL_STM32WB55_FLASH_DEVICE, | ||
|
|
||
| .cfg = &(whal_Stm32wbFlash_Cfg) { | ||
| .clkCtrl = &g_whalClock, | ||
| .clk = &(whal_Stm32wbRcc_Clk){WHAL_STM32WB55_FLASH_CLOCK}, | ||
|
|
||
| .startAddr = 0x08000000, | ||
| .size = 0x100000, | ||
| }, | ||
| }; | ||
|
|
||
| #ifndef WOLFHAL_NO_GPIO | ||
| /* GPIO pin configuration: LED on PB5 and optional UART1 pins. */ | ||
| whal_Stm32wbGpio_PinCfg g_whalPinCfg[] = { | ||
| { /* LED */ | ||
| .port = WHAL_STM32WB_GPIO_PORT_B, | ||
| .pin = 5, | ||
| .mode = WHAL_STM32WB_GPIO_MODE_OUT, | ||
| .outType = WHAL_STM32WB_GPIO_OUTTYPE_PUSHPULL, | ||
| .speed = WHAL_STM32WB_GPIO_SPEED_LOW, | ||
| .pull = WHAL_STM32WB_GPIO_PULL_UP, | ||
| .altFn = 0, | ||
| }, | ||
| #if defined(DEBUG_UART) || defined(UART_FLASH) | ||
| { /* UART1 TX */ | ||
| .port = WHAL_STM32WB_GPIO_PORT_B, | ||
| .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_UP, | ||
| .altFn = 7, | ||
| }, | ||
| { /* UART1 RX */ | ||
| .port = WHAL_STM32WB_GPIO_PORT_B, | ||
| .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_UP, | ||
| .altFn = 7, | ||
| }, | ||
| #endif /* DEBUG_UART || UART_FLASH */ | ||
| }; | ||
|
|
||
| /* GPIO controller for configured pins. */ | ||
| whal_Gpio g_whalGpio = { | ||
| WHAL_STM32WB55_GPIO_DEVICE, | ||
|
|
||
| .cfg = &(whal_Stm32wbGpio_Cfg) { | ||
| .clkCtrl = &g_whalClock, | ||
| .clk = &(whal_Stm32wbRcc_Clk) {WHAL_STM32WB55_GPIOB_CLOCK}, | ||
|
|
||
| .pinCfg = g_whalPinCfg, | ||
| .pinCount = sizeof(g_whalPinCfg) / sizeof(whal_Stm32wbGpio_PinCfg), | ||
| }, | ||
| }; | ||
| #endif | ||
|
|
||
| #if defined(DEBUG_UART) || defined(UART_FLASH) | ||
| /* UART1 configuration for debug/flash operations. */ | ||
| whal_Uart g_whalUart = { | ||
| WHAL_STM32WB55_UART1_DEVICE, | ||
|
|
||
| .cfg = &(whal_Stm32wbUart_Cfg){ | ||
| .clkCtrl = &g_whalClock, | ||
| .clk = &(whal_Stm32wbRcc_Clk) {WHAL_STM32WB55_UART1_CLOCK}, | ||
|
|
||
| .baud = 115200, | ||
| }, | ||
| }; | ||
| #endif /* DEBUG_UART || UART_FLASH */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| CFLAGS += -DWHAL_CFG_NO_CALLBACKS=1 | ||
|
|
||
| OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/reg.o | ||
|
|
||
| OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/stm32wb_rcc.o \ | ||
| $(WOLFBOOT_LIB_WOLFHAL)/src/flash/stm32wb_flash.o | ||
|
|
||
| APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/reg.o | ||
|
|
||
| APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/clock/stm32wb_rcc.o \ | ||
| $(WOLFBOOT_LIB_WOLFHAL)/src/flash/stm32wb_flash.o | ||
|
|
||
| ifeq ($(WOLFHAL_NO_GPIO),) | ||
| OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/gpio/stm32wb_gpio.o | ||
| APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/gpio/stm32wb_gpio.o | ||
| endif | ||
|
|
||
| ifeq ($(DEBUG_UART),1) | ||
| OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/uart/stm32wb_uart.o | ||
| APP_OBJS += $(WOLFBOOT_LIB_WOLFHAL)/src/uart/stm32wb_uart.o | ||
| endif |
dgarske marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* stm32wb.c | ||
| * | ||
| * Copyright (C) 2025 wolfSSL Inc. | ||
| * | ||
| * This file is part of wolfBoot. | ||
| * | ||
| * wolfBoot is free software; you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation; either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * wolfBoot is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
| #include <wolfHAL/wolfHAL.h> | ||
| #include "image.h" | ||
|
|
||
| extern whal_Clock g_whalClock; | ||
| #ifndef WOLFHAL_NO_GPIO | ||
| extern whal_Gpio g_whalGpio; | ||
| #endif | ||
| extern whal_Flash g_whalFlash; | ||
| #if defined(DEBUG_UART) || defined(UART_FLASH) | ||
| extern whal_Uart g_whalUart; | ||
| #endif /* DEBUG_UART || UART_FLASH */ | ||
|
|
||
| void hal_init(void) | ||
| { | ||
| whal_Error err; | ||
|
|
||
| err = whal_Clock_Init(&g_whalClock); | ||
| if (err) { | ||
| return; | ||
| } | ||
|
|
||
| #ifndef WOLFHAL_NO_GPIO | ||
| err = whal_Gpio_Init(&g_whalGpio); | ||
| if (err) { | ||
| return; | ||
| } | ||
| #endif | ||
|
|
||
| err = whal_Flash_Init(&g_whalFlash); | ||
| if (err) { | ||
| return; | ||
| } | ||
|
|
||
| #if defined(DEBUG_UART) || defined(UART_FLASH) | ||
| err = whal_Uart_Init(&g_whalUart); | ||
| if (err) { | ||
| return; | ||
| } | ||
| #endif /* DEBUG_UART || UART_FLASH */ | ||
|
|
||
| } | ||
|
|
||
| void hal_prepare_boot(void) | ||
| { | ||
| #if defined(DEBUG_UART) || defined(UART_FLASH) | ||
| whal_Uart_Deinit(&g_whalUart); | ||
| #endif /* DEBUG_UART || UART_FLASH */ | ||
|
|
||
| whal_Flash_Deinit(&g_whalFlash); | ||
|
|
||
| #ifndef WOLFHAL_NO_GPIO | ||
| whal_Gpio_Deinit(&g_whalGpio); | ||
| #endif | ||
|
|
||
| whal_Clock_Deinit(&g_whalClock); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that WOLFHAL configuration must lives in the same configuration of wolfBoot. I would like to have a better separation. I'm not sure how to drive the wolfBoot toolchain though, probably there is the need of some integration in arch.mk and similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are technically wolfBoot configuration options for the wolfBoot wolfHAL target. Maybe we need better naming for these?