How do I get FatFS working on a NucleoH7A3?
I've been struggling to get FatFs working on a NucleoH7A3 board for a while. I built a little board with a uSD card connector that plugs into the Arduino connectors on the Nucleo board. The pins for the uSD card connector are connected to the same GPIO lines on the NucleoH7A3 as are used on the H7B3I Discovery board for its built in uSD connector. My Nucleo/uSD board works with the H7B3I Discovery board FatFs_uSD_DMA_Standalone example. But I haven't been able to build a project that works from scratch using STM32CubeIDE as in this video: https://www.youtube.com/watch?v=I9KDN1o6924 . f_mount returns FR_OK but f_mkfs returns FR_DISK_ERR. If I format the uSD card on my PC and comment out the f_mkfs command, the f_open command returns FR_DISK_ERR.
One difference from the video example is there doesn't seem to be an option to enable DMA for the H7 in the SDMMC1 configuration. According to the H7 data sheet, the SDMMC interface has a dedicated DMA controller. Does that mean there's no configuration required and I don't have to do anything to get DMA on the SDMMC? Just in case, I've tired enabling and disabling the DMA template in the FATFS configuration but neither way works.
Is there something unique about the H7 that makes it different than the F7?
int main(void)
{
/* USER CODE BEGIN 1 */
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = "STM32 FATFS works great!"; /* File write buffer */
uint8_t rtext[_MAX_SS];/* File read buffer */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
// MX_UART4_Init();
// MX_USART2_UART_Init();
// MX_USART3_UART_Init();
// MX_UART5_Init();
// MX_USART6_UART_Init();
// MX_UART7_Init();
// MX_UART9_Init();
// MX_USART10_UART_Init();
// MX_BDMA2_Init();
// MX_I2C4_Init();
// MX_I2C2_Init();
// MX_LPUART1_UART_Init();
/* USER CODE BEGIN 2 */
res = f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
if(res != FR_OK)
{
Error_Handler();
}
else
{
// res = f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext));
// if(res != FR_OK)
// {
// Error_Handler();
// }
// else
{
//Open file for writing (Create)
res = f_open(&SDFile, "mySTM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
if(res != FR_OK)
{
Error_Handler();
}
else
{
//Write to the text file
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
Error_Handler();
}
else
{
f_close(&SDFile);
}
}
}
}
f_mount(&SDFatFS, (TCHAR const*)NULL, 0);