MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / efm_spiSd_init

Function efm_spiSd_init

bsp/efm32/drv_sdcard.c:1195–1240  ·  view source on GitHub ↗

/ * @brief * Initialize all memory card related hardware and register the device to * kernel * * @details * * @note * * @return * Error code ******************************************************************************/

Source from the content-addressed store, hash-verified

1193* Error code
1194******************************************************************************/
1195rt_err_t efm_spiSd_init(void)
1196{
1197 struct efm32_usart_device_t *usart;
1198
1199 do
1200 {
1201 /* Find SPI device */
1202 spi = rt_device_find(SPISD_USING_DEVICE_NAME);
1203 if (spi == RT_NULL)
1204 {
1205 sdcard_debug("SPISD: Can't find device %s!\n",
1206 SPISD_USING_DEVICE_NAME);
1207 break;
1208 }
1209 sdcard_debug("SPISD: Find device %s\n", SPISD_USING_DEVICE_NAME);
1210
1211 /* Config chip slect pin */
1212 usart = (struct efm32_usart_device_t *)(spi->user_data);
1213 if (!(usart->state & USART_STATE_AUTOCS))
1214 {
1215 GPIO_PinModeSet(SD_CS_PORT, SD_CS_PIN, gpioModePushPull, 1);
1216 sdAutoCs = false;
1217 }
1218
1219 /* Register SPI SD device */
1220 sd_device.type = RT_Device_Class_MTD;
1221 sd_device.init = rt_spiSd_init;
1222 sd_device.open = rt_spiSd_open;
1223 sd_device.close = rt_spiSd_close;
1224 sd_device.read = rt_spiSd_read;
1225 sd_device.write = rt_spiSd_write;
1226 sd_device.control = rt_spiSd_control;
1227 sd_device.user_data = RT_NULL;
1228 rt_device_register(
1229 &sd_device,
1230 SPISD_DEVICE_NAME,
1231 RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
1232
1233 sdcard_debug("SPISD: HW init OK, card type %x\n", sdType);
1234 return RT_EOK;
1235 } while (0);
1236
1237 /* Release buffer */
1238 rt_kprintf("SPISD: HW init failed!\n");
1239 return -RT_ERROR;
1240}
1241
1242/***************************************************************************//**
1243 * @brief

Callers 1

rt_application_initFunction · 0.85

Calls 4

rt_device_findFunction · 0.85
GPIO_PinModeSetFunction · 0.85
rt_device_registerFunction · 0.85
rt_kprintfFunction · 0.85

Tested by

no test coverage detected