0

I am trying to build a simply first blinkyon a nrf51822 china clone (YJ-14015), as part of building a redox wireless and debugging why the BLE communication does not work.

As SDK I use nrf5_SDK_11 as the keyboards custom firmware is based on it.

Now I tried a very minimal example blinky with main.c

#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"

#define LED_PIN_1 1           // LED connected to pin 1       

/* --> from nrf5_SDK_11/components/drivers_nrf/hal/nrf_gpio.h
__STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number)
{
    NRF_GPIO->OUTSET = (1UL << pin_number);
}

__STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
{
    NRF_GPIO->OUTCLR = (1UL << pin_number);
}
*/

int main(void)
{

    // Make LED pin an output pin
    nrf_gpio_cfg_output(LED_PIN_1);
    nrf_gpio_pin_set(LED_PIN_1);

    // Toggle LEDs.
    while (true)
    {
        // Down
        NRF_GPIO->OUTCLR = (NRF_GPIO->OUT & (1UL << LED_PIN_1));
        // nrf_gpio_pin_clear(LED_PIN_1);
        nrf_delay_ms(1000);

        // Up
        NRF_GPIO->OUTSET= (NRF_GPIO->OUT | (1UL << LED_PIN_1));
        // nrf_gpio_pin_set(LED_PIN_1);
        nrf_delay_ms(1000);
    }
}

My expectation would have been that I can see the voltage flip every second from high to low to high etc on PIN 01... Unfortunately I only get a 1.55 V vs ground if I attach it to my multi meter, but the voltage just stays constant and nothing changes. Anything I did wrong with this loop?

For flashing I use a ST-LinkV2 clone + the docker containers for openocd and the toolchain of the redox wireless project, which basically uses telnet over openocd. After adjusting for the right paths, flashing seems successful and as mentioned above, PIN 01 can be set to 1.55V, so I assume there is no problem with the flashing itself.

matthias
  • 141
  • 1
  • 6
  • 1
    The fact that your multimeter measures around half the expected voltage (3.3 V I assume) tells that the output is likely toggling between 0 and 1. Just way faster than you were expecting, maybe something is not right with the `nrf_delay_ms` function. I don't know about the NRF SDK, but maybe there is some init function that must be called to setup clocks etc. before using the delay function. – Klas-Kenny Dec 10 '21 at 15:54
  • Thank you for your suggestion. I tried to validate it by just setting the `PIN 01` outside of the while loop and then not changing it. Unfortunately this still just raises it to `1.5V`. For what it is worth, all other pins are at approx `300mV` - besides `SWCLK` which is at `3.3V`. Also I tried to raise other pins with the same effect. The raised ones are at `1.5V` all others at `300mV`. – matthias Dec 11 '21 at 18:09

1 Answers1

0

In case someone else stumbles across the same difficulties:

After quite a while, I figured out a way to fix the blinky example for the yj-14015. The key was to adjust the Makefile which I took from the nordic SDK according to the Makefile in the redox firmware.

The relevant lines being as follows:

#flags common to all targets
CFLAGS  = -DNRF51
CFLAGS += -DGAZELL_PRESENT
CFLAGS += -DBOARD_CUSTOM
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -O3 -g3
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-variable
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums


# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DNRF51
ASMFLAGS += -DGAZELL_PRESENT
ASMFLAGS += -DBOARD_CUSTOM
ASMFLAGS += -DBSP_DEFINES_ONLY

Here would be the full Makefile.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
matthias
  • 141
  • 1
  • 6