-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add support for STM32C0 #286
Conversation
Still in debug mode so wolf boot is big. I'll cleanup documentation to handle debug layout and release layout. Might be able to get wolfBoot into 5 sectors if we change to SHA384, like Daniele recommends. This build should be suitable for the demo. Takes right at 45 seconds from reset to boot app. I'll continue to clean things up. |
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.
It works! With ED25519 and SHA2-384 the code size is 10840
and takes about 10 seconds for the LED to turn on.
I also tested with RSA2048 with SHA2-256 the code size is 13092
and it boots in under 1 second.
SIGN?=RSA2048
HASH?=SHA256
Please add these size/boot time details to the Targets.md
.
docs/Targets.md
Outdated
``` | ||
|
||
### Building STM32C0 | ||
xxx |
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.
Remove the xxx
.
docs/Targets.md
Outdated
For RAMFUNCTION support (required for SEC_PROT) make sure `RAM_CODE=1`. | ||
|
||
### STM32C0 Programming | ||
xxx |
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.
Remove the xxx
docs/Targets.md
Outdated
``` | ||
|
||
### STM32C0 Debugging | ||
xxx |
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.
Remove the xxx
docs/Targets.md
Outdated
|
||
### Building STM32C0 | ||
xxx | ||
Reference configuration (see [/config/examples/stm32g0.config](/config/examples/stm32g0.config)). |
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.
Replace stm32g0
with stm32c0
throughout new section.
config/examples/stm32c0.config
Outdated
SPMATH?=1 | ||
RAM_CODE?=1 | ||
DUALBANK_SWAP?=0 | ||
#Max APP size is 4kB |
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.
8kB
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 think this is correct, as in NVM_FLASH_WRITEONCE the last two sectors are reserved
hal/stm32c0.c
Outdated
RCC_CFGR = (reg32 | RCC_CFGR_SW_HSISYS); | ||
DMB(); | ||
|
||
#if 0 |
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.
Remove or comment on #if 0
hal/stm32c0.ld
Outdated
MEMORY | ||
{ | ||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = @BOOTLOADER_PARTITION_SIZE@ | ||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00002FFF |
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.
Might consider 12K
instead of 0x00002FFF
for readability.
test-app/app_stm32c0.c
Outdated
@@ -0,0 +1,39 @@ | |||
/* main.c |
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.
app_stm32c0.c
test-app/led.c
Outdated
@@ -146,6 +146,43 @@ void boot_led_on(void) | |||
|
|||
#endif /** PLATFORM_stm32g0 **/ | |||
|
|||
#ifdef PLATFORM_stm32c0 |
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.
At quick glance is identical to the above PLATFORM_stm32g0
section. I am okay with reusing the same code for both. #if defined(PLATFORM_stm32g0) || defined(PLATFORM_stm32c0)
. Looks like it ended up being GPIOA5 for both.
docs/HAL.md
Outdated
@@ -19,7 +19,7 @@ and RAM boundaries. | |||
## Supported platforms | |||
|
|||
The following platforms are supported in the current version: | |||
- STM32F4, STM32L5, STM32L0, STM32F7, STM32H7, STM32G0 | |||
- STM32F4, STM32L5, STM32L0, STM32F7, STM32H7, STM32G0, STM32C0 |
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.
Since updating the list also includes: STM32WB55
and STM32U5
docs/Targets.md
Outdated
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x08004000 /* offset 16kB to 24kB */ | ||
#define WOLFBOOT_PARTITION_SIZE 0x2000 /* 8 KB */ | ||
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x08006000 /* offset 24kB to 32kB */ | ||
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x08003800 /* offset 14kB to 16kB */ |
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 assume you resolved the issue with using the end of flash and it was related to NVM_FLASH_WRITEONCE
?
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.
Can't prove that yet. One of the things I need to test. I'll make a maximum-sized test app to prove it out.
hal/stm32c0.c
Outdated
# error "wolfBoot STM32C0 HAL: no WRITEONCE support detected. Please define NVM_FLASH_WRITEONCE" | ||
#endif | ||
|
||
/* XXX Debug only! */ |
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.
Use #ifdef DEBUG
config/examples/stm32c0.config
Outdated
WOLFBOOT_VERSION?=0 | ||
V?=0 | ||
SPMATH?=1 | ||
RAM_CODE?=1 |
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.
Note: With RAM_CODE?=0
the code size is about 670 bytes smaller. However that prevents wolfBoot from having the ability to self-update. Also its about 75% slower. Recommend the default stays enabled, but might be worth documenting.
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.
OTOH immutable wolfboot if that smaller would allow for larger partition and a better geometry (10K wolfBoot, 10K partition size, BOOT=0x08002800 UPDATE=0x08005000 SWAP=0x08007800 with 6KB max effective application size and 2 sectors reserved for NVM_FLASH_WRITEONCE in each partition)
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.
Is the speed impact due to the code running out of the flash? I thought this had an instruction cache (small), but no data cache. I'll extend the documentation to provide those tradeoffs. Is the ONLY thing I need to do to disable wolfBoot updates is set RAM_CODE=0? Seems like we should be ok with pushing a bunch of the code into RAM during boot since the ram will be recovered during the app boot.
…r either RSA2048 or ED25519. Partition scheme allows 10KB application partition or (6KB actual due to NVM write once). Made space using NO_MPU=1, RAM_CODE=0, USE_SLOW_SHA256 and !FLASH_SECURABLE_MEMORY_SUPPORT.
fb61bd3
to
696e655
Compare
@danielinux rebased, cleaned up and improved PR. After CI it is ready for review and inclusion in upcoming release. |
hal/stm32c0.c
Outdated
static void clock_pll_on(int powersave) | ||
{ | ||
uint32_t reg32; | ||
uint32_t cpu_freq, plln, pllm, pllq, pllp, pllr, hpre, ppre, flash_waitstates; |
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.
Remove declarations of unused variables (cpu_freq, plln, pllm, pllq, pllp, pllr, hpre, ppre)
hal/stm32c0.c
Outdated
#define RCC_CR (*(volatile uint32_t *)(RCC_BASE + 0x00)) /* RM0444 - 5.4.1 */ | ||
#define RCC_CFGR (*(volatile uint32_t *)(RCC_BASE + 0x08)) /* RM0444 - 5.4.3 */ |
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.
Wrong reference manual in comments - should be RM0490
hal/stm32c0.c
Outdated
#define RCC_CFGR_SW_PLL 0x2 | ||
#define RCC_PLLCFGR_PLLR_EN (1 << 28) /* RM0444 - 5.4.3 */ | ||
|
||
#define RCC_PLLCFGR_PLLSRC_HSI16 2 |
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.
Unused PLL defines
hal/stm32c0.c
Outdated
|
||
/*** FLASH ***/ | ||
#define PWR_APB1_CLOCK_ER_VAL (1 << 28) | ||
#define SYSCFG_APB2_CLOCK_ER_VAL (1 << 0) /* RM0444 - 5.4.15 - RCC_APBENR2 - SYSCFGEN */ |
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.
correct value, wrong RM in comment
hal/stm32c0.ld
Outdated
MEMORY | ||
{ | ||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = @BOOTLOADER_PARTITION_SIZE@ | ||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 12K-1 |
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.
remove "-1"
Supports STM32C0x0/STM32C0x1.
Tested build configurations: