This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BUG: nrf_delay doesn't compile using nRF52 on GCC

Building nrf_delay.c (or anything else including nrf_delay.h) with NRF52 defined produces:

arm-none-eabi-gcc -I C:\Nordic\nRF5_SDK_11.0.0-2.alpha\components\device  -D_DEBUG -DNRF52 -DDEBUG -std=gnu11 -mcpu=cortex-m0 -mthumb -mabi=aapcs -Wall -Wno-switch -ffunction-sections -fdata-sections -ggdb -c C:\Nordic\nRF5_SDK_11.0.0-2.alpha\components\drivers_nrf\delay\nrf_delay.c -o build\nrf_delay.o
C:\Windows\ccESAXKg.s: Assembler messages:
C:\Windows\ccESAXKg.s:58: Error: instruction not supported in Thumb16 mode -- `subs r0,r0,#1'

(Using GCC ARM Tools for Embedded 5_2-2015q4, nRF5 SDK 11.0.0-2.alpha.)

If where nrf_delay.h has

#ifdef NRF51

I replace it with

#if defined(NRF51) || defined(NRF52)

the problem is fixed. There are other NRF52 checks in the file (mainly to add more NOPs).

Parents
  • it's because you're compiling for the wrong core.

    -mcpu-cortex-m0
    

    the nRF52 you're targetting is the M4 and gas treats subs differently by default (which is arguably incorrect gas behaviour but it's long-standing incorrect gas behaviour)

    Not that anyone should be using divided assembler syntax anyway anymore, and that's not going to, and doesn't work with, clang for instance. So I think the whole ifdef should go and the entire file should be

    .syntax unified
    

    I don't know why it's switched only for the nrf51, possibly in an attempt to 'do no harm' when someone found the original didn't compile.

Reply
  • it's because you're compiling for the wrong core.

    -mcpu-cortex-m0
    

    the nRF52 you're targetting is the M4 and gas treats subs differently by default (which is arguably incorrect gas behaviour but it's long-standing incorrect gas behaviour)

    Not that anyone should be using divided assembler syntax anyway anymore, and that's not going to, and doesn't work with, clang for instance. So I think the whole ifdef should go and the entire file should be

    .syntax unified
    

    I don't know why it's switched only for the nrf51, possibly in an attempt to 'do no harm' when someone found the original didn't compile.

Children
Related