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

nRF51822 over the air bootloader with gcc

For my current project, I need to compile the »over the air bootloader« with gcc (because our buildserver runs on linux, developers using Mac … no Windows and no Keil so far).

But unfortunaly, the bootloader example from the sdk (5.1) examples won't compile with gcc. It's missing gcc makefile and even there are at least 2 Keil specific files in the project (arm_startup_nrf51.s and bootloader_util_arm.c).

Could you provide support to help me on this topic?

I'd also checked:- devzone.nordicsemi.com/index.php/nrf51822-bootloader-with-gcc

Parents
  • I also made some BLE DFU OTA code for gcc just today and I made this changes to nrf6310\device_firmware_updates\bootloader project:

    1. Linker scripts:

    1.1. gcc_nrf51_common.ld

    Add sections:

    SECTIONS
    {
        .bootloader_settings_block 0x0003FC00 :
        {
            KEEP(*(.bootloader_settings_sect))
        } > bootloader_settings
      
        .NRF_UICR_BOOT_START_BLOCK 0x10001014 :
        {
            KEEP(*(.NRF_UICR_BOOT_START_SECT))
        } > NRF_UICR_BOOT_START
    ...
    }
    

    1.2. gcc_nrf51_s110_xxaa.ld

    MEMORY
    {
      FLASH (rx) : ORIGIN = 0x3C000, LENGTH = 0x3C00 /* bootloader */
      bootloader_settings (rwx) : ORIGIN = 0x3FC00, LENGTH = 0x400 /* bootloader specific settings */
      NRF_UICR_BOOT_START (rwx) : ORIGIN = 0x10001014, LENGTH = 0x4 /* bootloader start address in UICR register */
      RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */
    }
    
    1. bootloader_util_arm.c

       uint8_t __attribute__((section (".bootloader_settings_sect"))) m_boot_settings[CODE_PAGE_SIZE] __attribute__((used));
       uint32_t __attribute__((section (".NRF_UICR_BOOT_START_SECT"))) m_uicr_bootloader_start_address = BOOTLOADER_REGION_START;
      
      
       inline void StartApplication(uint32_t start_addr)
       {
           asm volatile("LDR   R2, [R0]               \n\t" // Get App MSP.
                        "MSR   MSP, R2                \n\t" //Set the main stack pointer to the applications MSP.
                        "LDR   R3, [R0, #0x00000004]  \n\t" //Get application reset vector address.
                        "BX    R3                     \n\t" //No return - stack code is now activated only through SVC and plain interrupts.
                        ".ALIGN"
                       );
       }
      
    2. dfu_types.h

       #define BOOTLOADER_REGION_START         0x0003C000
      
    3. pstorage_platform.h I had error from some check in pstorage, so I had to change PSTORAGE_MIN_BLOCK_SIZE value from 0x0010 to 0x000C:

       #define PSTORAGE_MIN_BLOCK_SIZE     0x000C
      

    UPD: But I think additional padding word for bootloader_settings_t is better solution for PSTORAGE_MIN_BLOCK_SIZE problem. UPD2: And with -Os optimization I have:

    'Invoking: Cross ARM GNU Print Size'
    arm-none-eabi-size  --format=berkeley "nRF51822_BLE_DFU.elf"
       text	   data	    bss	    dec	    hex	filename
      13988	   2128	   2096	  18212	   4724	nRF51822_BLE_DFU.elf
    'Finished building: nRF51822_BLE_DFU.siz'
    ' '
    

    Compiled with gcc version 4.8.3 20131129 (release) [ARM/embedded-4_8-branch revision 205641] (GNU Tools for ARM Embedded Processors).

    UPD3: I forgot that I deleted DFU start from button push and replaced it with NRF_POWER->GPREGRET check so code size was a bit smaller. With button usage:

    'Invoking: Cross ARM GNU Print Size'
    arm-none-eabi-size  --format=berkeley "nRF51822_BLE_DFU.elf"
       text	   data	    bss	    dec	    hex	filename
      14128	   2136	   2096	  18360	   47b8	nRF51822_BLE_DFU.elf
    'Finished building: nRF51822_BLE_DFU.siz'
    ' '
    

    UPD4: I attached eclipse project for bootloader.

    UPD 2014.06.26:

    I attached updated eclipse project for bootloader:

    C:\fakepath\Eclipse_workspace_2.rar

    Changes:

    • Added the function of simultaneous flashing bootloader and application via J-Link from this question: devzone.nordicsemi.com/.../

    • Added additional optimization as Joe Merten suggested: --specs=nano.specs -flto For -flto optimization you need to change your SDK files and add attribute ((used, section(".Vectors"))) to the IRQ handlers (GPIOTE_IRQHandler, RTC1_IRQHandler, SWI0_IRQHandler, SWI2_IRQHandler) like this:

       void __attribute__ ((used, section(".Vectors"))) GPIOTE_IRQHandler(void)
       {
       ...
       }
      

    in files:

    app_common/app_gpiote.c
    app_timer/app_gpiote.c
    sd_common/softdevice_handler.c
    

    To tim, I don't use makefile, but you can find makefile autogenerated by Eclipse in attached Eclipse_workspace_2.rar in this folder:

    nRF51822_BLE_DFU_flashing_with_app\Debug

    But if you want to use pure Makefile project then I would suggest you use the Joe Merten's project.

  • Very thanx for your reply. Yes, I forgot to describe dfu_types.h / BOOTLOADER_REGION_START in my post. And I'd also reworked about ".ALIGN". Are you using the makefiles & startup code from the sdk or from https://github.com/hlnd ? Are you developing on a Linux, OSX or Windows machine?

Reply Children
No Data
Related