I'm using the nRF5 SDK 12.3.0 on Linux (Fedora 33), with a minimal N51822 breakout board (nRF51822-QFAA(build code: H0) 256kB Flash, 16kB RAM).
For programming I'm using a ST-Link v2 and OpenOCD.
Testing with the blinky example, the pre-built .hex file included with the SDK works ok, but the .hex produced by compiling does not.
I'm using version 12.3.0 of the SDK because that seems to be the last one that included pre-built examples for nRF51822.
Here are the steps I took after downloading the SDK.
Modify components/toolchain/gcc/Makefile.posix to specify the compiler:
GNU_INSTALL_ROOT ?= /home/chris/projects/gcc-arm-none-eabi-10.3-2021.07
Go to examples/peripheral/blinky/hex/
Flash the pre-built example .hex to the device like this:
openocd -f interface/stlink.cfg -f target/nrf51.cfg -c "init" -c "halt" -c "nrf51 mass_erase" -c "program blinky_pca10028.hex" -c "reset" -c "exit"
The programming succeeds, and I see the LEDs blinking. I can connect with gdb, pause and resume the execution etc. So everything is fine with the pre-built .hex.
Next I go to examples/peripheral/blinky/pca10028/blank/armgcc/ and run 'make', which compiles successfully:
[chris@localhost armgcc]$ make mkdir _build Compiling file: nrf_log_backend_serial.c Compiling file: nrf_log_frontend.c Compiling file: app_error.c Compiling file: app_error_weak.c Compiling file: app_timer.c Compiling file: app_util_platform.c Compiling file: hardfault_implementation.c Compiling file: nrf_assert.c Compiling file: sdk_errors.c Compiling file: boards.c Compiling file: nrf_drv_clock.c Compiling file: nrf_drv_common.c Compiling file: nrf_drv_uart.c Compiling file: nrf_nvic.c Compiling file: nrf_soc.c Compiling file: main.c Compiling file: RTT_Syscalls_GCC.c Compiling file: SEGGER_RTT.c Compiling file: SEGGER_RTT_printf.c Assembling file: gcc_startup_nrf51.S Compiling file: system_nrf51.c Linking target: _build/nrf51422_xxac.out text data bss dec hex filename 3192 108 112 3412 d54 _build/nrf51422_xxac.out Preparing: _build/nrf51422_xxac.hex Preparing: _build/nrf51422_xxac.bin
When I flash the newly compiled .hex using the same method as before, the programming succeeds again. But the LEDs do not blink, and when I connect with gdb the program is always in HardFault_Handler:
[chris@localhost ~]$ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger > halt target halted due to debug-request, current mode: Handler HardFault xPSR: 0x61000003 pc: 0x00000b62 msp: 0x20007fe0
Shouldn't the pre-built example be just the same as what we get from compiling? What could be wrong with my toolchain that causes the compiled .hex to fail?