How do I program my STM32L4R9 with SDMMC and FatFS?
Hello,
I would like to write a simple program for writing CSV files to a micro SD card on a custom board I made with my STM32L4R9. The card works on 3.3V and my STM on 1.8V, so I'm using a level shifter.
For now, I selected SDMMC1 4 bits wide bus and FatFS. Next, I tried basing myself on the example code for the evaluation board (STM32L4R9I-Discovery), but I get an error when the function SD_PowerOn() (on file stm32l4xx_hal_sd.c) is called. Specifically, I get a timeout error on this line:
/* SEND CMD55 APP_CMD with RCA as 0 */
errorstate = SDMMC_CmdAppCommand(hsd->Instance, 0);
if(errorstate != HAL_SD_ERROR_NONE)
{
return errorstate;
}And my main looks like this:
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
FRESULT res;
res = f_mkfs(SDPath, FM_ANY, 0, workBuffer, sizeof(workBuffer)); // This is where I get problems
if (res != FR_OK)
{
Error_Handler();
}I cannot get past the f_mkfs() function call.
I also could not take the examples for the STM32L476 on the forum as they rely on DMA interruptions, and I also do not know how to configure them on my STM32L4+, as the SDMMC has its own connection to the DMA bus.
As a design error, I cannot detect when a card is plugged in (the signal from the connector is missing on the board).
Does anyone know what config I shoud use on CubeMX and what functions I should call?
