Post Go back to editing

SPI Flash behavior changes based on optimization enabling

Category: Software
Product Number: ADSP-21594
Software Version: CCES 2.11.1
Hi team,
We are working on developing a code for verifying SPI flash working-Erase,Write and Read operations in ADSP-21594 platform.For this, we have used few of the functions from the code written for SPI flash on EZ Kit found from AD Engineer Zone in the below link:
One of the functions in this code is flash_byte_access(). On verification it is observed that based on whether optimization is enabled for this function or not,code behavior changes.
Flash is successful only if "optimize_off" pragma is used for flash_byte_access().
Flash fails if "optimize_off" pragma is not used for flash_byte_access().
Note: Compiler optimization option is enabled in properties for both the cases.
Kindly let us know the relation between optimization and flash_byte_access() and this behavior.
Thanks,
B. Shanmuga Eashwari

Thread Notes

  • Hi Eashwari,

    Thank you for your inquiry.

    Could you please share us more details about actual issue or the observation that you are facing. Please confirm whether you are facing any error message or unexpected behavior while flashing without using "optimize_off" pragma.

    In order to simulate the issue, could you please share us your project tested in ADSP-21594 Evaluation kit. This would be helpful for us to assist you further.

    Awaiting for your reply.

    Best Regards,
    Santhakumari.V

  • Hi Santha,

    Thanks for the response.

    Please find the observation details as below:

    While flash is verified without using "optimize_off" pragma for flash_byte_access() function,flash erase and write are successful but flash fails at read operation.

    We are trying to write known data('A') to flash.On dumping the read data,it is observed that first 8bytes is  0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF and do not match with the known data.Only after the 8th byte,the known data written is observed.

    But when "optimize_off" pragma is used for flash_byte_access(),issue is not observed and flash is successful.

    Note:

    Enable optimization option has been enabled in project settings.

    Kindly share your feedback on this behavior and root cause for this issue.

    Thanks and Regards,

    B.Shanmuga Eashwari

  • Hi Eashwari,

    Can you please share us your test project which replicates this issue in ADSP-SC594 Eval kit. This would be helpful for us to find the cause of the issue.

    Thanks in advance and waiting for your reply.

    Best Regards,
    Santhakumari.K

  • Hi Santha,
    Thanks for the response.

    We have developed the flash code for ADSP-21594 processor and verification is being done in Eval Melody AVR9 board.We have attached the code for your reference.Hope this code can be loaded in ADSP-SC594 Eval Kit also.

    Code implementation details:
    Flash erase,write and read operations are done for 3 blocks.Known data('A') is written into flash.

    Enable optimization option has been enabled in Core1 properties.
    Optimize_off prgama for flash_byte_access() is commented to simulate the issue scenario.

    Kindly share your feedback on this.

    ADSP_21594_Flash_code.zip

    Thanks and Regards,

    B.Shanmuga Eashwari

  • Hi Eashwari,

    Thank you for sharing the Test project with us. We have simulated the observation that you are facing.

    The SPI communication speed is determined by the Baud rate. While optimization is enabled, it improvises application's performance. So by increasing the SPI clock, it might be more compatible to run the application .

    Here we can overcome your issue by setting the Baud rate value below 24. We tried by setting this SPI2 clock register as "*pREG_SPI2_CLK= 23;" and we are able to write and read data from flash successfully. Could you please try the same value with you test setup and let us know whether the issue got resolved.

    Regards,
    Santhakumari.K

  • Hi Santha,
    Thanks for the reply.

    Sorry for the delayed response.

    We have checked the flash issue by setting *pREG_SPI2_CLK= 23" as suggested.Issue is not observed for this case.
    Note:
    Optimization option has been enabled in Core1 properties.

    We understand that baud rate determines SPI clock speed and is set based on desired SPI clock frequency.
    Kindly elaborate on how baud rate and optimization is related and why SPI clock should be increased when optimization is enabled for proper working of flash.

    Also,difference between SPI Clock in both the cases is very less ie.
    When Baud rate=24;SPI CLK is 5MHz
    When Baud rate=23;SPI CLK is 5.2MHz
    Kindly explain how this increase in SPI Clock ie. decrease in Baud rate solves the issue.

    This would be helpful to understand the exact root cause of this issue.

    Thanks and Regards,

    B.Shanmuga Eashwari

  • Hi Eashwari,

    As we mentioned in the previous response, while optimization is enabled, it improvize application's performance. But the SPI clock frequency is not compatible to perform the read/write transactions with the application speed.

    Initially we tried a small delay with SPI read/write transaction and the application works fine with the Baud rate of 24 itself(i. e SPI CLK is 5MHz).So we tried to change the baud rate value below 24 by increasing the SPI clock frequency which is compatible to run the application as per your requirement.

    Also, please check the below FAQ that may help you to find out the typical reasons that optimization 'breaks' working code - there are some common causes that can be avoided with specific programming practices.

    FAQ: Why does my code stop working when I enable optimization?
    ez.analog.com/.../why-does-my-code-stop-working-when-i-enable-optimization

    Hope this helps.

    Best Regards,
    Santhakumari.K