Never reset SD card pins
This commit is contained in:
parent
38d2472683
commit
48d826b15d
|
@ -235,16 +235,22 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
|
|||
if (clock != NULL) {
|
||||
gpio_set_function(clock->number, GPIO_GPFSEL4_FSEL48_SD1_CLK);
|
||||
gpio_set_pull(clock->number, BP_PULL_NONE);
|
||||
self->clock_pin = clock->number;
|
||||
gpio_set_function(command->number, GPIO_GPFSEL4_FSEL49_SD1_CMD);
|
||||
gpio_set_pull(command->number, BP_PULL_UP);
|
||||
self->command_pin = command->number;
|
||||
gpio_set_function(data[0]->number, GPIO_GPFSEL5_FSEL50_SD1_DAT0);
|
||||
gpio_set_pull(data[0]->number, BP_PULL_UP);
|
||||
self->data_pins[0] = data[0]->number;
|
||||
gpio_set_function(data[1]->number, GPIO_GPFSEL5_FSEL51_SD1_DAT1);
|
||||
gpio_set_pull(data[1]->number, BP_PULL_UP);
|
||||
self->data_pins[1] = data[1]->number;
|
||||
gpio_set_function(data[2]->number, GPIO_GPFSEL5_FSEL52_SD1_DAT2);
|
||||
gpio_set_pull(data[2]->number, BP_PULL_UP);
|
||||
self->data_pins[2] = data[2]->number;
|
||||
gpio_set_function(data[3]->number, GPIO_GPFSEL5_FSEL53_SD1_DAT3);
|
||||
gpio_set_pull(data[3]->number, BP_PULL_UP);
|
||||
self->data_pins[3] = data[3]->number;
|
||||
} else {
|
||||
// Switch the sdcard to use the old arasan interface.
|
||||
GPIO->EXTRA_MUX_b.SDIO = GPIO_EXTRA_MUX_SDIO_ARASAN;
|
||||
|
@ -280,7 +286,19 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
|
|||
// Start clocking the card.
|
||||
_set_card_clk(0, 400);
|
||||
|
||||
sdmmc_card_init(&self->host_info, &self->card_info);
|
||||
sdmmc_err_t err = SDMMC_ERR_INVALID_RESPONSE;
|
||||
size_t tries = 3;
|
||||
while (err == SDMMC_ERR_INVALID_RESPONSE && tries > 0) {
|
||||
err = sdmmc_card_init(&self->host_info, &self->card_info);
|
||||
if (err != SDMMC_OK) {
|
||||
mp_printf(&mp_plat_print, "SD card init failed %d\n", err);
|
||||
} else if (tries < 3) {
|
||||
mp_printf(&mp_plat_print, "SD card init success\n");
|
||||
}
|
||||
tries--;
|
||||
}
|
||||
|
||||
self->init = err == SDMMC_OK;
|
||||
|
||||
self->capacity = self->card_info.csd.capacity;
|
||||
}
|
||||
|
@ -297,9 +315,6 @@ uint8_t common_hal_sdioio_sdcard_get_width(sdioio_sdcard_obj_t *self) {
|
|||
return self->num_data;
|
||||
}
|
||||
|
||||
STATIC void check_for_deinit(sdioio_sdcard_obj_t *self) {
|
||||
}
|
||||
|
||||
STATIC void check_whole_block(mp_buffer_info_t *bufinfo) {
|
||||
if (bufinfo->len % 512) {
|
||||
mp_raise_ValueError(translate("Buffer length must be a multiple of 512"));
|
||||
|
@ -307,11 +322,12 @@ STATIC void check_whole_block(mp_buffer_info_t *bufinfo) {
|
|||
}
|
||||
|
||||
int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
|
||||
check_for_deinit(self);
|
||||
if (!self->init) {
|
||||
return -EIO;
|
||||
}
|
||||
check_whole_block(bufinfo);
|
||||
self->state_programming = true;
|
||||
|
||||
// mp_printf(&mp_plat_print, "write %d %d %d %d\n", start_block, bufinfo->len / 512, self->card_info.csd.capacity, self->card_info.csd.sector_size);
|
||||
sdmmc_err_t error = sdmmc_write_sectors(&self->card_info, bufinfo->buf,
|
||||
start_block, bufinfo->len / 512);
|
||||
|
||||
|
@ -325,7 +341,9 @@ int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t sta
|
|||
}
|
||||
|
||||
int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) {
|
||||
check_for_deinit(self);
|
||||
if (!self->init) {
|
||||
return -EIO;
|
||||
}
|
||||
check_whole_block(bufinfo);
|
||||
sdmmc_err_t error = sdmmc_read_sectors(&self->card_info, bufinfo->buf,
|
||||
start_block, bufinfo->len / 512);
|
||||
|
@ -339,7 +357,9 @@ int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t *self, uint32_t star
|
|||
}
|
||||
|
||||
bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t frequency, uint8_t bits) {
|
||||
check_for_deinit(self);
|
||||
if (!self->init) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -361,7 +381,14 @@ void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self) {
|
|||
self->data_pins[1] = COMMON_HAL_MCU_NO_PIN;
|
||||
self->data_pins[2] = COMMON_HAL_MCU_NO_PIN;
|
||||
self->data_pins[3] = COMMON_HAL_MCU_NO_PIN;
|
||||
self->init = false;
|
||||
}
|
||||
|
||||
void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self) {
|
||||
never_reset_pin_number(self->command_pin);
|
||||
never_reset_pin_number(self->clock_pin);
|
||||
never_reset_pin_number(self->data_pins[0]);
|
||||
never_reset_pin_number(self->data_pins[1]);
|
||||
never_reset_pin_number(self->data_pins[2]);
|
||||
never_reset_pin_number(self->data_pins[3]);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ typedef struct {
|
|||
uint8_t num_data;
|
||||
bool state_programming;
|
||||
bool has_lock;
|
||||
bool init;
|
||||
uint8_t command_pin;
|
||||
uint8_t clock_pin;
|
||||
uint8_t data_pins[4];
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 82c3fbb0d8622a0108003eb84d8fbdac0ac9d80e
|
||||
Subproject commit 24578e029babb1a01ef8641ca6019f1a86992ff4
|
|
@ -60,6 +60,7 @@ void supervisor_flash_init(void) {
|
|||
NULL, NULL,
|
||||
0, NULL, 8000000);
|
||||
#endif
|
||||
common_hal_sdioio_sdcard_never_reset(&sd);
|
||||
|
||||
uint32_t buffer[512 / sizeof(uint32_t)];
|
||||
mp_buffer_info_t bufinfo;
|
||||
|
|
Loading…
Reference in New Issue