Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
dpgeorge wants to merge2 commits intomicropython:master
base:master
Choose a base branch
Loading
fromdpgeorge:stm32-sdcard-fix-n6

Conversation

@dpgeorge
Copy link
Member

@dpgeorgedpgeorge commentedDec 17, 2025
edited
Loading

Summary

There are two small changes here:

  1. unconditionally enable SDMMC1/2 clocks in low power mode, which is necessary for the SD card driver to work (it was previously only being done for the cyw43 SDIO driver)
  2. change the SD card clock speed to high speed for H5/H7/N6, which doubles the transfer speed of the SDIO bus

Testing

Tested on OPENMV_N6:

  • WLAN still works
  • SD card read speed goes from a maximum of 10.6MiB/sec to 16.9MiB/sec, much closer to the theoretical limit for a 4-bit 50MHz bus

TODO:

  • test SD on H5/H7

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
Copy link
MemberAuthor

@kwagyeman@iabdalkader this should hopefully improve the speed of SD card on the N6. Are you able to test this PR to confirm that?

@github-actions
Copy link

Code size report:

Reference:  tests/basics/string_fstring.py: Test fstring nested replacement fields. [ef567dc]Comparison: stm32/sdcard: Use high speed mode for SD transfers on H5/H7/N6. [merge of 6cc3215]  mpy-cross:    +0 +0.000%    bare-arm:    +0 +0.000% minimal x86:    +0 +0.000%    unix x64:    +0 +0.000% standard      stm32:    +0 +0.000% PYBV10     mimxrt:    +0 +0.000% TEENSY40        rp2:    +0 +0.000% RPI_PICO_W       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS  qemu rv32:    +0 +0.000% VIRT_RV32

@kwagyeman
Copy link
Contributor

@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
Copy link
Contributor

Can you test this on an H7/H5 first? I was getting the expected performance on them

That's because I patch all these dividers to 0 in our HALs, except for N6 which is not patched.

@kwagyeman
Copy link
Contributor

Ah! Okay, then this is likely fine. When I was debugging, changing the divider was what I did to increase the speed.

@dpgeorge
Copy link
MemberAuthor

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.

That's because I patch all these dividers to 0 in our HALs,

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
Copy link
Contributor

iabdalkader commentedDec 18, 2025
edited
Loading

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).

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);
Copy link
Contributor

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

Copy link
MemberAuthor

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.c enables LL_AHB5_GRP1_PERIPH_XSPI2 and LL_AHB5_GRP1_PERIPH_XSPIM, so they should be combined with this LL_AHB5_GRP1_PERIPH_ALL
  • usbd_conf.c enables LL_AHB5_GRP1_PERIPH_OTG1 and LL_AHB5_GRP1_PERIPH_OTGPHY1 as part of its initialization, so they should be removed from there
  • eth.c enables the ETH low power clocks, and they should be removed from there

iabdalkader reacted with thumbs up emoji
Copy link
Contributor

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.

Copy link
MemberAuthor

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@iabdalkaderiabdalkaderiabdalkader approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@dpgeorge@kwagyeman@iabdalkader

[8]ページ先頭

©2009-2025 Movatter.jp