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

Soft Device + Application flash doesn't work with Eclipse

Hello all,

I struggle to program nrf52 on Eclipse, and it works fine with Keil. Let me explain :

With Keil :

-I first flash softdevice 5.0 manually with JFlash Lite

-I flash my code with Keil,

it works fine. I can flash a merged hex file and my code after that, it is okay, my code is running

With Eclipse :

My code compiles (the same code), but if I flash the same softdevice, and my code, my code is not running.

I checked my project ld file and .map file : all is okay (i.e : same parameters in Keil),  my code starts at 0x23000

I am running out of ideas... Any help?

Thank you!

Parents
  • UPDATE : I found out what is going on : I am using the default .ld file provided in an SDK example and the FLASH lenght was specifed to 5D000, wich is too much : I had data around 0x39000 which were corrupted. When I specify Keil parameter (0x15000), my code doesn't compile anymore! I am facing flash overflow! Now I know Keil was performing size optimisation I have to tell gcc to do. (because in Keil, the code compiles)

    I set the same Optimisation level as Keil (O2) but I don't know how to tell gcc to use microlib library.

    Could someone help please? 

Reply
  • UPDATE : I found out what is going on : I am using the default .ld file provided in an SDK example and the FLASH lenght was specifed to 5D000, wich is too much : I had data around 0x39000 which were corrupted. When I specify Keil parameter (0x15000), my code doesn't compile anymore! I am facing flash overflow! Now I know Keil was performing size optimisation I have to tell gcc to do. (because in Keil, the code compiles)

    I set the same Optimisation level as Keil (O2) but I don't know how to tell gcc to use microlib library.

    Could someone help please? 

Children
  • For GCC optimization for space, use -Os

    For newlib nano, use linker parameter --specs=nano.specs

    It is better to use Eclipse native project than makefile project.  

  • Thank you for the advice. Unfortunately, with -Os : it still overflows by 276 bytes. I could increase FLASH lenght a little bit, but it will delay the issue : my code is going to be bigger. In Keil, it compiles fine with -O2, and I would like to have this results in Eclipse. nano.specs is already set. here is a piece of my Makefile, I think it could help :

    # Libraries common to all targets
    LIB_FILES += \

    # Optimization flags
    OPT = -O2 -g3
    # Uncomment the line below to enable link time optimization
    #OPT += -flto



    CPPFLAGS += BOARD_PCA10040
    CPPFLAGS += NRF52 NRF52832_XXAA
    CPPFLAGS += NRF52_PAN_74
    CPPFLAGS += NRF_SD_BLE_API_VERSION=5
    CPPFLAGS += S132
    CPPFLAGS += SOFTDEVICE_PRESENT
    CPPFLAGS += SWI_DISABLE0

    # C flags common to all targets
    CFLAGS += $(OPT)
    CFLAGS += -DBOARD_PCA10040
    CFLAGS += -DCONFIG_GPIO_AS_PINRESET
    CFLAGS += -DNRF52
    CFLAGS += -DNRF52832_XXAA
    CFLAGS += -DNRF52_PAN_74
    CFLAGS += -DNRF_SD_BLE_API_VERSION=5
    CFLAGS += -DS132
    CFLAGS += -DSOFTDEVICE_PRESENT
    CFLAGS += -DSWI_DISABLE0
    CFLAGS += -mcpu=cortex-m4
    CFLAGS += -mthumb -mabi=aapcs
    CFLAGS +=  -Wall
    CFLAGS += -Werror=implicit-function-declaration
    CFLAGS += -Wno-unused-function -Wno-comment -Wno-unused-variable
    CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    CFLAG += -split_sections
    CFLAG += -apcs=interwork
    CFLAG += --cpu Cortex-M4.fp
    # keep every function in a separate section, this allows linker to discard unused ones
    CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
    CFLAGS += -fno-builtin -fshort-enums
    CFLAG += --library_type=microlib


    # C++ flags common to all targets
    CXXFLAGS += $(OPT)

    # Assembler flags common to all targets
    ASMFLAGS += -O2 -g3
    ASMFLAGS += -mcpu=cortex-m4
    ASMFLAGS += -mthumb -mabi=aapcs
    ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    ASMFLAGS += -DBOARD_PCA10040
    ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
    ASMFLAGS += -DNRF52
    ASMFLAGS += -DNRF52832_XXAA
    ASMFLAGS += -DNRF52_PAN_74
    ASMFLAGS += -DNRF_SD_BLE_API_VERSION=5
    ASMFLAGS += -DS132
    ASMFLAGS += -DSOFTDEVICE_PRESENT
    ASMFLAGS += -DSWI_DISABLE0
    ASMFLAGS += -D__MICROLIB

    # Linker flags
    LDFLAGS += $(OPT)
    LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
    LDFLAGS += -mcpu=cortex-m4
    LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    LDFLAG += --library_type=microlib
    # let linker dump unused sections
    LDFLAGS += -Wl,--gc-sections
    # use newlib in nano version
    LDFLAGS += -specs=nano.specs -lc -lnosys -lm

    I tried to copy compiler command lines and asm command line from Keil.

    I tried to make gcc use microlib; but either I put the line or not, it doesn't change anything

    Thank you for support :)

  • Well, what is your nRF52 chip ? The nRF52832 has 512KB flash which 0x80000.  The firmware starts at 0x23000 which gives you the length 0x80000 - 0x23000 = 0x5D000 size. 0x15000 is only 86KB, way too small.  The nRF52810 has 256KB Flash if I remember. 

  • Yes it is nRF52832. I have data stored at 0x38000 and for the moment, I can't move them. 0x38000-0x23000 = 0x15000, that is why I specified this size for the code. At 0x3D000 there would be a bootloader in the near future, and after, a buffer zone for soft device, and a buffer zone for code. I could use -Os, which is very useful, but I need another code optimisation to make my code fit. That is why I looked for libraries like microlib

  • Ok I see.  You can use __attribute__ section on the data array then map that to anywhere in the linker script, See https://stackoverflow.com/questions/19781375/how-to-place-constant-at-specific-address-with-ld-linker-command-file

    That way you don't need to reduce your flash length.

Related