Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Accessing the underlying Nordic SDK #58

Open
@theelims

Description

@theelims

The last days I tried to gain access to the Nordic SDK below the mbed layer. My application needs tight timings and the mbed timers caused to much jitter. Therefore I tried going with the hardware timer and nrf52's PPI module. I tried to get a modified timer-example from the nordic SDK to compile. So far without success. I reached a dead end and are looking for advice.

  1. I learned about the role of sdk_config.h and how to overwrite the default configuration with the right defines.
  2. There are many missing headers and source files for the SDK. Some are already missing in the original mbed repos. But the arduino repo dismissed even more:
    ArduinoCore-nRF528x-mbedos/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/src is missing all source files. The headers are complete. The mbed repo still has all sources present.
    ArduinoCore-nRF528x-mbedos/cores/arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/legacy/ The legacy layer is missing most files also. But mbed is not better here.

I copied all missing files (nrfx_timer.c & nrf_drv_timer.h) into their respective folder. I took them from the nordic SDK 15.0.

  1. The compiler seems to find all headers now. However, the linker throws some errors:
Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano 33 BLE"
sketch\sketch_mar06a.ino.cpp.o: In function `setup':
C:\Users\elims\Documents\Arduino\Tests\sketch_mar06a/sketch_mar06a.ino:51: undefined reference to `nrfx_timer_init'
C:\Users\elims\Documents\Arduino\Tests\sketch_mar06a/sketch_mar06a.ino:56: undefined reference to `nrfx_timer_extended_compare'
C:\Users\elims\Documents\Arduino\Tests\sketch_mar06a/sketch_mar06a.ino:59: undefined reference to `nrfx_timer_enable'
collect2.exe: error: ld returned 1 exit status
exit status 1

Here is the actual code I'm trying to compile. Via googling I got the hint, that it doesn't find the nrfx_timer.c. The include paths in the includes.txt are all set to these folders. How do I tell the linker where to look?

//override settings in sdk_config.h to enable timer support
#define NRFX_TIMER_ENABLED 1
#define NRFX_TIMER0_ENABLED 1
//enable legacy support
#define TIMER_ENABLED 1
#define TIMER0_ENABLED 1


#include "nrf.h"
#include "nrf_drv_timer.h"
#include "app_error.h"

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);

mbed::DigitalOut led1(digitalPinToPinName(LED_BUILTIN));
 
void flip() {
    led1 = !led1;
}

/**
 * @brief Handler for timer events.
 */
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            flip();
            break;

        default:
            //Do nothing.
            break;
    }
}

void setup() {
    uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    //Configure all leds on board.
    led1 = 1;

    //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);

    nrf_drv_timer_extended_compare(
         &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&TIMER_LED);
}
 
void loop() {
  while(1){
    __WFI();
  }
}

Arduino and mbed are perfect for most high level stuff. However, some things need to be done with dedicated hardware peripherals. I would highly appreciate if it would be possible to use the advanced hardware features of this fantastic chip out of the arduino environment. Like it is possible an all other platforms.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions