2025-02-21 12:34 AM - edited 2025-02-21 12:36 AM
Hello,
i need help how to share I2C in DMA mode between two FreeRTOS tasks.
I have two tasks:
Task 1:
osMutexAcquire(I2C1_MutexHandle, HAL_MAX_DELAY);
Task_Notification_I2C1 = WM8731;
configASSERT(xTaskToNotifyI2C1_WM8731 == NULL );
xTaskToNotifyI2C1_WM8731 = xTaskGetCurrentTaskHandle();
Status = HAL_I2C_Master_Transmit_DMA(&hi2c1, (uint16_t)WM8731_I2C_ADDRESS, data, 2);
ulNotificationValue = ulTaskNotifyTake(pdFALSE, HAL_MAX_DELAY);
if(ulNotificationValue)
osMutexRelease(I2C1_MutexHandle);
else
DEBUGOUT("WM8731_Set_Register I2C timeout...\r\n");
Task 2:
osMutexAcquire(I2C1_MutexHandle, HAL_MAX_DELAY);
Task_Notification_I2C1 = FT5426;
configASSERT(xTaskToNotifyI2C1_FT5426 == NULL );
xTaskToNotifyI2C1_FT5426 = xTaskGetCurrentTaskHandle();
Status = HAL_I2C_Master_Receive_DMA(&hi2c1, (uint16_t)FT5426_I2C_ADDRESS, data, 64);
ulNotificationValue = ulTaskNotifyTake(pdFALSE, HAL_MAX_DELAY);
if(ulNotificationValue)
osMutexRelease(I2C1_MutexHandle);
else
DEBUGOUT("FT5426_Read_Complete I2C timeout...\r\n");
And ISR:
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if(hi2c->Instance == I2C1)
{
if(xTaskToNotifyI2C1_WM8731 != NULL)
{
configASSERT( xTaskToNotifyI2C1_WM8731 != NULL );
vTaskNotifyGiveFromISR(xTaskToNotifyI2C1_WM8731, &xHigherPriorityTaskWoken);
xTaskToNotifyI2C1_WM8731 = NULL;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
else if(xTaskToNotifyI2C1_FT5426 != NULL)
{
configASSERT( xTaskToNotifyI2C1_FT5426 != NULL );
vTaskNotifyGiveFromISR(xTaskToNotifyI2C1_FT5426, &xHigherPriorityTaskWoken);
xTaskToNotifyI2C1_FT5426 = NULL;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
}
That isnt working. The mutex cannot be acquired by second task so it is in blocked state.
I dont want to use additional task for handling I2C1, i would like to use notification from ISR.
Any ideas?
Thanks