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

Most recent, fully functional, GCC example code?

Hi,

I am trying to get even a basic ARM GCC example set up using the provided toolchain code, and am having a rough go at it.

First, what is the most recent, working, full example of how to set up ARM GCC to compile and deploy to a nRF51 DK? I have no 'difficult' goals - I am running without a softdevice, with only GPIO, no standard library, not trying to implement OTA firmware or anything. I can figure out Eclipse later, I just need to be able to deploy to a target for now.

My procedure was this -

  1. Changed the $sdk/components/toolchain/gcc/Makefile.posix to point to /usr/local, where the ARM GCC is linked
  2. CD to the blinky armgcc directory, make, make flash
  3. The .hex is around 3kB, which is what we would expect for a gpio-only hex file
  4. Worth pointing out at this point that "make flash" is broken, it calls --program when my nrfjprog uses --flash for some reason. Even then, as written, it calls flash on _build/.hex, which is obviously wrong. So, I do it manually, with JLinkExe commands r, loadfile _build/nrf51422_xxac.hex, r, g in a script file.
  5. In any case, it says that it flashes successfully, but the expected pins are not toggling.
  6. If I use JLinkExe and halt it just says that PC is at 00000. After stepping, CycleCnt doesn't change, PC doesn't change, etc. IPSR says HardFault - maybe a problem with the startup code?
  7. Speaking of which, I read that some people saw blinky start at _start, which is a stdlib function, and suggested that blinky would work with the CFLAG -nostdlib. This didn't change anything.

When I halt, I see the following output -

PC = FFFFFFFE, CycleCnt = 00000000
R0 = FFFFFFFF, R1 = FFFFFFFF, R2 = FFFFFFFF, R3 = FFFFFFFF
R4 = FFFFFFFF, R5 = FFFFFFFF, R6 = FFFFFFFF, R7 = FFFFFFFF
R8 = FFFFFFFF, R9 = FFFFFFFF, R10= FFFFFFFF, R11= FFFFFFFF
R12= FFFFFFFF
SP(R13)= FFFFFFD8, MSP= FFFFFFD8, PSP= FFFFFFFC, R14(LR) = FFFFFFF9
XPSR = 81000003: APSR = Nzcvq, EPSR = 01000000, IPSR = 003 (HardFault)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00

The obvious questions,

  • What am I missing to make this work?

  • Is there a way to step through the code, on the command line? I will look up GDB in the meantime.

  • From an organizational perspective, are there Makefile examples that are self-contained? The current system looks like it would work best if you duplicated the example projects in-place. There doesn't seem to be a way for me to just "point to" a nRF SDK installation and have it use the files there, without modifying the Makefile. I did that, and got the same result, so it's not hard, but I am interested to know why this method of organization was selected. It seems a little awkward to have to actually drop your code into the nRF SDK examples folder to use the provided stationary.

Version notes -

OSX Yosemite, 10.10.2
ARM GCC version 4.7.4 20140401 (release) [ARM/embedded-4_7-branch revision 209195]
SDK 8.0.0

Thanks,

-Alex

  • When the chip has Softdevice flashed in, it won't work directly due to protection. You need to do full erase before you can debug any program that does not use Softdevice.

  • Like I said, I am not using a SoftDevice. Good thought, though, I have run into that issue in other contexts.

  • 1), 2) and 3) look right. Just to confirm you're in the 'blinky/pca10028/blank/armgcc' subdirectory and not the s110 one or the other board, sure you are but may as well check everything. I just built that example, I get a 3684 byte hex file. And that works on my DK, it's blinking right now.

    1. make flash is broken if you're on OSX partly because nrfjprog doesn't exist on OSX, what are you actually running here, OSX or something under parallels. (you can use this if you like, it's a homebrew not-really-look-alike version of nrfjprog plus a gui which runs on OSX)

    2. is the code actually on the chip?

      mem 0 128

    in JLinkExe. I get this (first few lines)

    00000000 = 00 80 00 20 15 03 00 00 5D 03 00 00 5F 03 00 00 
    00000010 = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
    

    which makes sense. 0x20008000 for the stack pointer, reset handler at 0x00000314

    1. CycleCnt won't change, the nrf51 doesn't have a cycle counter on it, the rest of the registers make no sense at all unless you don't actually have code on the chip. In fact that looks really like you have 0xff everywhere, PC at 0xFFFFFFFE, SP at 0xFFFFFFD8 (starts at 0xffffffff, gets aligned to 8 bytes on the exception and then has 32 bytes pushed --> 0xFFFFFFD8).

    2. I don't know where you read that but that advice is garbage, I'd ignore that.

    Couple other things, are you running JLinkExe with

    -if swd -device nrf51
    

    Before programming try the flash wipe sequence which is

    r
    sleep 500
    w4 4001e504 2
    w4 4001e50c 1
    r
    w4 4001e504 1
    sleep 1000
    r
    

    no need for the sleeps if you're typing from the command line.

    what else - you can single step with JLinkExe if you have lots of patience, it's fine for a blinky example, not hard to follow along.

  • You can follow https://devzone.nordicsemi.com/tutorials/7/development-with-gcc-and-eclipse/ to set up your mac dev environment.

    If you don't want that, the basic things you need are GNU Tools for ARM Embedded Processors (you probably want to put it in /usr/local/bin) and RKNRFGO (to flash your board).

    You seem like you installed gcc arm and changed makefile correctly I assume. Then you cd to "/nRF51_SDK_8.0.0_5fc2c3a/examples/peripheral/blinky/pca10028/blank/armgcc" and make. Use RKNRFGO to download .hex to the board without soft device.

    This works for me. Sorry if I am not solving your question directly. But those are the steps that took me.

  • That is what I meant. not using Softdevice. The problem you are having is very similar to the problem I mentioned. When you run a Blink Blank on a blank chip, it's fine. If you run the Blinky blank on a chip already have Softdevice burned in. The jtag is unable to write you blinky lot location zero but it thinks that the write was successful and crash with register dump all FF. This problem is not only with Jlink but also with OpenOCD. After using nRFGo to perform an erase all, blinky blank works.

Related