Closed minihant closed 4 years ago
did you open the I2C driver first using DRV_I2C_Open API?
did you open the I2C driver first using DRV_I2C_Open API?
Yes, I Do the DRV_I2C_Open before I do the I2C device Write & Read
can you debug inside your DRV_I2C_WriteTransfer API and see why is it returning false? it will return false only when: clientObj = NULL or transfer size = 0 or transfer buffer = NULL.
check if Open function has returned the valid handle or not. if yes, then the same handle should be passed as the first argument to DRV_I2C_WriteTransfer API. you can have a look at some demos using I2C driver in synch mode at following location: core\apps\driver\i2c\sync
I use the cryptoauthlib\lib\hal\hal_pic32mz2048efmI2c.c API. after the hal_i2c_init(), then call the hal_i2c_wake() API. But I need to modify the hal_i2c_wake() to meet the HMC3 for "DRV_I2C.c" here is the modify function: ATCA_STATUS hal_i2c_wake(ATCAIface iface) { DRV_I2C_Object tempI2cObj; ATCAIfaceCfg cfg = atgetifacecfg(iface); uint8_t data[4]; DRV_I2C_TRANSFER_EVENT Rx_Transaction = DRV_I2C_TRANSFER_EVENT_ERROR; data[0] = 0x00;
if(DRV_I2C_WriteTransfer(drvI2CMasterHandle, cfg->atcai2c.slave_address, (void*)data, 1) == false)
{
LED_ACT_On();
}
atca_delay_us(cfg->wake_delay); // wait tWHI + tWLO which is configured based on device type and configuration structure
if( DRV_I2C_ReadTransfer(drvI2CMasterHandle, cfg->atcai2c.slave_address, (void*)data, 4)== false)
{
do
{
Rx_Transaction = DRV_I2C_Status(drvI2CMasterHandle);
} while (Rx_Transaction != SYS_STATUS_READY);
}
return hal_check_wake(data, 4);
} //======================= During Debug, it always do the LED_ACT_On(); that means the DRV_I2C_WriteTransfer() always fail.
Then I debug into DRV_I2C_WriteTransfer() --> in DRV_I2C.c "isSuccess= true " never happened :
//----------------------------------------------------- bool DRV_I2C_WriteTransfer(……) { bool isSuccess = false; …………………. if (hDriver->i2cPlib->write(address, buffer, size) == true) { / Wait till transfer completes. This semaphore is released from ISR / if (OSAL_SEM_Pend( &hDriver->transferDone, OSAL_WAIT_FOREVER ) == OSAL_RESULT_TRUE) { if (hDriver->transferStatus == DRV_I2C_TRANSFER_STATUS_COMPLETE) { isSuccess = true; } } } / Release the mutex to allow other threads to access the PLIB / OSAL_MUTEX_Unlock( &hDriver->transferMutex); } } return isSuccess; }
The cryptoauthlib\lib\hal\hal_pic32mz2048efmI2c.c is working fine in HMC2 . Then I check the difference of drv_i2c.c between HMC2 & HMC3. It is totally different .
in Harmony 3 most of the drivers have two versions:
i guess for hal, you want to use async version of I2C driver, not the sync version. transfer APIs are different for async and sync versions. for async version, APIs are:
you may want to use these APIs for porting. go through the Harmony 3 help document for more details on the same.
DRV_I2C_WriteTransferAdd
I use RTOS, so I use the Sync version, and it support in Harmony 2.06. And I am sure the HAL function working fine in Harmony2 in PIC32MZ because I can successful porting the cryptoauthlib to access ECC508A with RTOS in Sync mode. As I debug into the drv_I2c.c and found the "isSuccess = true" never happen. Can you try to use Harmony 3 to access ECC508 with RTOS with PIC32MZ family?
are you really sure Harmony v2.06 has synch driver support? i don't think it has. it has RTOS support, but for async driver only. in fact there is nothing called sync driver in Harmony v2.06, not for I2C driver at least.
anyway, as you are debugging, can you tell me because of which conditions failure, "isSuccess = true" is not happening and control is going out of the "DRV_I2C_WriteTransfer" API?
which RTOS are you using? have you allocated enough heap?
arpananand1 : Thanks for your reply. I use cryptoauthlib which is released from Microchip.https://microchiptech.github.io/cryptoauthlib/html/index.html It indeed support RTOS to access I2C driver.
When I call to DRV_I2C_WriteTransfer(), DRV_I2C_ReadTransfer() both of them return false from i2cPlib
if (hDriver->i2cPlib->write(address, buffer, size) == true) { / Wait till transfer completes. This semaphore is released from ISR / if (OSAL_SEM_Pend( &hDriver->transferDone, OSAL_WAIT_FOREVER ) == OSAL_RESULT_TRUE) { if (hDriver->transferStatus == DRV_I2C_TRANSFER_STATUS_COMPLETE) { isSuccess = true; } } }
The RTOS version is FREERTOS V10.0.1, heap size is 65535 in FreeRTOSConfig.h
No news on this issue since a while. @minihant, I close it for now but feel free to reopen it if the issue is still present.
@minihant Did you solve this issue? I get the same error Harmony 3 synchronous I2C driver on the same line that you mentioned
if (hDriver->i2cPlib->write(address, buffer, size) == true) { / Wait till transfer completes. This semaphore is released from ISR / if (OSAL_SEM_Pend( &hDriver->transferDone, OSAL_WAIT_FOREVER ) == OSAL_RESULT_TRUE) { if (hDriver->transferStatus == DRV_I2C_TRANSFER_STATUS_COMPLETE) { isSuccess = true; } } }
Thanks in advance!
I try to add ECC508A cryptoauthlib into the HMC 3 project. And found the DRV_I2C.c --> DRV_I2C_WriteTransfer --> always return false .
This issue cause the I2c device Read & write fail.
Please help to verify it . Thanks!