variants: allow mbedtls buffer lazy allocation#512
Merged
Conversation
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.0% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
58 | 16 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
30 | 8 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 8 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 8 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
52 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
62 | 18 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
66 | 16 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
74 | 16 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
26.9% |
56 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
There was a problem hiding this comment.
Pull request overview
This PR reduces baseline RAM usage on selected variants by preventing Zephyr/mbedTLS from reserving its heap buffer at boot, and instead initializing the mbedTLS buffer allocator only when TLS-capable sketch code is linked/used.
Changes:
- Disable automatic mbedTLS initialization (
CONFIG_MBEDTLS_INIT=n) in multiple STM32H747 / Portenta C33 variants to avoid reserving the mbedTLS heap by default. - Add a
ZephyrSSLClientimplementation that initializes the mbedTLS memory buffer allocator from a sketch-side static heap when TLS is used. - Export
mbedtls_memory_buffer_alloc_initfrom the loader to support sketch-side initialization, and adjust SocketWrapper headers’ include structure.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.conf | Disable automatic mbedTLS init on Portenta H7 variant to avoid reserving heap at boot |
| variants/arduino_portenta_c33_r7fa6m5bh3cfc/arduino_portenta_c33_r7fa6m5bh3cfc.conf | Disable automatic mbedTLS init on Portenta C33 variant |
| variants/arduino_opta_stm32h747xx_m7/arduino_opta_stm32h747xx_m7.conf | Disable automatic mbedTLS init on Opta variant |
| variants/arduino_nicla_vision_stm32h747xx_m7/arduino_nicla_vision_stm32h747xx_m7.conf | Disable automatic mbedTLS init on Nicla Vision variant |
| variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.conf | Disable automatic mbedTLS init on GIGA R1 variant |
| loader/llext_exports.c | Export mbedTLS buffer allocator init symbol for sketch-side TLS initialization |
| libraries/SocketWrapper/ZephyrUDP.h | Remove direct Arduino.h include (now provided by SocketWrapper.h) |
| libraries/SocketWrapper/ZephyrSSLClient.h | Add ZephyrSSLClient wrapper that gates TLS connect on mbedTLS readiness |
| libraries/SocketWrapper/ZephyrSSLClient.cpp | Implement sketch-side mbedTLS buffer allocator initialization |
| libraries/SocketWrapper/SocketWrapper.h | Centralize Arduino.h include for SocketWrapper consumers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
facchinm
previously approved these changes
Jun 15, 2026
760c85a to
dabbaa2
Compare
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.0% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
58 | 16 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
30 | 8 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 8 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 8 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
52 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
62 | 18 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
66 | 16 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
74 | 16 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.5% |
56 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
Author
|
Tested on GIGA OPTA and PORTENTA C33 |
Moving mbedtls init function from the loader to the core allow lazy allocation of mbedtls buffer
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.0% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
58 | 16 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
30 | 8 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 8 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 8 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
52 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
62 | 18 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
66 | 16 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
74 | 16 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.5% |
56 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
|
Memory usage change @ 1467ed7
Click for full report table
Click for full report CSV |
pillo79
approved these changes
Jun 16, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
starting from this discussion This PR is an alternative implementation trying to reduce mbedtls RAM usage allocating the buffer only if the sketch includes TLS functionality.
Test results on GIGA R1
WiFiWebClient.ino sketchWiFiWebClientTLS.ino