mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Move SD card initialization to sdcard_init
This commit is contained in:
parent
6136bd04e1
commit
0370eb54be
@ -72,20 +72,13 @@ bool sdcard_is_present(void)
|
|||||||
return (HAL_GPIO_ReadPin(SD_CD_PORT, SD_CD_PIN)==GPIO_PIN_RESET);
|
return (HAL_GPIO_ReadPin(SD_CD_PORT, SD_CD_PIN)==GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void __fatal_error(const char *msg);
|
||||||
|
|
||||||
void sdcard_init(void)
|
void sdcard_init(void)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sdcard_power_on(void)
|
|
||||||
{
|
{
|
||||||
volatile int retry=10;
|
volatile int retry=10;
|
||||||
HAL_SD_CardInfoTypedef cardinfo;
|
HAL_SD_CardInfoTypedef cardinfo;
|
||||||
|
|
||||||
if (!sdcard_is_present()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDIO configuration
|
// SDIO configuration
|
||||||
SDHandle.Instance = SDIO;
|
SDHandle.Instance = SDIO;
|
||||||
SDHandle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
SDHandle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
||||||
@ -100,15 +93,14 @@ bool sdcard_power_on(void)
|
|||||||
// Init SD interface
|
// Init SD interface
|
||||||
while(HAL_SD_Init(&SDHandle, &cardinfo) != SD_OK && retry--) {
|
while(HAL_SD_Init(&SDHandle, &cardinfo) != SD_OK && retry--) {
|
||||||
if (retry == 0) {
|
if (retry == 0) {
|
||||||
return false;
|
__fatal_error("Failed to init sdcard: init timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
systick_sleep(100);
|
systick_sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure the SD Card in wide bus mode. */
|
/* Configure the SD Card in wide bus mode. */
|
||||||
if (HAL_SD_WideBusOperation_Config(&SDHandle, SDIO_BUS_WIDE_4B) != SD_OK) {
|
if (HAL_SD_WideBusOperation_Config(&SDHandle, SDIO_BUS_WIDE_4B) != SD_OK) {
|
||||||
return false;
|
__fatal_error("Failed to init sensor, sdcard: config wide bus");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure and enable DMA IRQ Channel
|
// Configure and enable DMA IRQ Channel
|
||||||
@ -116,6 +108,13 @@ bool sdcard_power_on(void)
|
|||||||
// preempt the DMA irq handler to set a flag indicating the end of transfer.
|
// preempt the DMA irq handler to set a flag indicating the end of transfer.
|
||||||
HAL_NVIC_SetPriority(SDIO_IRQn, IRQ_SDIO_PRE_PRI, IRQ_SDIO_SUB_PRI);
|
HAL_NVIC_SetPriority(SDIO_IRQn, IRQ_SDIO_PRE_PRI, IRQ_SDIO_SUB_PRI);
|
||||||
HAL_NVIC_EnableIRQ(SDIO_IRQn);
|
HAL_NVIC_EnableIRQ(SDIO_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sdcard_power_on(void)
|
||||||
|
{
|
||||||
|
if (!sdcard_is_present()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user