AnsweredAssumed Answered

S32K144 - flexio_i2c (i2c) does not work as expected when compiler optimization level set at -O0

Question asked by Rodrigo Cortes on Jul 23, 2019
Latest reply on Jul 31, 2019 by Rodrigo Cortes

I am trying to use I2C with the S32K144 EVB. I decided to start with the flexio_i2c_s32k144 SDK example project from the S32SDK_S32K1xx_RTM_3.0.0.

After facing several issues, and debugging the project, I have found the following:

When compiling the flexio_i2c_s32k144 SDK example project using the S32 Design Studio, and setting the C Compiler and Assembler Optimization level to -O0, the project is not working properly. 

After the FLEXIO_I2C_DRV_MasterSendDataBlocking() is called, the i2cMasterState flexio_i2c_master_state_t.status is STATUS_I2C_TX_UNDERRUN, lpi2cSlaveState lpi2c_slave_state_t.status is STATUS_SUCCESS but the slave buffer is filled up with incorrect values. 

Then when the FLEXIO_I2C_DRV_MasterReceiveDataBlocking() is called, the lpi2cSlaveState lpi2c_slave_state_t.status is STATUS_BUSY, the  i2cMasterState flexio_i2c_master_state_t.status  is STATUS_I2C_RECEIVED_NACK, and the master buffer is filled up again with incorrect values. 

 

When I set up the optimization level to -O1, the project works correctly as expected. 

Per my project requirements, I should set the optimization level to -O0.

 

I verified the code size, and I can confirm that the code is not large enough to not fit the flash memory. Here are the results for the .elf file generated after running the arm-none-eabi-size utility tool with and without compiler optimization. It can be seen that the .text section without optimization is 0x96ac, which is fairly smaller than the available size of 512KB defined in the linker file as: 0x0007FBF0

 

******************************WITHOUT OPTIMIZATION (-O0)********************************

$ ./arm-none-eabi-size.exe --format=SysV -x /c/Users/rcortes/workspaceS32DS.ARM.2018.R1/flexio_i2c_s32k144/flexio_i2c_s32k144/Debug_FLASH/flexio_i2c_s32k144.elf

 

section size addr
.interrupts 0x400 0x0
.flash_config 0x10 0x400
.text 0x96ac 0x410
.interrupts_ram 0x400 0x1fff8000
.data 0x1e4 0x1fff8400
.code 0x0 0x1fff85e4
.bss 0x54 0x20000000
.heap 0x404 0x20000054
.stack 0x400 0x20006c00
.ARM.attributes 0x30 0x0
.debug_info 0x195b2 0x0
.debug_abbrev 0x2374 0x0
.debug_aranges 0x1288 0x0
.debug_ranges 0x1108 0x0
.debug_macro 0x20ebd 0x0
.debug_line 0xa1a4 0x0
.debug_str 0x73661 0x0
.comment 0xa0 0x0
.debug_frame 0x4ebc 0x0
Total 0xcbbfc

 

******************************WITH OPTIMIZATION (-O1)********************************

$ ./arm-none-eabi-size.exe --format=SysV -x /c/Users/rcortes/workspaceS32DS.ARM.2018.R1/flexio_i2c_s32k144/flexio_i2c_s32k144/Debug_FLASH/flexio_i2c_s32k144.elf

section size addr
.interrupts 0x400 0x0
.flash_config 0x10 0x400
.text 0x4044 0x410
.interrupts_ram 0x400 0x1fff8000
.data 0x1e4 0x1fff8400
.code 0x0 0x1fff85e4
.bss 0x54 0x20000000
.heap 0x404 0x20000054
.stack 0x400 0x20006c00
.ARM.attributes 0x30 0x0
.debug_info 0x22c1d 0x0
.debug_abbrev 0x2c50 0x0
.debug_loc 0x1177a 0x0
.debug_aranges 0x8f8 0x0
.debug_ranges 0xdf8 0x0
.debug_macro 0x20ebd 0x0
.debug_line 0x9b90 0x0
.debug_str 0x73660 0x0
.comment 0xa0 0x0
.debug_frame 0x1688 0x0
Total 0xdd16c

 

Thanks in advance for any inputs. I would expect the code to behave correctly regardless the compiler optimization level (specially if no optimization is selected)..

 

Best Regards,

Rodrigo

Outcomes