Question

I'm trying to build a simple project for Cortex M3. The problem I encountered with is that compiler includes a wrong libraries for the memset and other mem* -functions (memcpy, memcmp). And that results in hard fault every time when the execution approaches to the memset(arr, 0x55, 10); in list file it is written like blx <memset>. I'm using arm-none-eabi-gcc compiler. I don't use arm-none-eabi-ld for linking, but arm-none-eabi-gcc (4.8.2).

For gcc compiler I'm using these flags: -mthumb -mcpu=cortex-m3 -msoft-float -Os -gdwarf-2 -g3 -Wall -Wextra -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -Wundef -Wshadow -fno-common -ffunction-sections -fdata-sections

For linker script I'm using these flags: -L$(TOOLCHAIN_DIR) -L$(LIBGCC) --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group -nostartfiles -Wl,--gc-sections -Wl,--allow-multiple-definition -mthumb -mcpu=cortex-m3 -msoft-float -Wl,--print-gc-sections -T$(LINKER_SCRIPT) where $(LINKER_SCRIPT) is my own linker script $(TOOLCHAIN_DIR) - path to the libc.a, libnosys.a libraries $(LIBGCC) - path to the libgcc.a library

arm-none-eabi-gcc version is 4.8.2

So, my question is: where could a possible problem? Why memset and other functions from the string.h don't work at all? Could you, please, tell me what I missed?

Special section for dwelch ONLY: I can't provide you this code, because I do NOT have that toolchain anymore. You see, when you did ask me for the assembler, I've already recompiled a toolchain and got reed of that error. A new toolchain produces very different asm code, which does work. You wanted me to provide to you the thing that doesn't exist anymore. It's easy. The last thing, I catch was that blx instruction. Also, there are a lot of topics, where people complained about mem* functions. In those topics people typically had forgot to add architecture flags to linker

trust me, I've looked at this code for a very long time and I saw a lot of examples on network. Basically, it looked like: 08004c10 blx <memset> /*here was an error*/ Right now it looks like !!!08004a14 BL <memset>!!! And it works without any exceptions and hard faults. So, recompiling a toolchain was a solution. In this situation you are very wrong demanding a code which doesn't exist anymore and trying to say that I do not understand a problem.

End of the special section #fordwelchonly

Was it helpful?

Solution

It's not exactly an answer... but still. I had to re-build a toolchain. So, now everything looks as it suppose to be. Before recompiling a toolchain the line, which did cause a hard fault looked like:

08004c10     blx     <memset>

After recompiling a toolchain this line of code is:

08004a14      bl      <memset>

Apparently, a toolchain was configured and built in a wrong way.

The closest thing to what I just did is this post: http://www.bengreen.eu/fancyhtml/techiestuff/createcrosscompiletoolchainforlpcmbed.html

If someone has a similar problem, please, check the link I posted above.

Added: Have a look at Martin's comment on the topic too. Martin was right about linked libraries.

Added: The reason why I cannot see the blx label in my code is simple - Cortex M3 doesn't have an arm state. Igor Skochinsky pointed it out. Cortex M3 works only in thumb and debug states + implements thumb2 instructions set. Also, armv7m manual says that it works only in thumb states. That is, we have a reason, why it didn't work. Thank you Igor and Martin for the help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top