s32k144 FreeRTOS + I2C

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

s32k144 FreeRTOS + I2C

13,775件の閲覧回数
alice_th
Contributor III

i find this LPI2C_DRV_MasterSendDataBlocking can't used under freertos task,

read is always return 2, seems when write i2c is always busy, can anybody help to check it ?

i2c_test11,TMF882X_STAT=0
tmf882x_i2c_write ret=0
tmf882x_i2c_read,fisrt ret1=0,second ret2=2,recv=0

BTW, when use without freertos i can read i2c slave data correctly.

int test_tmf882x_i2c_read(uint32_t slave_addr, uint8_t reg, uint8_t *buf, int len)
{
//return read_i2c_block(slave_addr, reg, buf, len);
int ret1,ret2;
ret1 = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, &reg, 1, false, I2C_TIME_OUT);

ret2 = LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buf, len, true,I2C_TIME_OUT);
AMS_TOF_LOG("tmf882x_i2c_read,fisrt ret1=%d,second ret2=%d,recv=%d\n",ret1,ret2,*buf);
return ret2;
}

int test_tmf882x_i2c_write(uint32_t slave_addr, uint8_t reg, uint8_t *buf, int len)
{

int i,ret;
uint8_t send[len+1];
send[0] = reg;
if(len == 1)
send[len] = *buf;
else
{
for(i=0;i<len;i++)
send[i+1] = buf[i];
}
ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, send, len+1, true,I2C_TIME_OUT);
AMS_TOF_LOG("tmf882x_i2c_write ret=%d\n",ret);
return 0;
}
void i2c_test11()
{
uint8_t send[2];
uint8_t recv[2];
recv[0] = 0x80;
recv[1] = 0x90;
uint8_t regval = 0;
LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1,0x39,false);
while(1)
{
regval = 0x03;
test_tmf882x_i2c_write(0x39,0x80,&regval, 1);
regval = 0x00;
test_tmf882x_i2c_read(0x39,0x80, &regval, 1);
printf("i2c_test11,TMF882X_STAT=%x\n",regval);

}
}
int main (void)
{
//initialize System
lpi2c_master_state_t lpi2c1MasterState;
init_sys ();
//WDOG_disable();
// sensor_interface_init();
LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0,&lpi2c1MasterState);
enable_fault_handlers(); // If not set, all fault are handled by HardFault_Handler
set_fault_handlers_priority(); // priority: MemManage (1), BusFault (1), UsageFault(1)
LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1,I2C_SLAVEADDR,false);
INT_SYS_SetPriority( LPI2C0_Master_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1 );
//while(1)
{

//tof882x_init();
//i2c_test11();
//flash_read_write_test();
}
rtos_start();

return exit_code;
}

0 件の賞賛
返信
33 返答(返信)

9,929件の閲覧回数
alice_th
Contributor III

can any NXP mcu team members help this case, thanks!

0 件の賞賛
返信

9,910件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hi @alice_th,

What are the FreeRTOS and S32K1 packages you are using?

Best regards,

Dan

タグ(1)
0 件の賞賛
返信

9,893件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

i attached the project here, two issues 

1. i2c always busy with rtos(without rtos i2c read data ok)

logs below:
prvQueueSendTask=0
test_i2c000 tmf882x_i2c_read,fisrt ret1=2,second ret2=2,recv=0
prvQueueSendTask,value=0
prvQueueReceiveTask=0
prvQueueSendTask=0
test_i2c000 tmf882x_i2c_read,fisrt ret1=2,second ret2=2,recv=0
prvQueueSendTask,value=0
prvQueueReceiveTask=0

2. when add more task , like prvTestTask / prvNewTestTask, it will blocked, i think it should be printf issue.

please help to check it, thank you!

0 件の賞賛
返信

9,772件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hi @alice_th,

I saw that you haven't yet installed the "LPI2C0_Master_IRQHandler" (interrupt function) for I2C Master.

Could you install this interrupt function and re-test your example?

Best regards,

Dan

0 件の賞賛
返信

9,855件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hello @alice_th,

Please provide the name of the S32DS versions you are using.

And what are the FreeRTOS package's name and the S32K1 package's name you are using?

Best regards,

Dan

0 件の賞賛
返信

9,849件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

S32 Design Studio for ARM

Version: 2.2
Build id: 200116

Copyright Freescale Semiconductor 2016. All rights reserved.
Copyright 2017-2020 NXP

 

alice_thanks_0-1688355213921.pngalice_thanks_0-1688355213921.png

 

0 件の賞賛
返信

9,847件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

alice_thanks_0-1688355314223.pngalice_thanks_0-1688355314223.png

 

0 件の賞賛
返信

9,824件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hi @alice_th,

I can't find out the link to download the FreeRTOS 10.0.1 version on the NXP.com

Maybe this version is too old. Could you update to use FreeRTOS 10.4.6 (the latest version) instead of 10.0.1 version? If not, please send me the link to download FreeRTOS 10.0.1 version and the SDK package you are using.

Best regards,

Dan

0 件の賞賛
返信

9,821件の閲覧回数
alice_th
Contributor III
0 件の賞賛
返信

9,819件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

sdk is too big, can't attached, only support 25M

below is what we have 

C:\NXP\S32DS_ARM_v2.2\S32DS\software\S32SDK_S32K1xx_RTM_3.0.0

alice_thanks_0-1688372548234.pngalice_thanks_0-1688372548234.png

 

0 件の賞賛
返信

9,818件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

all the sdk and rtos is auto download with s32ds tools

alice_thanks_0-1688372837674.pngalice_thanks_0-1688372837674.png

 

0 件の賞賛
返信

9,791件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

any update or can you help test the project which i already attached to find what is the problem,

thanks a lot!

0 件の賞賛
返信

9,772件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

how install it, i see LPI2C0_Master_IRQHandler already in start.S file 

 

alice_thanks_0-1688455662508.pngalice_thanks_0-1688455662508.png

 

0 件の賞賛
返信

9,764件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hi @alice_th,

If you have an interrupt function in the startup file then you only need to enable LPI2C0_Master_IRQn in your code.

You should put a breakpoint in the LPI2C0_Master_IRQHandler to check whether you can jump into this function or not.

If the LPI2C0 interrupt didn't occur, you should check whether the bits are configured correctly as the below or not.

nxf78987_0-1688459587079.pngnxf78987_0-1688459587079.png

nxf78987_0-1688459822276.pngnxf78987_0-1688459822276.png

If not, please modify your configuration to enable the above bits.

Best regards,

Dan

0 件の賞賛
返信

9,758件の閲覧回数
alice_th
Contributor III

this API LPI2C_DRV_MasterInit already enable irq ,

see below, 

 

alice_thanks_0-1688460166972.pngalice_thanks_0-1688460166972.png

 

0 件の賞賛
返信

9,752件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hi @alice_th,

Yes, please check the bits I said previously.

Best regards,

Dan

 

0 件の賞賛
返信

9,712件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

even i add installHandler INT_SYS_EnableIRQ(LPI2C0_Master_IRQn); or set MCR MIER ISER register,
but still can't enter LPI2C_DRV_SlaveIRQHandler(0);  what is problem ? did you run my project and enther i2c irq ?
 
/* Install Button interrupt handler */
    INT_SYS_InstallHandler(LPI2C0_Master_IRQn, vPort_i2C0_ISRHandler, (isr_t *)NULL);
    /* Enable Button interrupt handler */
    INT_SYS_EnableIRQ(LPI2C0_Master_IRQn);
    //LPI2C0->MCR |= 0x09;
    //LPI2C0->MIER |= 0x01;
    //S32_NVIC->ISER[0] |= 0x01000000;

 

 
static void prvSetupHardware( void )
{
int i = 1;
lpi2c_master_state_t lpi2c1MasterState;
    /* Initialize and configure clocks
     *  -   Setup system clocks, dividers
     *  -   see clock manager component for more details
     */
    CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                   g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
    CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
    
     PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0,&lpi2c1MasterState);
    boardSetup();
  //  LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
    AMS_LOG("prvSetupHardware=%d\n",i);
 
/* Install Button interrupt handler */
    INT_SYS_InstallHandler(BTN_PORT_IRQn, vPort_C_ISRHandler, (isr_t *)NULL);
    /* Enable Button interrupt handler */
    INT_SYS_EnableIRQ(BTN_PORT_IRQn);
 
/* Install Button interrupt handler */
    INT_SYS_InstallHandler(LPI2C0_Master_IRQn, vPort_i2C0_ISRHandler, (isr_t *)NULL);
    /* Enable Button interrupt handler */
    INT_SYS_EnableIRQ(LPI2C0_Master_IRQn);
//LPI2C0->MCR |= 0x09;
//LPI2C0->MIER |= 0x01;
//S32_NVIC->ISER[0] |= 0x01000000;
/* Enable global interrupt */
    INT_SYS_EnableIRQGlobal();
    /* The interrupt calls an interrupt safe API function - so its priority must
    be equal to or lower than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. */
    INT_SYS_SetPriority( BTN_PORT_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
INT_SYS_SetPriority( LPI2C0_Master_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1 );
}
alice_thanks_0-1688536750721.pngalice_thanks_0-1688536750721.png

 

0 件の賞賛
返信

9,707件の閲覧回数
DanNguyenDuy
NXP Employee
NXP Employee

Hi @alice_th,

Please double-click into those bits and show me the values of them.

nxf78987_0-1688537636172.pngnxf78987_0-1688537636172.png

Second, I can't open your configuration to check it because something wrong (I don't know) and so, I enabled the bits in previous comment and it ran OK.

Best regards,

Dan

0 件の賞賛
返信

9,704件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

alice_thanks_0-1688538186571.pngalice_thanks_0-1688538186571.png

 

0 件の賞賛
返信

9,703件の閲覧回数
alice_th
Contributor III

@DanNguyenDuy 

even the register is same as you 

it will block it

alice_thanks_0-1688538579867.pngalice_thanks_0-1688538579867.png

 

0 件の賞賛
返信