2025-02-02 04:42 PM
Hello,
I've been playing with the U585 IOT dev board and really enjoying it, I've got I2C communicating with the sensors without DMA and now I would like to test out the GPDMA. However, there is a little more too this DAM controller then the DMA on the older STM32s which is what I'm used too.
I've done the bellow configuration in MX and I'm then calling HAL_I2C_Mem_Read_DMA, while HAL_I2C_Mem_Read works fine HAL_I2C_Mem_Read_DMA returns HAL ok but the data value, which should be 179 from the Who_Am_I reg of the LSP22HH, remains 0. I'm guessing my issuse is with my GPDMA config since I have not used it before.
uint32_t I2C_Read(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len) {
return HAL_I2C_Mem_Read_DMA(&I2C_Handle, address, reg, I2C_MEMADD_SIZE_8BIT, data, len);
}
Another question I have is what are the callback functions I need to define for TX/RX Cplt?
Cheers,
Michael
2025-02-03 02:55 AM
Hello @WrenchInTheWorks
Please refer to this example to make your DMA settings work.
For the callback function, you can implement the weak functions (One for read and one for write) below:
__weak void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hi2c);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_I2C_MemTxCpltCallback could be implemented in the user file
*/
}
/**
* @brief Memory Rx Transfer completed callback.
* @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
* the configuration information for the specified I2C.
* @retval None
*/
__weak void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hi2c);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_I2C_MemRxCpltCallback could be implemented in the user file
*/
}
2025-02-03 05:54 AM
Hello @Saket_Om,
Thanks for your help, I appreciate you taking the time. I have had a look through the U575 example, good thinking, I had not considerd having a look at example from a different U5. The first thing I notice is the use of linked-lists, is this needed for I2C? I had a skim read through AN5593 (quite daunting but I guess you only take what you need) and it does not seam to say if linked lists are strictly needed for I2C. Apart from the use of linked lists, my settings I have been using are identical (see Bellow). I did take note of the call to __HAL_LINKDMA in the example you provided and thought that might be my problem but I found that call in the HAL_I2C_MspInit function of my code.
I have also just tried using linked lists and I have not had any success there either, see my modifed test code and MX configs bellow.
/* USER CODE BEGIN 2 */
MX_Queue_tx_Config();
HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel6, &Queue_tx);
__HAL_LINKDMA(&hi2c2, hdmatx, handle_GPDMA1_Channel6);
MX_Queue_rx_Config();
HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel5, &Queue_rx);
__HAL_LINKDMA(&hi2c2, hdmarx, handle_GPDMA1_Channel5);
uint8_t data;
volatile HAL_StatusTypeDef status = HAL_I2C_Mem_Read_DMA(&hi2c2, 0xBB, 0x0F, I2C_MEMADD_SIZE_8BIT, &data, 1);
/* USER CODE END 2 */
My next step would be to start poking around the RAM and device registers to see if the DMA is actaully moving the values to the approprite place in the I2C controller, but that feels like a very difficult and extreme measure. Hopfully you have some more insite you can offer.
Cheers,
Michael
2025-02-04 12:01 AM - edited 2025-02-04 12:06 AM
Hello @WrenchInTheWorks
The use of linked lists in DMA is not strictly required for I2C communication. Instead, it depends on the specific requirements and configuration of your DMA and I2C operations.
To use the DMA in standard mode with I2C, please refer to the article "How to configure the GPDMA". In this article, we describe the necessary steps to configure GPDMA in standard mode for UART transmission. You can adapt it to your I2C application.
You can also look at the example Projects/NUCLEO-H743ZI/Examples/I2C/I2C_TwoBoards_ComDMA, which uses DMA in standard mode for I2C communication.
If your issue didn't get solved, please consider sharing your entire project with us so we can support you more effectively.
>> My next step would be to start poking around the RAM and device registers to see if the DMA is actaully moving the values to the approprite place in the I2C controller, but that feels like a very difficult and extreme measure. Hopfully you have some more insite you can offer.
To test if your DMA is transmitting the data, you can change the setting to "Memory to memory transmission" and then check if your data has moved to the destination.
2025-02-08 10:48 PM
Hello @Saket_Om,
Unfortunately no success. I'm testing with a very simple program now, works without DMA but the DMA functions don't work. I will include ther ZIP of the project bellow and a screenshot of my output. I'm unsure why the termnal is displaying extra lines but thats not the main problem here. Thanks again for your help!
Cheers,
Michael