9 years, 4 months ago.

Programming a non-mbed NRF51

Just wondering if anyone can tell me what the process would be for programming a non-mbed NRF51 chip.

I haven't used any mbed specific hardware, just trying to flash a LED and test interrupts.

I've got a J-Link, but I don't think it's as simple as taking the .hex file created by mbed and flashing it to the chip. Is it?

Thanks Mark

1 Answer

9 years, 4 months ago.

Quote:

I've got a J-Link, but I don't think it's as simple as taking the .hex file created by mbed and flashing it to the chip. Is it?

Actually it is as simple as that!

Connect the J-Link SWD pins to the NRF51. Select the NRF51 device in Segger J-Flash application, import the hex file, erase/flash the device (or use AUTO) and start the application.

Accepted Answer

Strange, I can't seem to get that to work.

This is my sample program, I'm building it for the NRF51822 dev board:

#include "mbed.h"

DigitalOut myled(p4);

int main() {
    while(1) {
        myled = 1;
        wait(0.5);
        myled = 0;
        wait(0.5);
    }
}

It says flashed successfully and then does nothing at all when I start the program with F9 in J-Flash.

This code works, I compiled it with GCC and then flashed it with J-Flash:

#include "nrf_delay.h"
#include "nrf_gpio.h"

int main(void){
	nrf_gpio_cfg_output(4);
	while(1){
		nrf_gpio_pin_toggle(4); 
		nrf_delay_ms(1000);
	}

}

So I'm sure the chip is fine, I must be missing something...

posted by Mark Baseggio 10 Dec 2014

The name p4 doesnt look like a valid pinname for the nRF51822. Are you compiling for lpc1768? Check the schematic of your board for the correct pinname for the LED. Use a format like Px_y in the mbed code.

DigitalOut myled(P0_19);
posted by Wim Huiskamp 10 Dec 2014

Is the part on your dev board the exact same variant as on the mbed device? Critically, if the RAM size is smaller than the mbed, then the stack pointer will be set outside of usable RAM. See eg http://developer.mbed.org/questions/4643/Does-mbed-support-STM32F030F4/ for how to modify the startup file with correct RAM size.

posted by David Lowe 11 Dec 2014

Both memory versions are supported by the mbed online compiler. Just select the correct platform: either RedbearLab for the 256KB flash or HRM1017 for the 128K flashsize. You may also want to check that both xtals are installed on your specific board.

posted by Wim Huiskamp 11 Dec 2014

Ahhh, this makes sense now. I'm sure the board doesn't have a 32kHz crystal, but I have a few around here, perhaps I can add this to the breadboard myself.

If I wanted to configure the device to use the internal oscillator is this the best way? I found this forum post:

http://developer.mbed.org/forum/platform-39-Nordic-nRF51822-community/topic/4982/

Since I'm just using the mbed_blinky as a sample I'm not sure how to get at the BLE_API file that post talks about, when I import BLE_API I don't see those folders. I must again, be missing something. Is there a way to just set this up in my main.cpp instead of editing those files?

I'm also assuming that this will adversely affect power consumption of the chip, because I read somewhere that using the 32kHz oscillator saves power.

LASTLY, is there a good reference to see if my chip has 256 or 128kb? I'm using nrf51822 qfaac0 but my Google searches don't return much for that part number.

Thanks to everyone for all the help!

posted by Mark Baseggio 11 Dec 2014

Ack. So, I did the following

  1. Changed ports to the appropriate notation (eg. P0_4)
  2. Installed 32.768kHz crystal (with 15pf capacitors to ground)
  3. Tried to compile and flash using RedBearLab board .. nothing
  4. Tried to compile and flash using HRM board ... nothing

Pulling my hair out over here because gcc is working fine. I've got pin interrupts working, serial, etc. Though I'd really like to use mbed.

Thanks again for your help!

posted by Mark Baseggio 11 Dec 2014

Quote:

LASTLY, is there a good reference to see if my chip has 256 or 128kb? I'm using nrf51822 qfaac0 but my Google searches don't return much for that part number.

The ''aa'' in qfaac0 indicates 256kB flash. When it says ''ab'' that would mean 128kB flash.

Did you try to update mbed lib to the latest release. Can you read back the flashed code and verify it matches your hex.

BLE lib should not be needed for blinky. Easiest way to include it is importing one of the BLE example programs eg iBeacon

posted by Wim Huiskamp 11 Dec 2014

Yeah, it's at the latest release. Every time I flash I've been verifying it as well.

Do I need to manually flash a softdevice or something?

Thanks again.

posted by Mark Baseggio 12 Dec 2014

Alright folks, a bit of an update. First of all thanks to everyone that helped.

It appears that mbed hex files work without any issue on one of my Chinese boards but not the other. The one I was having trouble with is labelled "XUNTONG." Even after I added a 32.768kHz crystal it didn't seem to want to do anything with the mbex hex files. While GCC compiled hex files from my linux setup were working fine.

I soldered some wires on to the other Chinese board I had (black board with 32kHz crystal and two double rows of pins on either side... and it worked fine the first time. So something could be up with those other boards who knows.

Anyway. Thanks again for all your help. Now if I can figure out the bug in the timer library I'd be very happy :) That question is here and still unsolved:

http://developer.mbed.org/questions/5505/Problems-with-timeout-timer-on-nRF51822-/

posted by Mark Baseggio 13 Dec 2014