2019-04-08 11:49 PM
Hi everybody,
I've got an STM32H743XI and use the Cube V1.3.2 Firmware for an project for my master thesis.
To this controller I have connected a SD Card with the SDMMC controller using the 4 bit bus. I also use FreeRtos and don't want a blocking read or write to the card.
Therefore I added a Freertos Notification that the Interrupt wakes up the thread who has written to the card. The thread has the highest priority and will be called 5 µs after the transfer complete interrupt. After I have written one time the SD structure State is HAL_SD_STATE_READY but the ErrorCode is 1 which should mean SDMMC_ERROR_CMD_CRC_FAIL.
This is the code which produces the fault.
/* Function to write to the SD Card */
void WriteToSDCard(uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
{
uint32_t ulNotificationValue;
xTaskToNotify = xTaskGetCurrentTaskHandle();
HAL_SD_WriteBlocks_DMA(&hsd1, pData, BlockAdd, NumberOfBlocks);
ulNotificationValue = ulTaskNotifyTake( pdTRUE, 1000000); //Wait for the Interrupt
if(ulNotificationValue == 0)
{
Error_Handler();
}
if(Wait_SDCARD_Ready() != HAL_OK)
{
Error_Handler();
}
}
/* Function from the Example */
static uint8_t Wait_SDCARD_Ready(void)
{
uint8_t retval = HAL_ERROR;
uint32_t loop = ((uint32_t)0x01000000U);
/* Wait for the Erasing process is completed */
/* Verify that SD card is ready to use after the Erase */
while(loop > 0)
{
loop--;
if(HAL_SD_GetCardState(&hsd1) == HAL_SD_CARD_TRANSFER)//HAL_SD_CARD_TRANSFER
{
retval = HAL_OK;
break;
}
}
return retval;
}
/**
* @brief Tx Transfer completed callbacks
* @param hsd: SD handle
* @retval None
*/
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR( xTaskToNotify, &xHigherPriorityTaskWoken ); //Free the thread
xTaskToNotify = NULL;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
This Code doesn't work because of the CRC error.
If I write and read from the SD Card like in the example SD_ReadWrite_DMA and call the function Wait_SDCARD_Ready() inside the interrupt, everything works fine an I achive an read and write speed of about 20 MBytes/s. But this means, when I measure the time, the function Wait_SDCARD_Ready() waits 1 ms in the interrupt and blocks the FreeRtos threads.
This is the Code which works.
/* Write Function */
void WriteToSDCard(uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
{
uint32_t ulNotificationValue;
xTaskToNotify = xTaskGetCurrentTaskHandle();
HAL_SD_WriteBlocks_DMA(&hsd1, pData, BlockAdd, NumberOfBlocks);
ulNotificationValue = ulTaskNotifyTake( pdTRUE, 1000000);
if(ulNotificationValue == 0)
{
Error_Handler();
}
}
/* Function from the example Project*/
static uint8_t Wait_SDCARD_Ready(void)
{
uint8_t retval = HAL_ERROR;
uint32_t loop = ((uint32_t)0x01000000U);
/* Wait for the Erasing process is completed */
/* Verify that SD card is ready to use after the Erase */
while(loop > 0)
{
loop--;
if(HAL_SD_GetCardState(&hsd1) == HAL_SD_CARD_TRANSFER)//HAL_SD_CARD_TRANSFER
{
retval = HAL_OK;
break;
}
}
return retval;
}
/**
* @brief Tx Transfer completed callbacks
* @param hsd: SD handle
* @retval None
*/
void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
{
if(Wait_SDCARD_Ready() != HAL_OK)
{
Error_Handler();
}
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR( xTaskToNotify, &xHigherPriorityTaskWoken );
xTaskToNotify = NULL;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
Can someone please explain me, why I get CRC errors, when I call the Wait_SDCARD_Ready() function outside of the interrupt, but 5 µs later inside the thread?
Best regards,
Max
2019-04-26 03:17 AM
Hello,
does anyone have an idea because of my problem?
Best regards,
Max
2020-12-09 04:49 PM
Im so sorry that u are ignored by st. change 2 another micro processor like TI may be a better idea.