Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/test-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,12 @@ jobs:
arch: arm
config-file: ./config/examples/stm32h7.config

stm32h755_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/stm32h755.config

stm32h7_qspi_test:
uses: ./.github/workflows/test-build.yml
with:
Expand Down
27 changes: 27 additions & 0 deletions config/examples/stm32h755.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARCH?=ARM
TARGET?=stm32h7
SIGN?=ECC256
HASH?=SHA256
DEBUG?=0
DEBUG_UART?=0
VTOR?=1
NO_ASM?=0
EXT_FLASH?=0
SPI_FLASH?=0
QSPI_FLASH?=0
OCTOSPI_FLASH?=0
ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=0
WOLFBOOT_VERSION?=1
V?=0
SPMATH?=1
RAM_CODE?=0
DUALBANK_SWAP?=0
WOLFBOOT_PARTITION_SIZE?=0xE0000
WOLFBOOT_SECTOR_SIZE?=0x20000
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8020000
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x8100000
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x81E0000

# NUCLEO-H755ZI-Q: core supplied by the SMPS alone (no LDO)
CFLAGS_EXTRA+=-DPWR_SUPPLY_CONFIG=PWR_CR3_SDEN -DSTM32H7_SMPS_ONLY
15 changes: 15 additions & 0 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,21 @@ make TARGET=stm32h7 SIGN=ECC256

The STM32H7 also supports using the QSPI for external flash. To enable use `QSPI_FLASH=1` in your configuration. The pins are defined in `hal/spi/spi_drv_stm32.h`. A built-in alternate pin configuration can be used with `QSPI_ALT_CONFIGURATION`. The flash and QSPI parameters are defined in `src/qspi_flash.c` and can be overridden at build time.

### STM32H7 with SMPS supply (NUCLEO-H755ZI-Q)

Use `cp ./config/examples/stm32h755.config .config`. It is the `stm32h7.config` layout plus two defines:

- `PWR_SUPPLY_CONFIG=PWR_CR3_SDEN` selects the supply written to `PWR_CR3`. The selection can be written once per power-on reset, so it is only written while the register still holds its reset value. Without the define the HAL enables the LDO, which suits boards such as the NUCLEO-H753ZI.
- `STM32H7_SMPS_ONLY` keeps the core at VOS1 and sets PLL1 for 400MHz from the 8MHz HSE bypass clock. VOS0 and 480MHz need the LDO.

On dual-core parts the HAL runs on the Cortex-M7. The Cortex-M4 boots from `0x08100000` by default, which is the update partition in this layout. Disable it or move its boot address with the option bytes:

```
STM32_Programmer_CLI -c port=swd mode=UR -ob BCM4=0
```

The test application runs the wolfCrypt test or benchmark after the version banner when built with `WOLFCRYPT_TEST=1` or `WOLFCRYPT_BENCHMARK=1`.

### STM32H7 Programming

ST-Link Flash Tools:
Expand Down
27 changes: 26 additions & 1 deletion hal/stm32h7.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,35 @@ static void clock_pll_on(int powersave)
uint32_t plln, pllm, pllq, pllp, pllr, hpre, d1cpre, d1ppre;
uint32_t d2ppre1, d2ppre2, d3ppre, flash_waitstates;

#ifdef PWR_SUPPLY_CONFIG
/* The supply selection can be written once per power-on reset */
if ((PWR_CR3 & PWR_CR3_SUPPLY_MASK) == PWR_CR3_SUPPLY_UNSET) {
PWR_CR3 = (PWR_CR3 & ~((uint32_t)PWR_CR3_SUPPLY_MASK)) |
(PWR_SUPPLY_CONFIG);
}
#else
PWR_CR3 |= PWR_CR3_LDOEN;
#endif
while ((PWR_CSR1 & PWR_CSR1_ACTVOSRDY) == 0) {};

PWR_D3CR |= (PWR_D3CR_VOS_SCALE_1 << PWR_D3CR_VOS_SHIFT);
/* Delay after setting the voltage scaling */
reg32 = PWR_D3CR;
#ifndef STM32H7_SMPS_ONLY
SYSCFG_PWRCR |= SYSCFG_PWRCR_ODEN;
/* Delay after setting the voltage scaling */
reg32 = PWR_D3CR;
#endif
while ((PWR_D3CR & PWR_D3CR_VOSRDY) == 0) {};

/* Select clock parameters (CPU Speed = 480MHz) */
/* Select clock parameters (CPU Speed = 480MHz, 400MHz if SMPS only) */
pllm = 1;
#ifdef STM32H7_SMPS_ONLY
/* VOS0 needs the LDO, which leaves VOS1 and 400MHz */
plln = 100;
#else
plln = 120;
#endif
pllp = 2;
pllq = 20;
pllr = 2;
Expand Down Expand Up @@ -491,20 +506,30 @@ static void clock_pll_on(int powersave)

/* PLL Clock source selection + DIVM1 */
reg32 = RCC_PLLCKSELR;
#ifdef STM32H7_SMPS_ONLY
reg32 &= ~((0x3F << 4) | 0x3);
#endif
reg32 |= RCC_PLLCKSELR_PLLSRC_HSE;
reg32 |= ((pllm) << 4);
RCC_PLLCKSELR = reg32;
DMB();

reg32 = RCC_PLL1DIVR;
#ifdef STM32H7_SMPS_ONLY
reg32 &= ~((0x7F << 24) | (0x7F << 16) | (0x7F << 9) | 0x1FF);
#endif
reg32 |= (plln -1);
reg32 |= ((pllp - 1) << 9);
reg32 |= ((pllq - 1) << 16);
reg32 |= ((pllr - 1) << 24);
RCC_PLL1DIVR = reg32;
DMB();

#ifdef STM32H7_SMPS_ONLY
RCC_PLLCFGR |= (RCC_PLLCFGR_PLL1RGE_8_16 << RCC_PLLCFGR_PLL1RGE_SHIFT);
#else
RCC_PLLCFGR |= (RCC_PLLCFGR_PLL1RGE_2_4 << RCC_PLLCFGR_PLL1RGE_SHIFT);
#endif
RCC_PLLCFGR |= RCC_PLLCFGR_DIVP1EN;
RCC_PLLCFGR |= RCC_PLLCFGR_DIVQ1EN;
RCC_PLLCFGR |= RCC_PLLCFGR_DIVR1EN;
Expand Down
5 changes: 5 additions & 0 deletions hal/stm32h7.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#define RCC_PLLCFGR_PLL1VCOSEL (1 << 1)

#define RCC_PLLCFGR_PLL1RGE_2_4 0x1
#define RCC_PLLCFGR_PLL1RGE_8_16 0x3
#define RCC_PLLCFGR_PLL1RGE_SHIFT 0x2

#define RCC_PLLCKSELR_DIVM1 (1 << 4)
Expand Down Expand Up @@ -106,6 +107,10 @@
#define PWR_CR3 (*(volatile uint32_t *)(PWR_BASE + 0x0C)) /* RM0433 - 5.8.4 */
#define PWR_CR3_SCUEN (1 << 2)
#define PWR_CR3_LDOEN (1 << 1)
#define PWR_CR3_SDEN (1 << 2) /* RM0399 name for bit 2 on parts with SMPS */
#define PWR_CR3_BYPASS (1 << 0)
#define PWR_CR3_SUPPLY_MASK (PWR_CR3_SDEN | PWR_CR3_LDOEN | PWR_CR3_BYPASS)
#define PWR_CR3_SUPPLY_UNSET (PWR_CR3_SDEN | PWR_CR3_LDOEN)
#define PWR_D3CR (*(volatile uint32_t *)(PWR_BASE + 0x18)) /* RM0433 - 5.8.6 */
#define PWR_D3CR_VOSRDY (1 << 13)
#define PWR_D3CR_VOS_SHIFT (14)
Expand Down
2 changes: 2 additions & 0 deletions test-app/ARM-stm32h7.ld
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
_Min_Heap_Size = 0x00002000; /* newlib stdio, wolfCrypt test and benchmark */

MEMORY
{
FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
Expand Down
3 changes: 3 additions & 0 deletions test-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ endif

ifeq ($(TARGET),stm32h7)
LSCRIPT_TEMPLATE=ARM-stm32h7.ld
ifeq ($(WOLFCRYPT_SUPPORT),1)
CFLAGS+=-DAPP_HAS_SYSTICK
endif
endif

ifeq ($(TARGET),stm32c0)
Expand Down
56 changes: 52 additions & 4 deletions test-app/app_stm32h7.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@
#include "wolfboot/wolfboot.h"
#include "target.h"

#ifdef WOLFCRYPT_TEST
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfcrypt/test/test.h>
int wolfcrypt_test(void *args);
#endif

#ifdef WOLFCRYPT_BENCHMARK
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfcrypt/benchmark/benchmark.h>
int benchmark_test(void *args);
#endif

#if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK)
#include <wolfssl/wolfcrypt/wc_port.h>
#endif

#define SET_BIT(REG, BIT) ((REG) |= (BIT))
#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
#define READ_BIT(REG, BIT) ((REG) & (BIT))
Expand All @@ -65,8 +81,12 @@

/* GENERAL DEFINITIONS */
/* ====================================================================== */
#ifndef FIRMWARE_A
#define FIRMWARE_A 1
#endif
#ifndef FIRMWARE_B
#define FIRMWARE_B 0
#endif

#define LED_OFF 0
#define LED_INIT 1
Expand Down Expand Up @@ -337,7 +357,7 @@ int uart_setup(uint32_t bitrate)
return -1;
}

static void uart_write(const char c)
static void uart_putc(const char c)
{
/* USART transmit data register(TDR), bit 0-8 contains the data character
* to be transmitted.
Expand All @@ -359,10 +379,23 @@ void uart_print(const char *s)
{
int i = 0;
while (s[i]) {
uart_write(s[i++]);
uart_putc(s[i++]);
}
}

#if (defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK)) && \
!defined(DEBUG_UART)
void uart_write(const char *buf, unsigned int sz)
{
unsigned int i;
for (i = 0; i < sz; i++) {
if (buf[i] == '\n')
uart_putc('\r');
uart_putc(buf[i]);
}
}
#endif

#ifdef WOLFBOOT_TEST_FILLER
#define FILLER_SIZE (64 * 1024)
static volatile uint8_t filler_data[FILLER_SIZE] = { 0x01, 0x02, 0x03 };
Expand Down Expand Up @@ -409,7 +442,7 @@ void main(void)

uart_print("\tFIRMWARE VERSION: ");
if (firmware_version <= 9) {
uart_write(firmware_version + '0');
uart_putc(firmware_version + '0');
uart_print(" \n\n\r");
}
else {
Expand All @@ -424,7 +457,7 @@ void main(void)

char_temp = READ_REG(UPDATE_CHARACTER_1);
uart_print("[DATA] Content of 0x08060000 (1 byte): ");
uart_write(char_temp);
uart_putc(char_temp);
uart_print("\n\r");

if ((char_temp == 'W') && FIRMWARE_A) {
Expand All @@ -435,6 +468,21 @@ void main(void)
uart_print("[INFO] User application B is running and update cannot be triggered\n\r");
}

#if defined(WOLFCRYPT_TEST) || defined(WOLFCRYPT_BENCHMARK)
wolfCrypt_Init();
#ifdef WOLFCRYPT_TEST
uart_print("\n\rRunning wolfCrypt tests...\n\r");
wolfcrypt_test(NULL);
uart_print("Tests complete.\n\r");
#endif
#ifdef WOLFCRYPT_BENCHMARK
uart_print("\n\rRunning wolfCrypt benchmarks...\n\r");
benchmark_test(NULL);
uart_print("Benchmarks complete.\n\r");
#endif
wolfCrypt_Cleanup();
#endif

/* busy wait */
while (1)
;
Expand Down
72 changes: 72 additions & 0 deletions test-app/wolfcrypt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,69 @@
}
#elif defined(TARGET_ti_am64x_r5)
extern uint64_t ClockP_getTimeUsec(void);
#elif defined(TARGET_stm32h7)
/* 1ms SysTick. The core clock is read back from the PLL1 registers
* rather than assumed. */
#define H7_SYST_CSR (*(volatile uint32_t *)(0xE000E010))
#define H7_SYST_RVR (*(volatile uint32_t *)(0xE000E014))
#define H7_SYST_CVR (*(volatile uint32_t *)(0xE000E018))
#define H7_RCC_CR (*(volatile uint32_t *)(0x58024400))
#define H7_RCC_CFGR (*(volatile uint32_t *)(0x58024410))
#define H7_RCC_D1CFGR (*(volatile uint32_t *)(0x58024418))
#define H7_RCC_PLLCKSELR (*(volatile uint32_t *)(0x58024428))
#define H7_RCC_PLL1DIVR (*(volatile uint32_t *)(0x58024430))
#ifndef STM32H7_HSE_HZ
#define STM32H7_HSE_HZ 8000000ULL
#endif
#define STM32H7_HSI_HZ 64000000ULL
#define STM32H7_CSI_HZ 4000000ULL

static volatile uint32_t h7_time_ms = 0;
static uint32_t h7_start_ms = 0;
static int h7_tick_on = 0;

void isr_systick(void)
{
h7_time_ms++;
}

static uint64_t h7_get_hz(void)
{
uint64_t hz = STM32H7_HSI_HZ >> ((H7_RCC_CR >> 3) & 0x3);
uint64_t src;
uint32_t divm, d1cpre;

if (((H7_RCC_CFGR >> 3) & 0x7) == 0x3) {
switch (H7_RCC_PLLCKSELR & 0x3) {
case 1: src = STM32H7_CSI_HZ; break;
case 2: src = STM32H7_HSE_HZ; break;
default: src = hz; break;
}
divm = (H7_RCC_PLLCKSELR >> 4) & 0x3F;
if (divm != 0) {
hz = (src / divm) *
((H7_RCC_PLL1DIVR & 0x1FF) + 1) /
(((H7_RCC_PLL1DIVR >> 9) & 0x7F) + 1);
}
}
d1cpre = (H7_RCC_D1CFGR >> 8) & 0xF;
if (d1cpre >= 12)
hz >>= (d1cpre - 6);
else if (d1cpre >= 8)
hz >>= (d1cpre - 7);
return hz;
}

static uint32_t h7_get_ms(void)
{
if (!h7_tick_on) {
H7_SYST_RVR = (uint32_t)(h7_get_hz() / 1000) - 1;
H7_SYST_CVR = 0;
H7_SYST_CSR = 0x7; /* processor clock, interrupt, enable */
h7_tick_on = 1;
}
return h7_time_ms;
}
#else
/* Simple tick counter fallback */
static volatile unsigned int tick_counter = 0;
Expand Down Expand Up @@ -252,6 +315,10 @@ unsigned long my_time(unsigned long* timer)
unsigned long t = (unsigned long)(ClockP_getTimeUsec() / 1000000);
if (timer) *timer = t;
return t;
#elif defined(TARGET_stm32h7)
unsigned long t = (unsigned long)(h7_get_ms() / 1000);
if (timer) *timer = t;
return t;
#else
/* Simple incrementing counter */
tick_counter++;
Expand Down Expand Up @@ -307,6 +374,11 @@ double current_time(int reset)
#elif defined(TARGET_ti_am64x_r5)
(void)reset;
return (double)(ClockP_getTimeUsec()) / 1000000.0;
#elif defined(TARGET_stm32h7)
uint32_t ms = h7_get_ms();
if (reset)
h7_start_ms = ms;
return (double)(ms - h7_start_ms) / 1000.0;
#else
/* Simple counter-based timing */
if (reset)
Expand Down
Loading