Bug in FSP 4.4.0

I have noticed some undefined behavior in my code running FSP 4.4.0 and may have found a bug.
I am writing code to interface a SRAM to read and write floats. While testing my code, I noticed that the loop conditions in my 'for' loop were being reset causing the software to be stuck in that loop but I am not modifying the loop conditions anywhere. Here is loop where 'k' will reset to 0 after completing the function 'spi_readf'.

for (int k = 0; k < dwt_samples; k++)

{

spi_readf(address_datax, &buffer2, 1);

axis_data.xAxis_g = buffer2;

spi_readf(address_datay, &buffer2, 1);

axis_data.yAxis_g = buffer2;

spi_readf(address_dataz, &buffer2, 1);

axis_data.zAxis_g = buffer2;

address_datax[2]++;

address_datay[2]++;

address_dataz[2]++;

ftoa(axis_data.xAxis_g, xAxis, 2); ftoa(axis_data.yAxis_g, yAxis, 2); ftoa(axis_data.zAxis_g, zAxis, 2);

//write data to uart

status = write_uart("R RAW: x-axis: "); status = write_uart(xAxis);

status = write_uart("\ty-axis: "); status = write_uart(yAxis);

status = write_uart("\tz-axis: "); status = write_uart(zAxis);

status = write_uart("\t(m/s^2)\n");

}



fsp_err_t spi_readf(uint8_t* address, uint32_t* output, uint16_t size)

{

status = R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_03, BSP_IO_LEVEL_LOW);

uint8_t buffer[4] = {read_cmd, address[0], address[1], address[2]};

uint8_t buffer2[dwt_samples * 4] = {0};

uint32_t buff[dwt_samples] = {0};

status = R_SPI_WriteRead(&g_spi0_ctrl, buffer, (float*)0x00, 4, SPI_BIT_WIDTH_8_BITS);

if (FSP_SUCCESS != status)

{

deinit_spi();

return status;

}

status = spi_event_wait(SPI_EVENT_TRANSFER_COMPLETE);

if (FSP_SUCCESS != status)

{

deinit_spi();

return status;

}

status = R_SPI_WriteRead(&g_spi0_ctrl, (float*)0x00, buffer2, (size * 4), SPI_BIT_WIDTH_8_BITS);

if (FSP_SUCCESS != status)

{

deinit_spi();

return status;

}

status = spi_event_wait(SPI_EVENT_TRANSFER_COMPLETE);

if (FSP_SUCCESS != status)

{

deinit_spi();

return status;

}

*************resetting of loop condition is caused by this loop.******************

for (l = 0; l < dwt_samples * 4; l += 4)                   

{

buff[l / 4] = ((buffer2[l] << 24)) | ((buffer2[l + 1] << 16)) | ((buffer2[l + 2] << 8)) | buffer2[l + 3];

memcpy(&output[l/4], &buff[l/4], 4);

}

status = R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_03, BSP_IO_LEVEL_HIGH);

return status;

}


Parents
  • Hello,

    Thanks for reaching out Renesas Engineering Community!

    Could you please provide to us more details about your issue?

    Also would it be possible to send to us either your project or some sample code , in order to help us to replicate your issue?

    Thank you!

    Regards,

    IK

  • Hi IK_Renesas, 

    I am writing floats to an SRAM and to verify that I am writing that correct information to the SRAM, I'm reading from the SRAM and matching the data. In the loop where I am performing the SRAM reads, the variable used for the loop conditions are always being reset to 0. Ex. below: the 'i' variable always resets to 0 causing me to be stuck in the for loop.

    for (int i = 0; i < some_number; i++)

    I have attached the project files below

     

Reply
  • Hi IK_Renesas, 

    I am writing floats to an SRAM and to verify that I am writing that correct information to the SRAM, I'm reading from the SRAM and matching the data. In the loop where I am performing the SRAM reads, the variable used for the loop conditions are always being reset to 0. Ex. below: the 'i' variable always resets to 0 causing me to be stuck in the for loop.

    for (int i = 0; i < some_number; i++)

    I have attached the project files below

     

Children