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

Why does nRF Connect SDK not boot unless I press the reset button?

Hi,

macOS 10.14.6
Segger Embedded Studio 4.20a
nRF Connect SDK 1.0


Trying with nRF52-DK / nRF52840-DK.

When Hex (elf) is downloaded / verified with Segger Embedded Studio, it works normally.
It seems that it does not boot when the DK power is turned off and then on again.
The connected sensor is MPU6050.

I confirmed that it starts when the reset button is pushed.
Can I boot when I turn on the power without pressing the reset button?

I don't know why it doesn't boot, so if you know someone, please let me know.

The DK LED lights up.

main.c

/* main.c - Application main entry point */

/*
 * Copyright (c) 2015-2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <misc/printk.h>
#include <misc/byteorder.h>
#include <zephyr.h>

#include <settings/settings.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/conn.h>
#include <bluetooth/gatt.h>
#include <bluetooth/hci.h>
#include <bluetooth/uuid.h>

#include <sensor.h>
#include <gpio.h>

#include <stdio.h>
#include <stdlib.h>

#include "MadgwickQuaternion.h"
#include "services/ble_mpu.h"


#define OUTPUT_BUF_SIZE sizeof(float)*10
static u8_t sensor_vals[OUTPUT_BUF_SIZE];


// Timer
static volatile u32_t overflows = 0;

u32_t millis( void )
{
  u64_t ticks = (u64_t)((u64_t)overflows << (u64_t)24) | (u64_t)k_uptime_get64();

  return (ticks * 1000) / 32768;
}

u32_t micros( void )
{
  u64_t ticks = (u64_t)((u64_t)overflows << (u64_t)24) | (u64_t) k_uptime_get(); //(NRF_RTC1->COUNTER);

  return (ticks * 1000000) / 32768;
}




static inline float out_ev(struct sensor_value *val)
{
    
    bool flag = false;
    if(val->val2<0 || val->val2<0){
        flag = true;
    }
    
    val->val1 = abs(val->val1);
    val->val2 = abs(val->val2);
    
    char buf[30];
    sprintf(buf, "%d.%06d", val->val1, val->val2);
    
    float ans = (float)atof(buf);
    
    if(flag == true){
        return (-ans);
    }
    
    return ans*0.1f;
}


// sensor
static struct device* dev_mpu6050;

static struct bt_conn* p_conn = NULL;

//BLE Advertise
static volatile u8_t mfg_data[] = { 0x00, 0x00, 0xaa, 0xbb };

static const struct bt_data ad[] = {
    BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
    BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 4),
    
    BT_DATA_BYTES(BT_DATA_UUID128_ALL,
                  0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
                  0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12),
};

//IMU Quaternion value.
float q[4] = {1.0f, 0.0f, 0.0f, 0.0f};    // vector to hold quaternion
float deltat;                            // integration interval for both filter schemes
u32_t lastUpdate;
u32_t Now;

static void connected(struct bt_conn *conn, u8_t err)
{
    if (err) {
        printk("Connection failed (err %u)\n", err);
    } else {
        printk("Connected\n");
        p_conn = conn;
        
    }
}

static void disconnected(struct bt_conn *conn, u8_t reason)
{
    printk("Disconnected (reason %u)\n", reason);
    p_conn = NULL;
}

static struct bt_conn_cb conn_callbacks = {
    .connected = connected,
    .disconnected = disconnected,
};

static void bt_ready(int err)
{
    if (err) {
        printk("Bluetooth init failed (err %d)\n", err);
        return;
    }
    
    printk("Bluetooth initialized\n");
    
    //ble service init.
    bmpu_init();
    
    if (IS_ENABLED(CONFIG_SETTINGS)) {
        settings_load();
    }
    
    err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
    if (err) {
        printk("Advertising failed to start (err %d)\n", err);
        return;
    }
    
    printk("Advertising successfully started\n");
}

// Sensor data
void update_sensor_data()
{
    struct sensor_value sen_val[3];
    
    sensor_sample_fetch(dev_mpu6050);
    sensor_channel_get(dev_mpu6050, SENSOR_CHAN_ACCEL_XYZ, sen_val);
    
    Now = micros();
    deltat = ((Now - lastUpdate)/1000000.0f); // set integration time by time elapsed since last filter update
    lastUpdate = Now;
    
    float out_accel_x = out_ev(&sen_val[0]);
    float out_accel_y = out_ev(&sen_val[1]);
    float out_accel_z = out_ev(&sen_val[2]);
    
    printf("acc:   x: %.6f    y: %.6f    z: %.6f\n", out_accel_x, out_accel_y, out_accel_z);
    
    sensor_channel_get(dev_mpu6050, SENSOR_CHAN_GYRO_XYZ, sen_val);
    
    float out_gyro_x = out_ev(&sen_val[0]);
    float out_gyro_y = out_ev(&sen_val[1]);
    float out_gyro_z = out_ev(&sen_val[2]);
    
    printf("gyr:   x: %.6f    y: %.6f    z: %.6f\n", out_gyro_x, out_gyro_y, out_gyro_z);
    
    MadgwickQuaternionUpdate(out_accel_x, out_accel_y, out_accel_z,
                             out_gyro_x*PI/180.0f, out_gyro_y*PI/180.0f, out_gyro_z*PI/180.0f);
    
    printf("qua:  x: %.6f  y: %.6f  z: %.6f  w: %.6f\n", q[0], q[1], q[2], q[3]);
    
    memset(sensor_vals, 0, sizeof(sensor_vals));
    
    memcpy(&sensor_vals[sizeof(float)*0], &out_accel_x, sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*1], &out_accel_y, sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*2], &out_accel_z, sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*3], &out_gyro_x, sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*4], &out_gyro_y, sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*5], &out_gyro_z, sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*6], &q[0], sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*7], &q[1], sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*8], &q[2], sizeof(float));
    memcpy(&sensor_vals[sizeof(float)*9], &q[3], sizeof(float));
}


void main(void)
{
    /* Set LED pin as output */
    struct device* port0 = device_get_binding("GPIO_0");
    gpio_pin_configure(port0, 17, GPIO_DIR_OUT);
    
    // flash  LED
    gpio_pin_write(port0, 17, 0);
    k_sleep(500);
    gpio_pin_write(port0, 17, 1);
//    k_sleep(500);
    
    // sensor
    dev_mpu6050 = device_get_binding("MPU6050");
    printk("dev %p name %s\n", dev_mpu6050, dev_mpu6050->config->name);
    
    k_sleep(500);
    
    // set up BLE
    int err;
    err = bt_enable(bt_ready);
    if (err) {
        printk("Bluetooth init failed (err %d)\n", err);
        return;
    }
    
    bt_conn_cb_register(&conn_callbacks);
    
    while (1) {
        if(p_conn != NULL){
            if(bmpu_is_notify()){
                update_sensor_data();
                bmpu_notify(p_conn, sensor_vals, OUTPUT_BUF_SIZE);
            }
        }
        k_sleep(100);
    }
    
}

prj.conf

# Incresed stack due to settings API usage
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_STDOUT_CONSOLE=y
CONFIG_NEWLIB_LIBC=y


CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_SIGNING=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_ATT_PREPARE_COUNT=2
CONFIG_BT_PRIVACY=y
CONFIG_BT_DEVICE_NAME="Zephyr Peripheral Sample Long Name"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=65

CONFIG_BT_SETTINGS=y

CONFIG_BT_RX_BUF_LEN=258
CONFIG_BT_ATT_TX_MAX=10
CONFIG_BT_ATT_PREPARE_COUNT=2
CONFIG_BT_CONN_TX_MAX=10
CONFIG_BT_L2CAP_TX_BUF_COUNT=10
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
#CONFIG_BT_CTLR_PHY=y
#CONFIG_BT_CTLR_PHY_2M=y
CONFIG_BT_CTLR_RX_BUFFERS=2
CONFIG_BT_CTLR_TX_BUFFERS=10
CONFIG_BT_CTLR_TX_BUFFER_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
#CONFIG_BT_AUTO_PHY_UPDATE=y

CONFIG_BT_GATT_DYNAMIC_DB=y

CONFIG_HEAP_MEM_POOL_SIZE=2048


CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_FCB=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_FCB=y

##########
# for I2C 
##########
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_I2C_0_NRF_TWIM=y
CONFIG_I2C_INIT_PRIORITY=60
CONFIG_I2C_0=y
CONFIG_MPU6050_I2C_MASTER_DEV_NAME="I2C_0"

##########
# for MPU6050
##########
CONFIG_SENSOR=y
CONFIG_MPU6050=y


Best regards.

Parents Reply Children
Related