Division operation in Cortex-M0

Asked by knauf

Greetings to all,

I have encountered a problem with the division operation using Cortex-M0. More precisely - it just doesn't work. And as soon as program detects a division operation, Cortex-M0 starts the HardFault Handler procedure. I'm sure this is nothing serious and maybe it just happened because I haven't set the correct linking/compiling options. But I just can't find any solution to that. In fact, disassembling the line with the division operation has shown to me that at some point a function "_aeabi_uidiv_from_thumb" is being called. After the call, a set of instructions (only three) take place, but only the two of them are defined (the last one isn't.). I've tried to search the "_aeabi_uidiv" function in "libgcc.a" library from the "arm-none-eabi" package, but it wasn't there. There was only "_aeabi_uldivmod", no more. And if I understand correctly, "_aeabi_uldivmod" is used in 64 bit system, or am I wrong?!

Thank you for your help in advance.

P.S. I'm using "gcc-arm-none-eabi-4_7-2013q1" package for stm32f051R8 and I'm running it on Linux Mint 64-bit system.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
knauf
Solved:
Last query:
Last reply:
Revision history for this message
Joey Ye (jinyun-ye) said :
#1

The correct function to call is __aeabi_uidiv. It could be caused by incorrect compiler/linker options. Can you please share your complete compiler and linker command line?

- Joey

Revision history for this message
knauf (kaizer-rtk) said :
#2

Thank you for your reply Joey. Here is the list of options that I'm using:
1) compiler options: -g -mthumb -Wstrict-prototypes -fverbose-asm -mcpu=cortex-m0
2) linker options: -nostartfiles -mthumb -T linker_file.ld

Revision history for this message
Joey Ye (jinyun-ye) said :
#3

Knauf,

You must also include -mcpu=cortex-m0 in your linker command line, to let
it link libraris for cortex-m0. Or otherwise it links to default library
which doesn't work on cortex-m0. Actually the recommended Makefile is to
include the whole compiler flags into linker command line.

Please try it to see if problem solved.

Joey

On Tue, Aug 6, 2013 at 2:26 PM, knauf
<email address hidden>wrote:

> Question #233519 on GCC ARM Embedded changed:
> https://answers.launchpad.net/gcc-arm-embedded/+question/233519
>
> knauf posted a new comment:
> Thank you for your reply Joey. Here is the list of options that I'm using:
> 1) compiler options: -g -mthumb -Wstrict-prototypes -fverbose-asm
> -mcpu=cortex-m0
> 2) linker options: -nostartfiles -mthumb -T linker_file.ld
>
> --
> You received this question notification because you are an answer
> contact for GCC ARM Embedded.
>

Revision history for this message
knauf (kaizer-rtk) said :
#4

Joey,

I did what you asked and it worked. Thank you very much for your help! I feel so stupid right now. :) I thought it is enough to pass this option to compiler.