1
votes

I discover the stm32f4 discovery board. For the moment I'm able to use leds, button, and to communicate through serial port. I'm now trying to use the Gmp library on this board. I build the arm-none-eabi toolchain following these instructions: https://blog.tan-ce.com/gcc-bare-metal/

I configure Gmp with the following options: ./configure CC=arm-none-eabi-gcc CFLAGS="-nostartfiles --specs=nosys.specs -g" --host=arm-none-eabi --disable-assembly

My project compiles and links without any issue, but when I try to initialise an mpz_t on the board with the following code:

mpz_t a; 
mpz_init_set_str(a, "31", 10);

I fall into the HardFault_Handler (), my arm-none-eabi-gdb gives me:

(gdb) bt
#0  HardFault_Handler () at ./src/stm32f4xx_it.c:34
#1  <signal handler called>
#2  0x08016ade in __gmpn_fft_best_k (n=134358201, sqr=134358201) at mul_fft.c:151
#3  0x0801816e in __gmpn_mul_fft (op=0x80006f5 <HardFault_Handler>, pl=134219497, n=0x8022471 <Reset_Handler>, nl=537001984, m=0x80224b9 <WWDG_IRQHandler>, ml=134358201, k=134358201) at mul_fft.c:870
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

If someone has already run Gmp on a microcontroller I am very interested in the way to do it !

1

1 Answers

1
votes

I finally found the solution, the cortex type must be specified. For the stm32f4, add -mcpu=cortex-m4 to the CFLAGS solve the problem.

I use the toolchain available here: arm-none-eabi toolchain

The whole configuration command is: ./configure CC=arm-none-eabi-gcc CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m4" --host=arm-none-eabi --disable-assembly --prefix=your-bare-metal-gmp-location

where "your-bare-metal-gmp-location" is the installation directory (you must not install a bare metal library in the classical /usr/local).