Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.6k
stm32: fix low-power clock and SD card speed on N6#18582
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
These peripherals are needed for SD card and WLAN support, and it doesn'thurt to unconditionally enable the clocks in low power, like all the otherperipherals.Signed-off-by: Damien George <damien@micropython.org>
This doubles the speed of SD card transfers.Signed-off-by: Damien George <damien@micropython.org>
dpgeorge commentedDec 17, 2025
@kwagyeman@iabdalkader this should hopefully improve the speed of SD card on the N6. Are you able to test this PR to confirm that? |
Code size report: |
kwagyeman commentedDec 17, 2025
@dpgeorge - Can you test this on an H7/H5 first? I was getting the expected performance on them... but, 1/2 on the N6. Changing the clock div indeed increases the speed, but, then it should also double the H7/H5 which. So, not 100% sure this is the correct thing to do. |
iabdalkader commentedDec 17, 2025
That's because I patch all these dividers to 0 in our HALs, except for N6 which is not patched. |
kwagyeman commentedDec 17, 2025
Ah! Okay, then this is likely fine. When I was debugging, changing the divider was what I did to increase the speed. |
dpgeorge commentedDec 18, 2025
I tested this on a H5 board, and indeed it increases the read speed of SD card, from a maximum of about 12.5M/s to about 18.5M/s.
Do you mean you use a value of 2? Because that's what SDMMC_HSPEED_CLK_DIV is defined to (and probably 0 is an illegal value). |
iabdalkader commentedDec 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
No, the N6 uses 0x4 with an SDMMC kernel clock of 200MHz, so it was running at 12.5MHz. A divider of 0x2 is sdmmc_ker_ck / 4 = 50MHz, so this change should be good. |
| // Enable some AHB peripherals during sleep. | ||
| LL_AHB1_GRP1_EnableClockLowPower(LL_AHB1_GRP1_PERIPH_ALL);// GPDMA1, ADC12 | ||
| LL_AHB4_GRP1_EnableClockLowPower(LL_AHB4_GRP1_PERIPH_ALL);// GPIOA-Q, PWR, CRC | ||
| LL_AHB5_GRP1_EnableClockLowPower(LL_AHB5_GRP1_PERIPH_SDMMC2 |LL_AHB5_GRP1_PERIPH_SDMMC1); |
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'd just add
LL_AHB5_GRP1_EnableClockLowPower(LL_AHB5_GRP1_PERIPH_ALL);
This is what we've been using:
#if defined(STM32N6)// Enable AHB peripherals during sleep.LL_AHB1_GRP1_EnableClockLowPower(LL_AHB1_GRP1_PERIPH_ALL);LL_AHB2_GRP1_EnableClockLowPower(LL_AHB2_GRP1_PERIPH_ALL);LL_AHB3_GRP1_EnableClockLowPower(LL_AHB3_GRP1_PERIPH_ALL);LL_AHB4_GRP1_EnableClockLowPower(LL_AHB4_GRP1_PERIPH_ALL);LL_AHB5_GRP1_EnableClockLowPower(LL_AHB5_GRP1_PERIPH_ALL);// Enable APB peripherals during sleep.LL_APB1_GRP1_EnableClockLowPower(LL_APB1_GRP1_PERIPH_ALL);LL_APB1_GRP2_EnableClockLowPower(LL_APB1_GRP2_PERIPH_ALL);LL_APB2_GRP1_EnableClockLowPower(LL_APB2_GRP1_PERIPH_ALL);LL_APB4_GRP1_EnableClockLowPower(LL_APB4_GRP1_PERIPH_ALL);LL_APB4_GRP2_EnableClockLowPower(LL_APB4_GRP2_PERIPH_ALL);LL_APB5_GRP1_EnableClockLowPower(LL_APB5_GRP1_PERIPH_ALL);#endif
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 can make that change, but it may need some further changes and testing:
main.cenables LL_AHB5_GRP1_PERIPH_XSPI2 and LL_AHB5_GRP1_PERIPH_XSPIM, so they should be combined with this LL_AHB5_GRP1_PERIPH_ALLusbd_conf.cenables LL_AHB5_GRP1_PERIPH_OTG1 and LL_AHB5_GRP1_PERIPH_OTGPHY1 as part of its initialization, so they should be removed from thereeth.cenables the ETH low power clocks, and they should be removed from there
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's up to you really, it was just a comment. It does sound like it would be a good cleanup.
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.
OK, I'll do some testing.
Uh oh!
There was an error while loading.Please reload this page.
Summary
There are two small changes here:
Testing
Tested on OPENMV_N6:
TODO: