Add STM32CubeMX2 (MX2) support: conf detection, HAL2 example console, codegen assets

pull/11348/head
David Garske 2026-08-28 16:38:15 -07:00
parent f670b0cd0d
commit b04084bff3
6 changed files with 1586 additions and 0 deletions

View File

@ -645,6 +645,8 @@ SSL_SNIFFER_EXPORTS
SSN_BUILDING_LIBYASSL
SSS_HAVE_SE05X_VER_GTE_07_02
STATIC_CHUNKS_ONLY
STM32C562xx
STM32C5A3xx
STM32F107xC
STM32F207xx
STM32F217xx
@ -673,6 +675,7 @@ STM32U385xx
STM32U575xx
STM32U585xx
STM32U5A9xx
STM32V873xx
STM32WB55xx
STM32WBA52xx
STM32WL55xx
@ -1173,6 +1176,7 @@ WOLFSSL_XILINX_PATCH
WOLFSSL_XIL_MSG_NO_SLEEP
WOLFSSL_ZEPHYR
WOLF_ALLOW_BUILTIN
WOLF_CONF_ASN_TIME
WOLF_CRYPTO_CB_ASYNC_POLL
WOLF_CRYPTO_CB_CMD
WOLF_CRYPTO_CB_ONLY_FALCON

View File

@ -0,0 +1,38 @@
# wolfSSL STM32CubeMX2 (MX2) codegen assets
STM32CubeMX2 replaces the classic CubeMX pack mechanism: the configuration
GUI is defined by a JSON-Forms schema and the configuration header is
rendered by a Handlebars template through `cube codegen`, producing
`mx_wolfSSL_conf.h` in the generated project (the MX2 analog of
`wolfSSL.I-CUBE-wolfSSL_conf.h`, using the same `WOLF_CONF_*` scheme).
- `mx_wolfSSL_parameters.json` - the wolfSSL configuration panel shown in
STM32CubeMX2 (JSON-Forms). Includes the `STM32 Hardware Crypto` toggle:
on devices where wolfSSL has register-level STM32 support (independent
of the HAL1 to HAL2 API change), the generated configuration enables the
RNG, HASH, AES and PKA peripherals.
- `mx_wolfSSL_conf_template.h.hbs` - the Handlebars template that renders
`mx_wolfSSL_conf.h`.
`wolfssl/wolfcrypt/settings.h` picks the generated header up automatically
via `__has_include("mx_wolfSSL_conf.h")` (HAL2 projects have no global
define like HAL1's `USE_HAL_DRIVER`).
These files are packaged into the `wolfSSL.wolfSSL_middlewares` pack for
STM32CubeMX2 by the wolfSSL pack tooling; the pack build prefers the copies
in this directory so the configuration stays versioned with the library.
## Project checklist (validated on NUCLEO-C5A3ZG, full wolfcrypt_test pass)
- Enable the console UART (Async) matching the wolfSSL panel's
`Console UART instance` (default `usart2`, the Nucleo VCP) and enable the
`RNG` peripheral so the generated clock init arms the RNG kernel clock.
- Raise `HEAP_SIZE`/`STACK_SIZE` in the project's `user_modifiable` linker
script (128 KB / 16 KB recommended); the defaults are too small for
wolfSSL and fail wolfcrypt_test's MEMORY test.
- Call `wolfCryptDemo(NULL)` (from `wolfssl_example.c`, the wolfCrypt Test
component) in `main()` to get the interactive test/benchmark menu on the
console UART; printf is retargeted through the syscalls utility's
`__io_putchar` hook automatically.
- For benchmark throughput output add `-u _printf_float` to the linker
options (newlib-nano) and build the Release profile.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,342 @@
{
"componentid": "::Security:STM32CubeMX2 Config:wolfSSL",
"type": "object",
"grammarVersion": "3.3",
"properties": {
"parameters": {
"type": "object",
"properties": {
"info": {
"title": "wolfSSL configuration",
"type": "object",
"properties": {
"label": {
"type": "string",
"title": "User Label",
"description": "Adds extra #define in generated code",
"default": "MX_WOLFSSL",
"pattern": "^([A-Z_][A-Z0-9_]{1,31})?$",
"unique": "project",
"unicityTag": "middlewares_wolfssl_sw_label",
"minLength": 3,
"maxLength": 15
}
}
},
"basic_config": {
"title": "Basic configuration",
"type": "object",
"properties": {
"debugSupport": {
"type": "boolean",
"title": "Debug support",
"description": "Enable debug support",
"default": false
},
"wolfCryptOnly": {
"type": "boolean",
"title": "wolfCrypt Only",
"description": "Enable wolfCrypt only",
"default": false
},
"tlsV13": {
"type": "boolean",
"title": "TLS v1.3",
"description": "Enable TLS v1.3",
"default": true
},
"tlsV12": {
"type": "boolean",
"title": "TLS v1.2",
"description": "Enable TLS v1.2",
"default": true
},
"dtlsSupport": {
"type": "boolean",
"title": "DTLS Support",
"description": "Enable DTLS support",
"default": false
},
"mathConfiguration": {
"type": "string",
"title": "Math configuration",
"description": "Configure math",
"default": "6",
"oneOf": [
{
"const": "1",
"title": "Fast (stack) math"
},
{
"const": "2",
"title": "Normal (heap) math"
},
{
"const": "3",
"title": "Single Precision C math (only common curves/key sizes)"
},
{
"const": "4",
"title": "Single Precision ASM Cortex-M3+ Math"
},
{
"const": "5",
"title": "Single Precision ASM Cortex-M0 (Generic Thumb) Math"
},
{
"const": "6",
"title": "Single Precision C all small"
},
{
"const": "7",
"title": "Single Precision C all big"
}
]
},
"rtos": {
"type": "string",
"title": "RTOS",
"description": "Configure RTOS",
"default": "1",
"oneOf": [
{
"const": "1",
"title": "Single Threaded (no RTOS / Baremetal)"
},
{
"const": "2",
"title": "FreeRTOS"
}
]
},
"rngSupport": {
"type": "boolean",
"title": "RNG Support",
"description": "Enable RNG support",
"default": true
},
"rsaSupport": {
"type": "boolean",
"title": "RSA Support",
"description": "Enable RSA support",
"default": true
},
"eccSupport": {
"type": "boolean",
"title": "ECC Support",
"description": "Enable ECC support",
"default": true
},
"dhSupport": {
"type": "boolean",
"title": "DH (Diffie-Hellman) Support",
"description": "Enable DH support",
"default": true
},
"aesGCMSupport": {
"type": "string",
"title": "AES GCM Support",
"description": "Configure AES GCM support",
"default": "1",
"oneOf": [
{
"const": "0",
"title": "Disabled"
},
{
"const": "1",
"title": "GCM_SMALL"
},
{
"const": "2",
"title": "GCM_TABLE_4BIT"
}
]
},
"aesCBCSupport": {
"type": "boolean",
"title": "AES CBC Support",
"description": "Enable AES CBC support",
"default": false
},
"chaCha20Support": {
"type": "boolean",
"title": "ChaCha20 / Poly1305 Support",
"description": "Enable ChaCha20 / Poly1305 support",
"default": true
},
"ed25519Support": {
"type": "boolean",
"title": "Ed25519 / Curve25519 Support",
"description": "Enable Ed25519 / Curve25519 support",
"default": false
},
"md5Support": {
"type": "boolean",
"title": "MD5 Support",
"description": "Enable MD5 support",
"default": false
},
"sha1Support": {
"type": "boolean",
"title": "SHA1 Support",
"description": "Enable SHA1 support",
"default": false
},
"sha2_224Support": {
"type": "boolean",
"title": "SHA2-224 Support",
"description": "Enable SHA2-224 support",
"default": false
},
"sha2_256Support": {
"type": "boolean",
"title": "SHA2-256 Support",
"description": "Enable SHA2-256 support",
"default": true
},
"sha2_384Support": {
"type": "boolean",
"title": "SHA2-384 Support",
"description": "Enable SHA2-384 support",
"default": false
},
"sha2_512Support": {
"type": "boolean",
"title": "SHA2-512 Support",
"description": "Enable SHA2-512 support",
"default": false
},
"sha3Support": {
"type": "boolean",
"title": "SHA3 Support",
"description": "Enable SHA3 support",
"default": false
},
"preSharedKeySupport": {
"type": "boolean",
"title": "Pre-Shared-Key Support",
"description": "Enable Pre-Shared-Key support",
"default": false
},
"pwdBasedKeyDerivationSupport": {
"type": "boolean",
"title": "Pwd Based Key Derivation Support",
"description": "Enable Pwd Based Key Derivation support",
"default": false
},
"keepPeerCertSupport": {
"type": "boolean",
"title": "Keep Peer Cert Support",
"description": "Enable Keep Peer Cert support",
"default": false
},
"base64EncodeSupport": {
"type": "boolean",
"title": "Base64 Encode Support",
"description": "Enable Base64 Encode support",
"default": false
},
"openSSLExtraSupport": {
"type": "string",
"title": "OpenSSL Extra Support",
"description": "Configure OpenSSL Extra support",
"default": "0",
"oneOf": [
{
"const": "0",
"title": "Disabled"
},
{
"const": "1",
"title": "Enable basic (OPENSSL_EXTRA)"
},
{
"const": "2",
"title": "Enable all (OPENSSL_ALL)"
}
]
},
"wolfCryptTestBenchmarkSupport": {
"type": "boolean",
"title": "WolfCrypt Test / Benchmark Support",
"description": "Enable WolfCrypt Test / Benchmark support",
"default": true
},
"kyberMLKemSupport": {
"type": "boolean",
"title": "KYBER / ML-KEM Post-Quantum Algorithm Support",
"description": "Enable KYBER / ML-KEM Post-Quantum Algorithm support",
"default": false
},
"dtls13Support": {
"type": "boolean",
"title": "DTLS v1.3 Support",
"description": "Enable DTLS v1.3 (requires DTLS Support and TLS v1.3)",
"default": false
},
"hwCrypto": {
"type": "boolean",
"title": "STM32 Hardware Crypto",
"description": "Use the STM32 hardware crypto peripherals (RNG, HASH, AES, PKA) where the selected device has wolfSSL support; software fallback otherwise",
"default": true
},
"consoleUart": {
"type": "string",
"title": "Console UART instance",
"description": "Lowercase UART instance the wolfCrypt test/benchmark console uses (matches the STM32CubeMX2 UART user label, e.g. usart2); the generated handle getter mx_<instance>_uart_gethandle() must exist",
"default": "usart2",
"pattern": "^[a-z0-9_]{3,16}$",
"minLength": 3,
"maxLength": 16
},
"armASMSupport": {
"type": "boolean",
"title": "ARM ASM Support",
"description": "Enable ARM ASM support",
"default": false
},
"ioInterfaceConfig": {
"type": "string",
"title": "IO Interface Configuration",
"description": "Configure IO Interface",
"default": "1",
"oneOf": [
{
"const": "1",
"title": "User IO"
},
{
"const": "2",
"title": "LWIP (posix API)"
},
{
"const": "3",
"title": "LWIP (native API)"
}
]
},
"sessionCacheSupport": {
"type": "boolean",
"title": "Session cache / Session tickets Support",
"description": "Enable Session cache / Session tickets support",
"default": false
},
"tpmSupport": {
"type": "boolean",
"title": "TPM Support",
"description": "Enable TPM support",
"default": false
},
"tlsKeyCallbacksSupport": {
"type": "boolean",
"title": "TLS Key Callbacks Support",
"description": "Enable TLS Key Callbacks support",
"default": false
}
}
}
}
}
}
}

View File

@ -117,10 +117,21 @@
/* This sets which UART to use for the console. It is something you will have
* to configure in STMCubeIDE and then change here. */
#ifdef WOLF_CONF_CONSOLE_UART_GETHANDLE
/* STM32CubeMX2 (HAL2): the generated configuration selects the console UART
* through the MX2 handle getter (mx_<instance>_uart_gethandle(), declared by
* mx_hal_def.h), so no HAL1-style extern handle exists. HAL2 also renames
* the status type (HAL_OK and friends are unchanged). */
#include "mx_hal_def.h"
#undef HAL_CONSOLE_UART
#define HAL_CONSOLE_UART (*WOLF_CONF_CONSOLE_UART_GETHANDLE())
typedef hal_status_t HAL_StatusTypeDef; /* HAL2 renames the status type */
#else
#ifndef HAL_CONSOLE_UART
#define HAL_CONSOLE_UART huart4
#endif
extern UART_HandleTypeDef HAL_CONSOLE_UART;
#endif
/*****************************************************************************
* Public types/enumerations/variables
@ -1833,8 +1844,40 @@ double current_time(void)
return ((double) time.Hours * 3600) + ((double) time.Minutes * 60)
+ (double) time.Seconds + ((double) subsec / 1000);
}
#else
/* No HAL RTC (e.g. STM32CubeMX2 / HAL2 projects): use the millisecond tick */
double current_time(void)
{
return (double)HAL_GetTick() / 1000.0;
}
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef WOLF_CONF_CONSOLE_UART_GETHANDLE
/* printf retargeting for STM32CubeMX2 projects, routed to the console UART.
* Both are weak or toolchain-specific so a project-provided version wins. */
#if defined(__ICCARM__)
size_t __write(int handle, const unsigned char* buf, size_t bufSize)
{
size_t i;
(void)handle;
for (i = 0; i < bufSize; i++) {
(void)HAL_UART_Transmit(&HAL_CONSOLE_UART, (uint8_t*)&buf[i], 1,
0xFFFF);
}
return bufSize;
}
#elif defined(__GNUC__)
/* The STM32CubeMX2 syscalls utility routes newlib _write() to the weak
* __io_putchar() hook; implementing the hook is the intended retarget. */
int __io_putchar(int ch)
{
uint8_t c = (uint8_t)ch;
(void)HAL_UART_Transmit(&HAL_CONSOLE_UART, &c, 1, 0xFFFF);
return ch;
}
#endif
#endif /* WOLF_CONF_CONSOLE_UART_GETHANDLE */
#ifdef CMSIS_OS2_H_
void wolfCryptDemo(void* argument)
#else

View File

@ -356,6 +356,19 @@
#endif
#endif
/* Probe for the STM32CubeMX2 generated configuration ahead of the chain
* below. __has_include must stay inside its own guarded block: preprocessors
* without it would otherwise fail parsing the #elif expression (the header
* name string is illegal in an integer constant expression), which the
* defined() short-circuit does not prevent. */
#if !defined(HAVE_CONFIG_H) && !defined(WOLFSSL_USER_SETTINGS) && \
!defined(WOLFSSL_OPTIONS_H) && !defined(WOLFSSL_NO_OPTIONS_H) && \
!defined(WOLFSSL_CUSTOM_CONFIG) && defined(__has_include)
#if __has_include("mx_wolfSSL_conf.h")
#define WOLFSSL_MX2_CONF_INCLUDE
#endif
#endif
#ifdef WOLFSSL_USER_SETTINGS
#if defined(BUILDING_WOLFSSL_ASM) && defined(WOLFSSL_USER_SETTINGS_ASM)
/*
@ -377,6 +390,11 @@
#elif defined(USE_HAL_DRIVER) && !defined(HAVE_CONFIG_H)
/* STM Configuration File (generated by CubeMX) */
#include "wolfSSL.I-CUBE-wolfSSL_conf.h"
#elif defined(WOLFSSL_MX2_CONF_INCLUDE)
/* STM Configuration File (generated by STM32CubeMX2). HAL2 projects
* have no global define like HAL1's USE_HAL_DRIVER, so the probe
* above detects the generated configuration header itself. */
#include "mx_wolfSSL_conf.h"
#elif defined(NUCLEUS_PLUS_2_3)
/* NOTE: cyassl_nucleus_defs.h is akin to user_settings.h */
#include "nucleus.h"