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

Programming custom board through SES corrupts host device's bootloader

I am using a nRF52 DK to program an externally powered board with a NRF52811. 

I am able to flash a blinky program onto the custom board successfully using the output .hex files after building in SES

However, when I try to Start Execution while Debug has been selected, the DK will only show up as a corrupted USB device and is not able to flashed until I re-upload the bootloader software onto it. It is still able to be found by nRFgo Studio but it requires that I select a NRF51 device as it is unknown to the version of J-link software.

Furthermore, my custom board will not be programmed by starting execution. The program will build successfully but it will usually give me a hardFault.

This is a problem as I need to test programs that use a serial terminal. Any direction would be appreciated

I am using VDDnRF, VDD, VTC, SWDIO, SWDCLK, RESET, GND DETECT from the development kit to program my board

Update 1: Since using the recover option that nRFgo provides on my development, I am no longer able to flash blinky onto my custom board

Update 2: A fresh install of everything Nordic related seemed to fix my issue regarding flashing blinky, however I am still faced with the hardFault errors for most examples (see my reply below)

Parents
  • Hi sheddanl,

    However, when I try to Start Execution while Debug has been selected, the DK will only show up as a corrupted USB device and is not able to flashed until I re-upload the bootloader software onto it. It is still able to be found by nRFgo Studio but it requires that I select a NRF51 device as it is unknown to the version of J-link software.

     nRFGo Studio is deprecated for the nRF52 Series. You need to use the nRF Programmer application in nRF Connect for Desktop, see nRF Connect Programmer.  If you flash the bootloader to a nRF52 device, then the nRF52 will remain in bootloader mode even though an application has been flashed until a boootloader settings page is flashed to the nRF52, see Appendix 1 in https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/getting-started-with-nordics-secure-dfu-bootloader

    Best regards

    Bjørn

  • Thank you for replying to my question :)

    Yesterday I did a fresh install of everything Nordic related and now I am able to get the pca10040e blinky example to program from Segger Embedded Studio using Debug and Release, however pca10040 does not work, it will give me a hardfault. This is the same with the TWI scanner for pca10040.

    I suppose my question is now why is the emulated project working for me but not the other?

  • This allowed the program to builld. If anyone is having the a similar problem with 'multiple definitions of UARTE0_UART0_IRQHANDLER'

    set the flag UART_LEGACY_SUPPORT to 0 in your sdk_config.h file.

    I am now met with another hard fault unfortunately. I've started with a fresh copy of twi_scanner and have performed the following steps on the pca10056 project to try and transfer it to the nrf52811 hardware:

    1. Project Options -> Common -> Debugger -> Target Device -> nRF52811_xxAA
    2. Project Options -> Common -> Preprocessor -> Preprocessor Definitions -> (changed NRF52840_XXAA to NRF52811_XXAA)
    3. Project Options -> Common -> Linker -> Section Placement Macros -> (changed FLASH_SIZE to 0x2FFFF and RAM_SIZE to 0x5FFF)
    4. Right click project -> Open Solution in Editor -> (change ses_startup_nrf52840.s to ses_startup_nrf52811.s and system_nrf52840 to system_nrf52811)
    5. Project Options -> Common -> Code Generation -> (ARM FPU TYPE -> None, ARM FP ABI TYPE -> Soft)
    6. Save and reload project
    7. Add in my own custom board layout and edit the scl and sda pins
    8. In the sdk_config.h file:
      1. NRFX_TWIM0_ENABLED 1
      2. UART_LEGACY_SUPPORT 0 
      3. NRFX_TWI0_ENABLED 1
    9. Also in the sdk_config.h file to enable the debug terminal
      1. NRF_LOG_BACKEND_RTT_ENABLED 1
      2. NRF_LOG_BACKEND_UART_ENABLED 0
      3. NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0

    The program will then build and when I try to run it will give me a hard fault.

    UPDATE: also be sure to change the register definiton file to nrf52811.svd

    I also tried this with the fatfs example and I am met with the same hard fault

  • Can you attach your modified twi_scanner example? I would like to debug it on a nRF52811 board I have here. 

  • thank_you_bjorn.zip

    I am able to get examples working if I paste them into an already emulated example and import all the libraries etc, however, I'd like to understand what's happening here.

  • Found two errors in the project

    The first error was that FLOAT_ABI_HARD was added under Code > Preprocessor > Preprocessor Definitions. This must be changed to FLOAT_ABI_SOFT. Without this change I was not able to compile the project. 

    Running the project I saw that it Hardfaulted immediately and I saw that the Stack pointer was way out of bounds so I check the FLASH and RAM settings and the second error was that the FLASH and RAM settings were still set as if the code was running on a nRF52840, i.e. 

    FLASH_PH_START=0x0
    FLASH_PH_SIZE=0x100000
    RAM_PH_START=0x20000000
    RAM_PH_SIZE=0x40000
    FLASH_START=0x0
    FLASH_SIZE=0x2FFFF
    RAM_START=0x20000000
    RAM_SIZE=0x5FFF

    If you compare this to another pca10056e peripheral project, see below, then you see that the physical size of FLASH and RAM are much lower. So changing the Code > Linker > Section Placement Macros to the one below 

    FLASH_PH_START=0x0
    FLASH_PH_SIZE=0x30000
    RAM_PH_START=0x20000000
    RAM_PH_SIZE=0x6000
    FLASH_START=0x0
    FLASH_SIZE=0x30000
    RAM_START=0x20000000
    RAM_SIZE=0x6000

    After this change the example runs with no issues on my nRF52811 board. 

    Best regards

    Bjørn

  • With the changes I still hardfault immediately. Would you be able to attach the modified project so I can check if it runs on my board?

Reply Children
  • Hi Bjorn, this one worked. No idea why my one didn't work originally after modifying everything. For anyone having similar problems to me here is a guide for running the twi_scanner example on nRF52811 hardware, if starting from a non-emulated project (i.e. pca10056):

    .emProject file modifications

    1. Right Click the project in the Project Explorer. In this case it will be named 'twi_scanner_pca10056'
    2. Select 'Open Solution in Editor' from the menu that appears.
    3. Change arm_fp_abi from "Hard" to "Soft"
    4. Change arm_fpu_type from "FPv4-SP-D16" to "Soft"
    5. Change arm_target_device_name from "nRF52840_xxAA" to "nRF52811_xxAA"
    6. Add in any directories you might want to use to c_user_include_directories
    7. Change in c_preprocessor_definitions:
      1. BOARD_PCA10056 to your custom board
      2. FLOAT_ABI_HARD to FLOAT_ABI_SOFT
      3. NRF52840_XXAA to NRF52811_XXAA
    8. Change debug_register_definition_file from "../../../../../../modules/nrfx/mdk/nrf52840.svd" to "../../../../../../modules/nrfx/mdk/nrf52811.svd"
    9. Change linker_section_placement_macros:
      1. FLASH_PH_SIZE=0x100000 to 0x30000
      2. RAM_PH_SIZE=0x40000 to 0x6000
      3. FLASH_SIZE=0x100000 to 0x30000
      4. RAM_SIZE=0x40000 to 0x6000
    10. Under <folder Name="None">
      1. <file file_name="../../../../../../modules/nrfx/mdk/ses_startup_nrf52840.s" /> change to <file file_name="../../../../../../modules/nrfx/mdk/ses_startup_nrf52811.s" />
      2. <file file_name="../../../../../../modules/nrfx/mdk/system_nrf52840.c" /> change to <file file_name="../../../../../../modules/nrfx/mdk/system_nrf52811.c" />

    sdk_config.h modifcations

    The reason I have included these is to use them as an example of the things you might have to change in a separate example.

    1. NRFX_TWIM0_ENABLED from 0 to 1
    2. NRFX_TWI0_ENABLED from 0 to 1
    3. TWI1_ENABLED from 1 to 0
    4. UART_LEGACY_SUPPORT from 1 to 0

    In order to get things printing in the Debug Terminal

    1. NRF_LOG_BACKEND_RTT_ENABLED from 0 to 1
    2. NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED from 1 to 0
    3. NRF_LOG_BACKEND_UART_ENABLED from 1 to 0

    main.c modifications

    1. Change your pin assignments

    Thank you Bjorn for all your help.

    I suggest Nordic provide clearer instructions in future for this kind of thing, as their instructions left out many things that Bjorn has helped with that are crucial for transferring examples to different hardware.

Related