LPC865 SDK 2.16 I2C DMA driver problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC865 SDK 2.16 I2C DMA driver problem

809 次查看
SALapilli
Contributor I
In the LPC865 SDK, when using DMA mode in the I2C driver, the driver fsl_i2c_dma.h defines the variable static i2c_isr_t s_i2cMasterIsr; and correctly initializes it to point to I2C_MasterTransferDMAHandleIRQ. However, the ISR routine I2C_TransferCommonIRQHandler (which uses s_i2cMasterIsr) is found in the module fsl_i2c.c which also has a static variable s_i2cMasterIsr declared but not initialized because DMA mode is being used, resulting in a Hard Fault with a NULL pointer. I believe the s_i2cMasterIsr variable should not be static, or a better solution would be to have a setter for the s_i2cMasterIsr variable in the fsl_i2c.c module that is called from fsl_i2c_dma.c to correctly instantiate the ISR.
标记 (1)
0 项奖励
回复
3 回复数

783 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @SALapilli 

Thanks for your sharing. 

The IRQ handler s_i2cMasterIsr is assigned differently depending on the function used.

For I2C without DMA, the I2C_MasterTransferCreateHandle() function is used:

/* Save master interrupt handler. */
s_i2cMasterIsr = I2C_MasterTransferHandleIRQ;

For I2C with DMA, the I2C_MasterTransferCreateHandleDMA() function is used instead.

Therefore, different APIs are called based on whether DMA is utilized or not.


 

BR

Alice

0 项奖励
回复

761 次查看
SALapilli
Contributor I
Yes, I have done everything you explained. The problem is that the interrupt service routine "I2C0_DriverIRQHandler" is in the module "fsl_i2c.c" and uses a static pointer to the specific routine. When calling the routine "I2C_MasterTransferCreateHandleDMA", it alter the static pointer "s_i2cMasterIsr" within the module "fsl_i2c_dma.c", and therefore it does not alter the value of the pointer of the same name "s_i2cMasterIsr" present in the module "fsk_i2c.c", which is the one used by the IRQ.
I have defined the following routine within "fsl_i2c.c":
void Setteri2cMasterIsr(uint32_t instance,void * handle,i2c_isr_t pRut)
{
s_i2cHandle[instance] = handle;
s_i2cMasterIsr = pRut;
}

And I call it from the routine "I2C_MasterTransferCreateHandleDMA" in the module "fsl_i2c_dma.c"

This solves the problem. Please fix the automatic code generator in the SDK to correctly modify the routine pointer so it is not left undefined and does not end in a HARD FAULT. To reproduce the SDK BUG, simply create a project with i2c DMA, which compiles perfectly but ends in a HARD FAULT when trying to run it.
0 项奖励
回复

723 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @SALapilli 

I really appreciate your sharing. We will analysis and reported it to SDK development team.

Sorry for the inconvenient to you.

 

BR

Alice

0 项奖励
回复