2020-10-20 7:10 AM
Hello,
I am currently using a STM32F030CCT6 with the STM32F0xx_HAL_DRIVER generated by CubeMx. The version of the driver/cube is STM32Cube_FW_F0_V1.10.0.
In my program, I have a low priority task that calls HAL_I2C_Mem_Read_IT. This function is interrupt based and therefore I should have no problem completing the I2C request. However, once in a while I get a timeout. I investigated that timeout and found out that my task get switch during the call to HAL_I2C_Mem_Read_IT.
Going into HAL_I2C_Mem_Read_IT, I see that this function is called I2C_RequestMemoryRead. This function is responsible to send the device address and the memory address. When looking into the implementation I found that this function is not interrupt based!
I get a timeout when the task switch during I2C_RequestMemoryRead!
I was wondering if there was a particular reason why the function I2C_RequestMemoryRead is not interrupt based? Is this wanted? Is there a driver that implements I2C_RequestMemoryRead with interrupts?
Thank you!
2020-10-20 3:00 PM
HAL support for I2C in interrupt mode just isn't well implemented. Probably partly because the I2C peripheral and protocol is relatively complicated compared to UART/SPI.
The F4 library seems to not have this drawback at a glance. You could try porting:
In the CubeF4 repo, HAL_I2C_Mem_Read_DMA seems to rely on I2C_RequestMemoryRead, but HAL_I2C_Mem_Read_IT does not.
No idea how common those two peripherals are.
2020-10-21 4:19 AM
Thank you for the quick answer!
I added a critical section for the call to "HAL_I2C_Mem_Read_IT" to prevent task switching it did the job. Would of like a cleaner solution but I am not willing at this moment to modify the hal driver to have everything in interrupts.
However, the point that you bring is a good one and anyone could try and implement the F4 driver into the F1. The driver is quite different. I can see the the "I2C_HandleTypeDef *hi2c" as new members suchs as: "Devaddress", "Memaddress","MemaddSize". But I am guessing that the architecture could be reproduce into the F0 and make " HAL_I2C_Mem_Read_IT" completely in interrupt.
In the mean time, I also notice that the function "HAL_I2C_IsDeviceReady" is not interrupt based. It is not declared at so, but if you want to have everything in interrupt this function should probably also be modified.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.