30 static uint32_t timeOut, xfersPrMsec;
36 static uint8_t WaitReady(
void)
42 retryCount = 500 * xfersPrMsec;
45 while ((res != 0xFF) && --retryCount);
65 xfersPrMsec = MICROSD_LO_SPI_FREQ / 8000;
74 #if defined( USART_CTRL_SMSDELAY )
76 MICROSD_USART->CTRL |= USART_CTRL_SMSDELAY;
127 GPIO->P[ MICROSD_GPIOPORT ].DOUTSET = 1 << MICROSD_CSPIN;
137 GPIO->P[ MICROSD_GPIOPORT ].DOUTCLR = 1 << MICROSD_CSPIN;
138 if (WaitReady() != 0xFF)
182 uint32_t retryCount, framectrl, ctrl;
185 retryCount = 100 * xfersPrMsec;
189 }
while ((token == 0xFF) && --retryCount);
198 framectrl = MICROSD_USART->FRAME;
199 ctrl = MICROSD_USART->CTRL;
209 if ( timeOut >= btr + 2 )
221 MICROSD_USART->TXDOUBLE = 0xffff;
224 MICROSD_USART->TXDOUBLE = 0xffff;
228 val = MICROSD_USART->RXDOUBLE;
237 MICROSD_USART->RXDOUBLE;
240 MICROSD_USART->FRAME = framectrl;
241 MICROSD_USART->CTRL = ctrl;
258 uint32_t framectrl, ctrl;
260 if (WaitReady() != 0xFF)
274 framectrl = MICROSD_USART->FRAME;
275 ctrl = MICROSD_USART->CTRL;
285 if ( timeOut >= bc + 2 )
304 MICROSD_USART->TXDOUBLE = val;
310 MICROSD_USART->TXDOUBLE = 0xFFFF;
318 MICROSD_USART->FRAME = framectrl;
319 MICROSD_USART->CTRL = ctrl;
323 if ((resp & 0x1F) != 0x05)
390 }
while ((res & 0x80) && --retryCount);
402 xfersPrMsec = MICROSD_LO_SPI_FREQ / 8000;
411 xfersPrMsec = MICROSD_HI_SPI_FREQ / 8000;
424 timeOut = xfersPrMsec * msec;
Clock management unit (CMU) API.
void MICROSD_Init(void)
Initialize the SPI peripheral for microSD card usage. SPI pins and speed etc. is defined in microsdco...
void USART_InitSync(USART_TypeDef *usart, const USART_InitSync_TypeDef *init)
Init USART for synchronous mode.
#define USART_CTRL_BYTESWAP
void USART_BaudrateSyncSet(USART_TypeDef *usart, uint32_t refFreq, uint32_t baudrate)
Configure USART operating in synchronous mode to use a given baudrate (or as close as possible to spe...
#define USART_CMD_CLEARRX
#define USART_STATUS_TXBL
#define USART_FRAME_DATABITS_SIXTEEN
Micro SD card driver for the EFM32GG_DK3750 development kit.
#define USART_ROUTE_CLKPEN
Universal synchronous/asynchronous receiver/transmitter (USART/UART) peripheral API.
void MICROSD_SpiClkSlow(void)
Set SPI clock to a low frequency suitable for initial card initialization.
#define USART_ROUTE_RXPEN
void MICROSD_PowerOn(void)
Turn on micro SD card power. DK doesn't support socket power control, only enable the SPI clock...
void MICROSD_Deinit(void)
Deinitialize SPI peripheral. Turn off the SPI peripheral and disable SPI GPIO pins.
void MICROSD_Deselect(void)
Deselect the micro SD card and release the SPI bus.
int MICROSD_Select(void)
Select the micro SD card and wait for the card to become ready.
bool MICROSD_TimeOutElapsed(void)
Check if timeout value set with MICROSD_TimeOutSet() has elapsed.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
void MICROSD_SpiClkFast(void)
Set SPI clock to maximum frequency.
void MICROSD_TimeOutSet(uint32_t msec)
Set a timeout value. The timeout value will be decremented towards zero when SPI traffic to/from the ...
#define _USART_FRAME_DATABITS_MASK
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define USART_STATUS_RXDATAV
int MICROSD_BlockTx(const uint8_t *buff, uint8_t token)
Send a data block to micro SD card.
void USART_Reset(USART_TypeDef *usart)
Reset USART/UART to same state as after a HW reset.
uint8_t USART_SpiTransfer(USART_TypeDef *usart, uint8_t data)
Perform one 8 bit frame SPI transfer.
void MICROSD_PowerOff(void)
Turn off micro SD card power. DK doesn't support socket power control, only disable the SPI clock...
uint8_t MICROSD_SendCmd(uint8_t cmd, DWORD arg)
Send a command packet to micro SD card.
#define USART_ROUTE_TXPEN
int MICROSD_BlockRx(uint8_t *buff, uint32_t btr)
Receive a data block from micro SD card.
#define USART_INITSYNC_DEFAULT
uint8_t MICROSD_XferSpi(uint8_t data)
Do one SPI transfer.
#define USART_CMD_CLEARTX