@@ -28,12 +28,12 @@ static void common_hal_sdioio_sdcard_check_for_deinit(sdioio_sdcard_obj_t *self)
28
28
}
29
29
30
30
static int check_pins (const mcu_pin_obj_t * clock , const mcu_pin_obj_t * command , const uint8_t num_data , const mcu_pin_obj_t * * data ) {
31
- if ( CONFIG_SOC_SDMMC_USE_GPIO_MATRIX ) {
32
- // ESP32-S3 and P4 can use any pin for any SDMMC func in either slot
33
- // Default to SLOT_1 for SD cards
34
- ESP_LOGI (TAG , "Using chip with CONFIG_SOC_SDMMC_USE_GPIO_MATRIX" );
35
- return SDMMC_HOST_SLOT_1 ;
36
- }
31
+ #ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
32
+ // ESP32-S3 and P4 can use any pin for any SDMMC func in either slot
33
+ // Default to SLOT_1 for SD cards
34
+ ESP_LOGI (TAG , "Using chip with CONFIG_SOC_SDMMC_USE_GPIO_MATRIX" );
35
+ return SDMMC_HOST_SLOT_1 ;
36
+ #endif
37
37
if (command -> number == GPIO_NUM_11 && clock -> number == GPIO_NUM_6 && data [0 ]-> number == GPIO_NUM_7 ) {
38
38
// Might be slot 0
39
39
if (num_data == 1 || (num_data == 4 && data [1 ]-> number == GPIO_NUM_8 && data [2 ]-> number == GPIO_NUM_9 && data [3 ]-> number == GPIO_NUM_10 )) {
@@ -62,11 +62,8 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
62
62
raise_ValueError_invalid_pins ();
63
63
}
64
64
65
- if (frequency > 40000000 ) {
66
- // Higher than max 40Mhz frequency
67
- mp_raise_ValueError (MP_ERROR_TEXT ("SDIO: requested frequency out of range" ));
68
- }
69
-
65
+ // max 40Mhz frequency
66
+ mp_arg_validate_int_max (frequency ,40000000 ,MP_QSTR_frequency );
70
67
ESP_LOGI (TAG , "Using slot %d" , sd_slot );
71
68
self -> slot = (uint8_t )sd_slot ;
72
69
esp_err_t err = ESP_OK ;
@@ -77,24 +74,18 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
77
74
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT ();
78
75
slot_config .width = 1 ;
79
76
slot_config .clk = clock -> number ;
80
- claim_pin (clock );
81
77
self -> clock = clock -> number ;
82
78
slot_config .cmd = command -> number ;
83
- claim_pin (command );
84
79
self -> command = command -> number ;
85
80
slot_config .d0 = data [0 ]-> number ;
86
81
self -> data [0 ] = data [0 ]-> number ;
87
- claim_pin (data [0 ]);
88
82
if (num_data == 4 ) {
89
83
slot_config .width = 4 ;
90
84
slot_config .d1 = data [1 ]-> number ;
91
- claim_pin (data [1 ]);
92
85
self -> data [1 ] = data [1 ]-> number ;
93
86
slot_config .d2 = data [2 ]-> number ;
94
- claim_pin (data [2 ]);
95
87
self -> data [2 ] = data [2 ]-> number ;
96
88
slot_config .d3 = data [3 ]-> number ;
97
- claim_pin (data [3 ]);
98
89
self -> data [3 ] = data [3 ]-> number ;
99
90
}
100
91
@@ -124,6 +115,15 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
124
115
125
116
common_hal_sdioio_sdcard_check_for_deinit (self );
126
117
118
+ claim_pin (clock );
119
+ claim_pin (command );
120
+ claim_pin (data [0 ]);
121
+ if (num_data == 4 ) {
122
+ claim_pin (data [1 ]);
123
+ claim_pin (data [2 ]);
124
+ claim_pin (data [3 ]);
125
+ }
126
+
127
127
ESP_LOGI (TAG , "Initialized SD card with ID %d:%d-%s" ,
128
128
self -> card .cid .mfg_id , self -> card .cid .oem_id , self -> card .cid .name );
129
129
0 commit comments