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.

Turning on optimizer causes bus fault with an attempted write to flash

We're using compiler version 15.2.3 and TivaC RTOS 2.16.1.14.  Everything runs fine when the compiler's optimizer is turned off, but when we enable it (even at level 0) we get the bus fault.  NVIC_FAULT_ADDR indicates an address in the flash memory range with optimizer set to 2, and with the optimizer set to 0 I've seen it attempt to write to the ROM memory range.  To be clear, none of the code actually attempts to do this, and it runs fine when the optimizer is off.

Nothing indicates that this is due to peripheral usage (as I've seen in other posts here), has anyone else run into issues with bus faults only when enabling the optimizer?

  • Hello Kaveh,

    Since this is a compiler and RTOS specific issue, moving it to the TI RTOS forum

    Regards
    Amit
  • Hi Kaveh,
    What device are you running this on?
    Thanks,
    Janet
  • TM4C129CNC
  • Hi Kaveh,
    Are you getting an exception dump in CCS? It should show register contents allowing you to find where in the code the exception occurred. Since the write is posted, you may need to look a few instructions back for the write. It could be that you have an uninitialized variable. You may also want to check your task stacks in ROV to make sure they have not overrun.
    Best regards,
    Janet
  • I've checked the stacks in ROV and they have not overrun (they're all less then 50%).  There isn't an uninitialized variable being used in this area, so I don't see how that could be it (and it works without the optimizer).  I have followed the exception dump (we dump it out over an UART)

    {L 2 mtime="00:00:00:02.10" Hard Fault FORCED 43
    {L 2 mtime="00:00:00:02.10" PRECISERR: Immediate Bus Fault, exact addr known 3c
    {L 2 mtime="00:00:00:02.11" Exception in background thread at PC = 0x00019282 b7
    {L 2 mtime="00:00:00:02.12" Core 0: Exception occurred in ThreadType_Task 33
    {L 2 mtime="00:00:00:02.12" Task name: stateMachineTaskHandle, handle: 0x20025cf0 e6
    {L 2 mtime="00:00:00:02.13" Task stack base: 0x20004380 ef
    {L 2 mtime="00:00:00:02.13" Task stack size: 0x1000 3f
    {L 2 mtime="00:00:00:02.14" R0 = 0x200276f8  R8  = 0xffffffff 8e
    {L 2 mtime="00:00:00:02.14" R1 = 0x00000002  R9  = 0xffffffff 43
    {L 2 mtime="00:00:00:02.15" R2 = 0x20028b60  R10 = 0xffffffff 8f
    {L 2 mtime="00:00:00:02.16" R3 = 0x00000000  R11 = 0xffffffff 4e
    {L 2 mtime="00:00:00:02.16" R4 = 0xffffffff  R12 = 0x20029278 6e
    {L 2 mtime="00:00:00:02.17" R5 = 0xffffffff  SP(R13) = 0x20005358 5e
    {L 2 mtime="00:00:00:02.17" R6 = 0xffffffff  LR(R14) = 0x00006873 5c
    {L 2 mtime="00:00:00:02.18" R7 = 0xffffffff  PC(R15) = 0x00019282 52
    {L 2 mtime="00:00:00:02.19" PSR = 0x01000000 79
    {L 2 mtime="00:00:00:02.19" ICSR = 0x00415803 c9
    {L 2 mtime="00:00:00:02.19" MMFSR = 0x00 e8
    {L 2 mtime="00:00:00:02.20" BFSR = 0x82 92
    {L 2 mtime="00:00:00:02.20" UFSR = 0x0000 fb
    {L 2 mtime="00:00:00:02.21" HFSR = 0x40000000 b3
    {L 2 mtime="00:00:00:02.21" DFSR = 0x00000001 ac
    {L 2 mtime="00:00:00:02.21" MMAR = 0xffffffff 59
    {L 2 mtime="00:00:00:02.22" BFAR = 0xffffffff 48
    {L 2 mtime="00:00:00:02.22" AFSR = 0x00000000 a9


    I've looked at where the PC is pointed to in the exception, and again I can't find anything to explain it.  It's usually in an area where we call a Semaphore_pend or a HWREGBITW to set a bit via bitbanding.  That said, if I comment out all the bit-banding, the crash still happens, just near the ***_pend function.

  • Some further information, the instruction that fails is

    00019282:   7828                ldrb       r0, [r5]

    This instruction is run many times successfully, but in the codepath where it fails, it seems r5 is not set up correctly (its value is 0xffffffff).