|
| 1 | +/* stm32wb.c |
| 2 | + * |
| 3 | + * Copyright (C) 2025 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfBoot. |
| 6 | + * |
| 7 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfBoot is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | + |
| 22 | +#include <stdint.h> |
| 23 | +#include <wolfHAL/wolfHAL.h> |
| 24 | +#include "image.h" |
| 25 | + |
| 26 | +extern whal_Clock wbClock; |
| 27 | +extern whal_Gpio wbGpio; |
| 28 | +extern whal_Uart wbUart; |
| 29 | +extern whal_Flash wbFlash; |
| 30 | + |
| 31 | +#ifdef WOLFHAL_INIT_HOOKS |
| 32 | +extern void hal_pre_init(); |
| 33 | +extern void hal_post_prepare_boot(); |
| 34 | +#endif /* WOLFHAL_INIT_HOOKS */ |
| 35 | + |
| 36 | +void RAMFUNCTION hal_flash_unlock(void) |
| 37 | +{ |
| 38 | + whal_Flash_Unlock(&wbFlash, |
| 39 | + 0, WOLFHAL_FLASH_SIZE); |
| 40 | +} |
| 41 | + |
| 42 | +void RAMFUNCTION hal_flash_lock(void) |
| 43 | +{ |
| 44 | + whal_Flash_Lock(&wbFlash, |
| 45 | + 0, WOLFHAL_FLASH_SIZE); |
| 46 | +} |
| 47 | + |
| 48 | +int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len) |
| 49 | +{ |
| 50 | + whal_Flash_Write(&wbFlash, address, data, len); |
| 51 | + return 0; |
| 52 | +} |
| 53 | + |
| 54 | +int RAMFUNCTION hal_flash_erase(uint32_t address, int len) |
| 55 | +{ |
| 56 | + if (len == 0) |
| 57 | + return -1; |
| 58 | + |
| 59 | + whal_Flash_Erase(&wbFlash, address, len); |
| 60 | + return 0; |
| 61 | +} |
| 62 | + |
| 63 | +void hal_init(void) |
| 64 | +{ |
| 65 | +#ifdef WOLFHAL_INIT_HOOKS |
| 66 | + hal_pre_init(); |
| 67 | +#endif /* WOLFHAL_INIT_HOOKS */ |
| 68 | + |
| 69 | + whal_Clock_Init(&wbClock); |
| 70 | + whal_Clock_Enable(&wbClock); |
| 71 | + |
| 72 | + whal_Gpio_Init(&wbGpio); |
| 73 | + whal_Uart_Init(&wbUart); |
| 74 | + whal_Flash_Init(&wbFlash); |
| 75 | +} |
| 76 | + |
| 77 | +void hal_prepare_boot(void) |
| 78 | +{ |
| 79 | + whal_Flash_Deinit(&wbFlash); |
| 80 | + whal_Uart_Deinit(&wbUart); |
| 81 | + whal_Gpio_Deinit(&wbGpio); |
| 82 | + |
| 83 | + whal_Clock_Disable(&wbClock); |
| 84 | + whal_Clock_Deinit(&wbClock); |
| 85 | + |
| 86 | +#ifdef WOLFHAL_INIT_HOOKS |
| 87 | + hal_post_prepare_boot(); |
| 88 | +#endif /* WOLFHAL_INIT_HOOKS */ |
| 89 | +} |
0 commit comments