Advertisement
Guest User

Untitled

a guest
Jun 25th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. I also made some BLE DFU OTA code for gcc just today and I made this changes to nrf6310\device_firmware_updates\bootloader project:
  2.  
  3. 1. Linker scripts:
  4.  
  5. 1.1. gcc_nrf51_common.ld
  6.  
  7. Add sections:
  8.  
  9. SECTIONS
  10. {
  11. .bootloader_settings_block 0x0003FC00 :
  12. {
  13. KEEP(*(.bootloader_settings_sect))
  14. } > bootloader_settings
  15.  
  16. .NRF_UICR_BOOT_START_BLOCK 0x10001014 :
  17. {
  18. KEEP(*(.NRF_UICR_BOOT_START_SECT))
  19. } > NRF_UICR_BOOT_START
  20. ...
  21. }
  22.  
  23. 1.2. gcc_nrf51_s110_xxaa.ld
  24.  
  25. MEMORY
  26. {
  27. FLASH (rx) : ORIGIN = 0x3C000, LENGTH = 0x3C00 /* bootloader */
  28. bootloader_settings (rwx) : ORIGIN = 0x3FC00, LENGTH = 0x400 /* bootloader specific settings */
  29. NRF_UICR_BOOT_START (rwx) : ORIGIN = 0x10001014, LENGTH = 0x4 /* bootloader start address in UICR register */
  30. RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */
  31. }
  32.  
  33. 2. bootloader_util_arm.c
  34.  
  35. uint8_t __attribute__((section (".bootloader_settings_sect"))) m_boot_settings[CODE_PAGE_SIZE] __attribute__((used));
  36. uint32_t __attribute__((section (".NRF_UICR_BOOT_START_SECT"))) m_uicr_bootloader_start_address = BOOTLOADER_REGION_START;
  37.  
  38.  
  39. inline void StartApplication(uint32_t start_addr)
  40. {
  41. asm volatile("LDR R2, [R0] \n\t" // Get App MSP.
  42. "MSR MSP, R2 \n\t" //Set the main stack pointer to the applications MSP.
  43. "LDR R3, [R0, #0x00000004] \n\t" //Get application reset vector address.
  44. "BX R3 \n\t" //No return - stack code is now activated only through SVC and plain interrupts.
  45. ".ALIGN"
  46. );
  47. }
  48.  
  49. 3. dfu_types.h
  50.  
  51. #define BOOTLOADER_REGION_START 0x0003C000
  52.  
  53. 4. pstorage_platform.h
  54. I had error from some check in pstorage, so I had to change PSTORAGE_MIN_BLOCK_SIZE value from 0x0010 to 0x000C:
  55.  
  56. #define PSTORAGE_MIN_BLOCK_SIZE 0x000C
  57.  
  58. UPD:
  59. But I think additional padding word for bootloader_settings_t is better solution for PSTORAGE_MIN_BLOCK_SIZE problem.
  60. UPD2:
  61. And with -Os optimization I have:
  62.  
  63.  
  64. 'Invoking: Cross ARM GNU Print Size'
  65. arm-none-eabi-size --format=berkeley "nRF51822_BLE_DFU.elf"
  66. text data bss dec hex filename
  67. 13988 2128 2096 18212 4724 nRF51822_BLE_DFU.elf
  68. 'Finished building: nRF51822_BLE_DFU.siz'
  69. ' '
  70.  
  71. Compiled with gcc version 4.8.3 20131129 (release) [ARM/embedded-4_8-branch revision 205641] (GNU Tools for ARM Embedded Processors).
  72.  
  73. UPD3:
  74. 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.
  75. With button usage:
  76.  
  77.  
  78. 'Invoking: Cross ARM GNU Print Size'
  79. arm-none-eabi-size --format=berkeley "nRF51822_BLE_DFU.elf"
  80. text data bss dec hex filename
  81. 14128 2136 2096 18360 47b8 nRF51822_BLE_DFU.elf
  82. 'Finished building: nRF51822_BLE_DFU.siz'
  83. ' '
  84.  
  85. UPD4:
  86. I attached eclipse project for bootloader.
  87.  
  88. UPD 2014.06.26:
  89.  
  90. I attached updated eclipse project for bootloader:
  91.  
  92. [C:\fakepath\Eclipse_workspace_2.rar](/attachment/50d398306ed418fa1a9fc86385457b3f)
  93.  
  94. Changes:
  95.  
  96. - Added the function of simultaneous flashing bootloader and application via J-Link from this question:
  97. https://devzone.nordicsemi.com/question/12800/flashing-bootloader-and-application-via-j-link/
  98.  
  99. - Added additional optimization as Joe Merten suggested:
  100. --specs=nano.specs
  101. -flto
  102. 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:
  103.  
  104. void __attribute__ ((used, section(".Vectors"))) GPIOTE_IRQHandler(void)
  105. {
  106. ...
  107. }
  108.  
  109. in files:
  110.  
  111. app_common/app_gpiote.c
  112. app_timer/app_gpiote.c
  113. sd_common/softdevice_handler.c
  114.  
  115. To tim,
  116. I don't use makefile, but you can find autogenerated by Eclipse makefile in attached Eclipse_workspace_2.rar in this folder:
  117.  
  118. nRF51822_BLE_DFU_flashing_with_app\Debug
  119.  
  120. But if you want to use pure Makefile project then I would suggest you use the Joe Merten's project.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement