get hardfault when do division func on stm32g070 with gcc cross compile tool
my cross compile tool version:
▸ arm-none-eabi-gcc -v Using built-in specs. COLLECT_GCC=arm-none-eabi-gcc COLLECT_LTO_WRAPPER=/home/red/.local/gcc-arm-none-eabi-10-2020-q4-major/bin/../lib/gcc/arm-none-eabi/10.2.1/lto-wrapper Target: arm-none-eabi Configured with: /mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/src/gcc/configure --target=arm-none-eabi --prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native --libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/lib --infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/install-native/arm-none-eabi --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr --with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr --with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr --with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr --with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-48_20201124_1606180641/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Arm Embedded Toolchain 10-2020-q4-major' --with-multilib-list=rmprofile,aprofile Thread model: single Supported LTO compression algorithms: zlib gcc version 10.2.1 20201103 (release) (GNU Arm Embedded Toolchain 10-2020-q4-major)
And My Final link config as:
[1/1] arm-none-eabi-g++ -nostartfiles -nostdlib --specs=nosys.specs -Xlinker -print-memory-usage -Xlinker --sort-section=alignment obj/kernel/core/core.tos_barrier.o obj/kernel/core/core.tos_binary_heap.o obj/kernel/core/core.tos_bitmap.o obj/kernel/core/core.tos_char_fifo.o obj/kernel/core/core.tos_completion.o obj/kernel/core/core.tos_countdownlatch.o obj/kernel/core/core.tos_event.o obj/kernel/core/core.tos_global.o obj/kernel/core/core.tos_mail_queue.o obj/kernel/core/core.tos_message_queue.o obj/kernel/core/core.tos_mmblk.o obj/kernel/core/core.tos_mmheap.o obj/kernel/core/core.tos_mutex.o obj/kernel/core/core.tos_pend.o obj/kernel/core/core.tos_priority_mail_queue.o obj/kernel/core/core.tos_priority_message_queue.o obj/kernel/core/core.tos_priority_queue.o obj/kernel/core/core.tos_ring_queue.o obj/kernel/core/core.tos_robin.o obj/kernel/core/core.tos_rwlock.o obj/kernel/core/core.tos_sched.o obj/kernel/core/core.tos_sem.o obj/kernel/core/core.tos_stopwatch.o obj/kernel/core/core.tos_sys.o obj/kernel/core/core.tos_task.o obj/kernel/core/core.tos_tick.o obj/kernel/core/core.tos_time.o obj/kernel/core/core.tos_timer.o obj/kernel/osal/cmsis_os/cmsis_os.cmsis_os.o obj/kernel/hal/tos_hal_armv6m_gcc.o obj/kernel/arch/arm/arm-v6m/common/common.tos_cpu.o obj/kernel/arch/arm/arm-v6m/common/common.tos_fault.o obj/kernel/arch/arm/arm-v6m/cortex-m0/gcc/cortex-m0.port_c.o obj/kernel/arch/arm/arm-v6m/cortex-m0/gcc/port_s.o obj/platform/vendor_bsp/st/CMSIS/Device/ST/STM32G0xx/Source/Templates/platform.system_stm32g0xx.o obj/board/XYJ_STM32G070CBTX/APP/hello_world/startup_stm32g070xx.o obj/board/XYJ_STM32G070CBTX/APP/hello_world/APP.main.o obj/board/XYJ_STM32G070CBTX/APP/hello_world/HAL.stm32g0xx_it.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_uart.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_uart_ex.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_dma.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_rcc.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_rcc_ex.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_pwr.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_pwr_ex.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_gpio.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/HAL.stm32g0xx_hal_cortex.o obj/board/XYJ_STM32G070CBTX/BSP/Src/BSP.mcu_init.o obj/board/XYJ_STM32G070CBTX/BSP/Src/BSP.gpio.o obj/board/XYJ_STM32G070CBTX/BSP/Src/BSP.bsp_usart.o obj/board/XYJ_STM32G070CBTX/BSP/Src/BSP.usart.o obj/platform/vendor_bsp/st/STM32G0xx_HAL_Driver/Src/vendor_bsp_hal.stm32g0xx_hal.o -T /home/red/LearnProjects/ChipAdaptation/board/XYJ_STM32G070CBTX/LEDsingle.ld -L/home/red/.local/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi/lib/thumb/v6-m/nofp -lgcc -Wl,-Map=LEDsingle.map -o LEDsingle.elf && arm-none-eabi-objcopy -O binary LEDsingle.elf LEDsingle.bin && arm-none-eabi-objcopy -O ihex LEDsingle.elf LEDsingle.hex && arm-none-eabi-size LEDsingle.elf
And when I use gdb to debug, I found I will get in Hardfault_Handler, and the stack backtrace as:
(gdb) bt
#0 HardFault_Handler () at ../board/XYJ_STM32G070CBTX/APP/hello_world/stm32g0xx_it.c:89
#1
#2 0x08008ff8 in ?? ()
#3 0x08003ca2 in cpu_init () at ../kernel/arch/arm/arm-v6m/common/tos_cpu.c:81
the cpu_init func is just as:
k_cpu_cycle_per_tick = TOS_CFG_CPU_CLOCK / k_cpu_tick_per_second;
it's equa with k_cpu_cycle_per_tick = 16000000 / 1000;
I wonder how could this happen, I build this on stm32g070cb chip.
w
