2

I've recently purchased an nrf52840 usb dongle; however, I'm new to programming without an IDE and with Nordic products in general. I'm not getting the results I expect from my program, or indeed any results at all, though I'm not sure if my problem stems from my program or the linker script I wrote. Any help would be appreciated.

Edit: I've edited the linker script to contain all (I hope) required material. I've also posted the start-up code.

@Lundin I'm using GCC to compile and NRF Connect to program the chip via USB. I'm currently experimenting with the clock settings with no luck so far, but I have noticed in the datasheet that there is a 32 MHz internal oscillator that will supposedly turn on if the high speed clock is called and the external oscillator is not on.

LEDTest.c

// RGB LED at pins G-22,R-23,B-24

#define GPIO_BASE_ADDRESS     0x50000000
#define OUTSET_ADDRESS_OFFSET 0x508  //  1's written to this register set corresponding pins (HIGH). 0's have no effect.
#define DIRSET_ADDRESS_OFFSET 0x518  //  1's written to this register setup corresponding pins as OUTPUT. 0's have no effect.

volatile unsigned long * setupOutputPins = (volatile unsigned long *)GPIO_BASE_ADDRESS + DIRSET_ADDRESS_OFFSET;
volatile unsigned long * ledOn           = (volatile unsigned long *)GPIO_BASE_ADDRESS + OUTSET_ADDRESS_OFFSET;

void main(void){

    *setupOutputPins = 0x01C00000;  //  Make pins 22, 23, and 24 OUTPUT

    for(;;){
        *ledOn           = 0x00400000;  //  Make pin 22 HIGH
    }
}

LEDTest.ld

ENTRY (main)

MEMORY{
  FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xFF000
  RAM  (rwx) : ORIGIN = 0x20000008, LENGTH = 0x3FFF8
}

SECTIONS{
    . = 0x1000;
    .text : {
        *(vectors);
        *(.text);
    }
    .rodata : {
        *(.rodata);
    }
    flash_sdata = .;

    . = 0x20000008;
    ram_sdata = .;
    .data : AT (flash_sdata){
        *(.data);
    }
    ram_edata = .;
    data_size = ram_edata - ram_sdata;

    sbss = .;
    .bss  : {
        *(.bss)
    }
    ebss = .;
    bss_size = ebss - sbss;
}

startup.s

.section "vectors"

reset:  b   start
undef:  b   undef
swi:    b   swi
pabt:   b   pabt
dabt:   b   dabt
        nop
irq:    b   irq
fiq:    b   fiq

.text

start:
            ldr     r0, =flash_sdata
            ldr     r1, =ram_sdata
            ldr     r2, =data_size

            cmp     r2, #0
            beq     init_bss

copy:
            ldrb    r4, [r0], #1
            strb    r4, [r1], #1
            subs    r2, r2, #1
            bne     copy

init_bss:
            ldr     r0, =sbss
            ldr     r1, =ebss
            ldr     r2, =bss_size

            cmp     r2, #0
            beq     init_stack

            mov     r4, #0

zero:
            strb    r4, [r0], #1
            subs    r2, r2, #1
            bne     zero

init_stack:
            ldr     sp, =0x20040000
            bl      main

stop:   b   stop
KC Engel
  • 43
  • 1
  • 8
  • This is far too broad to answer. If you have no IDE what CRC and start-up code are you using? Where do you set clock etc? Where is your vector table? How do you download programs? And why are you using `int main (void)` in a freestanding system. You need an implementation-defined form like for example `void main (void)` and an eternal loop to prevent main() from returning. – Lundin Mar 11 '19 at 09:00
  • @Lundin Indeed. My experience in this is definitely lacking and it seems I was missing quite a bit. I've researched linker scripts and start-up code and I'm still not getting the LED on the board to light up. I'll edit my original post with the updated code. – KC Engel Mar 16 '19 at 17:14

1 Answers1

0

There are a few resources by Nordic that help you get started with nRF52840 development. Please see the following links:-

Please note that you can still use an IDE to write your applications, but as you probably already know, you then have to use Nordic's tools to flash the app onto the dongle. For more information on IDE usage, please see this:-

I hope this helps.

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72