Scenario: RT1064 with FreeRTOS and SDK 2.8.2
I'm facing some issues using the LPI2C peripheral with eDMA - I've used the sdk example "evkmimxrt1064_lpspi_edma_b2b_transfer_master" as reference.
The transfer is working properly, for reading and writing a slave device in the bus.
But when I try to read some data from a device address that is not present in the bus, the problems start. The transmission, of course, finishes with a NAK: Start + Slave Address + NAK + Stop.
Problems:
1) The callback is not called when some errors happen. The callback is tied to the eDMA channel completion trigger, and probably in case of errors like this, the transmission was not completed and the callback is never called. In my standpoint, the callback should be called even in case of error, because we need to handle it.
2) Ok, we can workaround this with an LPI2C IRQ in case of error. Then the most logical path would be call "LPI2C_MasterTransferAbortEDMA" to clear the transfer handlers, FIFOs, DMA TCD, etc so the device is ready for a new transfer. This function correctly clears the FIFOs but then sends a Stop command to the bus, which will be kept in the TX FIFO buffer because there are error flags set in the LPI2C peripheral. In the next transaction, when the error flags are cleared, immediately the MSR->FEF will be raised since we are trying to transmit a Stop without a Start. By the way, the AUTOSTOP bit is not set.
I can see there function "LPI2C_MasterEDMACallback" can handle some errors, the problem is that it will not be called in some errors, like this when the transfer is not completed. That would need a proper fix. And the "LPI2C_MasterTransferAbortEDMA" should check if there is any ongoing transaction before sending the stop.
Am I doing something wrong in the procedure?
Cheers.
Alex