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.

BusFault on a code protected device when using rtsv7M4_T_le_v4SPD16_eabi.lib functions

Other Parts Discussed in Thread: CODECOMPOSER

Hello, I'm new here. I searched a while in the forum with no luck about this issue.

I'm using an TM4C1233H6PMI device, with a very simple code. Based on SPMA044A application report (spma044a.pdf) I protected a section of the code (from 0x800 to 0x1800 where the .text section is placed) as execute-only. Working with CodeComposer v5.5.0.00077.
I can run all the code, but when the code makes a call to a strtok() it generates a busfault. This behaviour is seen only with strtok(); i've tried with strcmp(), strcpy() and some driverlib functions and they all function properly, i mean, they don't trigger a BusFault.

Looking into the disassembly code, there is an LDR call pointing to a protected memory area (I put an breakpoint before the FlashProtectSet() call in order to see the disassembly, that's why is visible in the image).

Going deeper, the FaulStat shows a BusFault precise fault, and the FaultAddress is shown in
the image.

The disassembly at the Fault Address shows this:

As you can see, the LDR instruction points to $C$CON1. 

Now the question is: how Can I fix this issue? I'm missing something here?

Here is the map section in which strtok() is placed, and the memory configuration (only useful data shown)

MEMORY CONFIGURATION

         name            origin    length      used     unused   attr    fill
----------------------  --------  ---------  --------  --------  ----  --------
  FLASH                 00000000   00000800  0000026c  00000594  R  X
  FLASH_EX              00000800   00001800  00000fa8  00000858     X
  FLASH_2               00002000   0003e000  000007ba  0003d846  R  X
  SRAM                  20000000   00008000  0000044e  00007bb2  RW X

SEGMENT ALLOCATION MAP

run origin  load origin   length   init length attrs members
----------  ----------- ---------- ----------- ----- -------
00000000    00000000    0000026c   0000026c    r--
  00000000    00000000    0000026c   0000026c    r-- .intvecs
00000800    00000800    00000fa8   00000fa8    r-x
  00000800    00000800    00000fa8   00000fa8    r-x .text
00002000    00002000    000007c0   000007c0    r--
  00002000    00002000    00000782   00000782    r-- .const
  00002788    00002788    00000038   00000038    r-- .cinit
20000000    20000000    00000451   00000000    rw-
  20000000    20000000    00000400   00000000    rw- .stack
  20000400    20000400    00000035   00000000    rw- .bss
  20000438    20000438    00000019   00000000    rw- .data


SECTION ALLOCATION MAP

 output                                  attributes/
section   page    origin      length       input sections
--------  ----  ----------  ----------   ----------------
 00001720    00000018     rtsv7M4_T_le_v4SPD16_eabi.lib : args_main.obj (.text)
 00001738    00000018                                   : strcmp.obj (.text)
 00001750    00000014                                   : _lock.obj (.text)
 00001764    00000012                                   : copy_zero_init.obj (.text:decompress:ZI)
 00001776    00000010                                   : strcpy.obj (.text)
 00001786    0000000e                                   : copy_decompress_none.obj (.text:decompress:none)

Thanks in advance.

  • Sorry, I had an error on the information shown in Section Allocation Map. This is what it should say:

    SECTION ALLOCATION MAP

    output attributes/
    section page origin length input sections
    -------- ---- ---------- ---------- ----------------
    00001540 00000048 rtsv7M4_T_le_v4SPD16_eabi.lib : boot.obj (.text)
    00001588 00000044 : cpy_tbl.obj (.text)
    000015cc 00000044 : exit.obj (.text)
    00001610 00000040 : strtok.obj (.text)
  • The problem is that the strtok function reads an embedded constant, but you have HW protections enabled which limit memory access to execution only.  An embedded constant is a constant value placed in memory right after the instructions for the function.  Unfortunately, these things do not work together.

    One solution is to disable the HW protection.  That's probably not what you want.

    The other solution is to build all of your code with the option  --embedded_constants=off.  Please read about that option in the ARM compiler manual.  This means everything, including all the libraries you use, should be built with --embedded_constants=off.

    One library you use is the compiler RTS library (which supplies strtok).  You have to build a custom version of the RTS library.  Please see this wiki article on building the RTS library.  Pay close attention to this section, on building a custom one.  In your case, the key command to issue is similar to ...

    mklib --pattern=rtsv7M4_T_le_v4SPD16_eabi.lib --name=rtsv7M4_T_le_v4SPD16_eabi_noconsts.lib --install_to=$Project/Debug --extra_options="--embedded_constants=off"

    Thanks and regards,

    -George

  • The ARM compiler release is supposed to ship with rtsv7M4_T_le_v4SPD16_xo_eabi.lib, which is the same as rtsv7M4_T_le_v4SPD16_eabi.lib rebuilt with --embedded_constants=off; you shouldn't need to rebuild it yourself, just change to that library.
  • Thanks Archaeologist, I changed the properties of the proyect selecting rtsv7M4_T_le_v4SPD16_xo_eabi.lib and rebuilding driverlib.lib with --embedded_constants=off and the proyect start running.

    Thank you so much