This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Driverlib optimization;keil

Genius 3300 points


I have read this post:

Amit said "The driverlib.lib if compiled with the optimization option can create this issue. Please recompile the driverlib with optimization set to 0".

I am using TivaWare_C_Series-2.1.1.71 with Keil 5.13.  Instead of adding driverlib.lib n project, I add individual peripheral files in code & then compile the entire code, which makes library files also to be compiled at higher optimization settings. Should I compile only at zero level?

  • In many, many years here - I cannot recall such an in-depth (and potentially eventful) post.   Good that.

    And one far beyond my knowledge - this sounds like a, "Chester" and/or "Amit" - perhaps Robert or Frank (f.m.) specialty, as well.

    As a functioning "investigator" - I must suggest that you visit this same question to Keil - you may have to "muddy" several waters to reach dry land...

  • Hello cb1,

    Chester question definitely, since I have never had to change from the default optimization options.

    Regards
    Amit
  • My own thoughts on this

    First you really should be linking with the library (rebuilt if you feel that's necessary). You do not gain a speed or size advantage by explicit linking. If anything the size is likely to increase. I'd only apply whole program optimization that didn't optimize the library after first determining that there was a problem, and it could not be narrowed to a specific area and could not be addressed algorithmically. I'd also be concerned about future expandability. The problems are not the optimization but the management overhead you impose on yourself to manage it.

    That rant over. On to the library optimization question. If the library does not work at higher levels of optimization then either there is a bug in the optimizer or in the library. Past compilers did have issues with corner cases at high optimization levels but they have become increasingly reliable. Code bugs can be quite subtle and just because code works at low optimization levels but not at high does not mean the code is correct, in fact it often means the same bug still lies in wait at lower optimization levels, just harder to trigger.

    If the compiler optimization is broken then no code should be compiled at optimization levels that exhibit the bug.
    If the library has a bug that shows at particular optimizations then you need to work with a version compiled at a level of optimization that does not show the bug.

    In both cases the bug needs to be fixed. In the first you can avoid the issue by not using problematic optimization levels. The second cannot,with confidence, be avoided but using a version that appears not to show the issue at least increases your chance of avoiding the issue.

    You really cannot do anything to fix the first case except, perhaps, document a test case for the compiler company. For the second case you may be able to find the issue yourself if you manage to find a simple enough test case to narrow the problem area.

    On a final note the result is likely better using high optimization and linking with the library than using whole program compilation at level 0. Level 0 usually disables most or even all optimization and I would expect any multimodule optimization to be among the first turned off.

    Robert
  • I would have said the problem was most likely a library bug before reading the link. After reading the link and seeing the suggestion made for two different compilers I'd increase the odds there is a library bug.

    Robert
  • Robert,

    OMG - what to say? Absolutely outstanding!

    Well introduced - clear, detailed and properly sequenced explanations - topped off w/your (usual) inspired strategies & recommendations.

    We are in your debt - (my check's "in the mail") - deep thanks - know that your efforts are greatly appreciated!
  • Vindhyachal Takniki said:
    Amit said "The driverlib.lib if compiled with the optimization option can create this issue. Please recompile the driverlib with optimization set to 0".

    I have replied to the referenced thread, saying that am unable to repeat the problem using TI ARM compiler v5.2.6. However I am unsure which compiler version the original poster was using.

    Vindhyachal Takniki said:
    I am using TivaWare_C_Series-2.1.1.71 with Keil 5.13

    I don't have the Keil compiler, so am unable to test the SSIConfigSetExpClk function on which the issue was reported with the Keil compiler.

    Looking at the source code of the SSIConfigSetExpClk function I can't identify any bugs in the function. When using the Keil compiler have you identified any issues at higher optimization settings?