Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
b26704aa
Commit
b26704aa
authored
Dec 14, 2021
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stm32/sdcard: Support 8-bit wide SDIO bus.
Signed-off-by:
Damien George
<
damien@micropython.org
>
parent
9a1ab228
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
7 deletions
+32
-7
ports/stm32/sdcard.c
ports/stm32/sdcard.c
+32
-7
No files found.
ports/stm32/sdcard.c
View file @
b26704aa
...
...
@@ -60,6 +60,10 @@
#define STATIC_AF_SDCARD_D1 STATIC_AF_SDMMC2_D1
#define STATIC_AF_SDCARD_D2 STATIC_AF_SDMMC2_D2
#define STATIC_AF_SDCARD_D3 STATIC_AF_SDMMC2_D3
#define STATIC_AF_SDCARD_D4 STATIC_AF_SDMMC2_D4
#define STATIC_AF_SDCARD_D5 STATIC_AF_SDMMC2_D5
#define STATIC_AF_SDCARD_D6 STATIC_AF_SDMMC2_D6
#define STATIC_AF_SDCARD_D7 STATIC_AF_SDMMC2_D7
#else
#define SDIO SDMMC1
#define SDMMC_IRQHandler SDMMC1_IRQHandler
...
...
@@ -75,6 +79,10 @@
#define STATIC_AF_SDCARD_D1 STATIC_AF_SDMMC1_D1
#define STATIC_AF_SDCARD_D2 STATIC_AF_SDMMC1_D2
#define STATIC_AF_SDCARD_D3 STATIC_AF_SDMMC1_D3
#define STATIC_AF_SDCARD_D4 STATIC_AF_SDMMC1_D4
#define STATIC_AF_SDCARD_D5 STATIC_AF_SDMMC1_D5
#define STATIC_AF_SDCARD_D6 STATIC_AF_SDMMC1_D6
#define STATIC_AF_SDCARD_D7 STATIC_AF_SDMMC1_D7
#endif
// The F7 & L4 series calls the peripheral SDMMC rather than SDIO, so provide some
...
...
@@ -120,6 +128,10 @@
#define STATIC_AF_SDCARD_D1 STATIC_AF_SDIO_D1
#define STATIC_AF_SDCARD_D2 STATIC_AF_SDIO_D2
#define STATIC_AF_SDCARD_D3 STATIC_AF_SDIO_D3
#define STATIC_AF_SDCARD_D4 STATIC_AF_SDIO_D4
#define STATIC_AF_SDCARD_D5 STATIC_AF_SDIO_D5
#define STATIC_AF_SDCARD_D6 STATIC_AF_SDIO_D6
#define STATIC_AF_SDCARD_D7 STATIC_AF_SDIO_D7
#endif
...
...
@@ -133,6 +145,13 @@
#define MICROPY_HW_SDCARD_CMD (pin_D2)
#endif
// Define a constant to select the bus width.
#if MICROPY_HW_SDCARD_BUS_WIDTH == 4
#define SDIO_BUS_WIDE_VALUE SDIO_BUS_WIDE_4B
#elif MICROPY_HW_SDCARD_BUS_WIDTH == 8
#define SDIO_BUS_WIDE_VALUE SDIO_BUS_WIDE_8B
#endif
#define PYB_SDMMC_FLAG_SD (0x01)
#define PYB_SDMMC_FLAG_MMC (0x02)
#define PYB_SDMMC_FLAG_ACTIVE (0x04)
...
...
@@ -162,10 +181,16 @@ void sdcard_init(void) {
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_CK
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_CK
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_CMD
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_CMD
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D0
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D0
);
#if MICROPY_HW_SDCARD_BUS_WIDTH
=
= 4
#if MICROPY_HW_SDCARD_BUS_WIDTH
>
= 4
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D1
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D1
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D2
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D2
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D3
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D3
);
#if MICROPY_HW_SDCARD_BUS_WIDTH == 8
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D4
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D4
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D5
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D5
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D6
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D6
);
mp_hal_pin_config_alt_static
(
MICROPY_HW_SDCARD_D7
,
MP_HAL_PIN_MODE_ALT
,
MP_HAL_PIN_PULL_UP
,
STATIC_AF_SDCARD_D7
);
#endif
#endif
// configure the SD card detect pin
...
...
@@ -252,9 +277,9 @@ STATIC HAL_StatusTypeDef sdmmc_init_sd(void) {
mp_hal_delay_ms
(
50
);
}
#if MICROPY_HW_SDCARD_BUS_WIDTH
=
= 4
// configure the SD bus width for 4-bit wide operation
status
=
HAL_SD_ConfigWideBusOperation
(
&
sdmmc_handle
.
sd
,
SDIO_BUS_WIDE_
4B
);
#if MICROPY_HW_SDCARD_BUS_WIDTH
>
= 4
// configure the SD bus width for 4
/8
-bit wide operation
status
=
HAL_SD_ConfigWideBusOperation
(
&
sdmmc_handle
.
sd
,
SDIO_BUS_WIDE_
VALUE
);
if
(
status
!=
HAL_OK
)
{
HAL_SD_DeInit
(
&
sdmmc_handle
.
sd
);
return
status
;
...
...
@@ -287,12 +312,12 @@ STATIC HAL_StatusTypeDef sdmmc_init_mmc(void) {
// As this is an eMMC card, overwrite LogBlockNbr with actual value
sdmmc_handle
.
mmc
.
MmcCard
.
LogBlockNbr
=
7469056
+
2048
;
#if MICROPY_HW_SDCARD_BUS_WIDTH
=
= 4
// Configure the SDIO bus width for 4-bit wide operation
#if MICROPY_HW_SDCARD_BUS_WIDTH
>
= 4
// Configure the SDIO bus width for 4
/8
-bit wide operation
#ifdef STM32F7
sdmmc_handle
.
mmc
.
Init
.
ClockBypass
=
SDIO_CLOCK_BYPASS_ENABLE
;
#endif
status
=
HAL_MMC_ConfigWideBusOperation
(
&
sdmmc_handle
.
mmc
,
SDIO_BUS_WIDE_
4B
);
status
=
HAL_MMC_ConfigWideBusOperation
(
&
sdmmc_handle
.
mmc
,
SDIO_BUS_WIDE_
VALUE
);
if
(
status
!=
HAL_OK
)
{
HAL_MMC_DeInit
(
&
sdmmc_handle
.
mmc
);
return
status
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment