@@ -28,12 +28,12 @@ static void common_hal_sdioio_sdcard_check_for_deinit(sdioio_sdcard_obj_t *self)
2828}
2929
3030static 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
3737 if (command -> number == GPIO_NUM_11 && clock -> number == GPIO_NUM_6 && data [0 ]-> number == GPIO_NUM_7 ) {
3838 // Might be slot 0
3939 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,
6262 raise_ValueError_invalid_pins ();
6363 }
6464
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 );
7067 ESP_LOGI (TAG , "Using slot %d" , sd_slot );
7168 self -> slot = (uint8_t )sd_slot ;
7269 esp_err_t err = ESP_OK ;
@@ -77,24 +74,18 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
7774 sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT ();
7875 slot_config .width = 1 ;
7976 slot_config .clk = clock -> number ;
80- claim_pin (clock );
8177 self -> clock = clock -> number ;
8278 slot_config .cmd = command -> number ;
83- claim_pin (command );
8479 self -> command = command -> number ;
8580 slot_config .d0 = data [0 ]-> number ;
8681 self -> data [0 ] = data [0 ]-> number ;
87- claim_pin (data [0 ]);
8882 if (num_data == 4 ) {
8983 slot_config .width = 4 ;
9084 slot_config .d1 = data [1 ]-> number ;
91- claim_pin (data [1 ]);
9285 self -> data [1 ] = data [1 ]-> number ;
9386 slot_config .d2 = data [2 ]-> number ;
94- claim_pin (data [2 ]);
9587 self -> data [2 ] = data [2 ]-> number ;
9688 slot_config .d3 = data [3 ]-> number ;
97- claim_pin (data [3 ]);
9889 self -> data [3 ] = data [3 ]-> number ;
9990 }
10091
@@ -124,6 +115,15 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
124115
125116 common_hal_sdioio_sdcard_check_for_deinit (self );
126117
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+
127127 ESP_LOGI (TAG , "Initialized SD card with ID %d:%d-%s" ,
128128 self -> card .cid .mfg_id , self -> card .cid .oem_id , self -> card .cid .name );
129129
0 commit comments