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

Getting Consistently Stuck at A Secure Boot Spin with Basic Configuration on nRF9160 DK

Hi,

I understand there have been a few changes in the nRF Connect SDK with regards to Secure Boot and SPM.

I've been stuck for many hours trying to understand why I'm stuck in a boot loop in the secure partition, and never reach application code.

My files appear as follows:


CMakeLists.txt

# SPDX-License-Identifier: Apache 2.0

cmake_minimum_required(VERSION 3.13.1)

# Define non-secure nRF9160_DK board
set(BOARD "nrf9160_pca10090ns")

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(nrf9160_adc_demo)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

nrf9160_pca10090.overlay

&led0 {
	gpios = <&gpio0 12 GPIO_INT_ACTIVE_LOW>;
	status = "enabled";
};

&adc {
	status = "okay";
};

nrf9160_pca10090ns.overlay

nrf9160_pca10090

prj.conf

CONFIG_BSD_LIBRARY=y
CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NETWORKING=y
CONFIG_NET_BUF_USER_DATA_SIZE=1
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_RAW_MODE=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_LOG=n
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_HEAP_MEM_POOL_SIZE=1024
# LTE link control
CONFIG_LTE_LINK_CONTROL=n
CONFIG_ADC=y
CONFIG_ADC_0=y
CONFIG_ADC_NRFX_SAADC=y
CONFIG_MAIN_STACK_SIZE=4096

main.c

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <nrf9160.h>
#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <stdio.h>
#include <gpio.h>
#include <misc/util.h>
#include <misc/printk.h>
#include <console.h>
#include <stdlib.h>
#include <string.h>
#include <uart.h>
#include <adc.h>


/* 1000 msec = 1 sec */
#define SLEEP_TIME 	2000

#define PULL_UP 0
#define EDGE 0

#define LEAK_DETECT_PIN 14
int choice;

struct device *adc_dev;
//#define CONFIG_BOARD_NRF9160_PCA10090NS

#if defined(CONFIG_BOARD_NRF52_PCA10040) ||                                    \
	defined(CONFIG_BOARD_NRF52840_PCA10056) ||                             \
	defined(CONFIG_BOARD_NRF9160_PCA10090NS) ||                              \
	defined(CONFIG_BOARD_NRF52840_BLIP)

#include <hal/nrf_saadc.h>
#define ADC_DEVICE_NAME DT_ADC_0_NAME
#define ADC_RESOLUTION 10
#define ADC_GAIN ADC_GAIN_1_6
#define ADC_REFERENCE ADC_REF_INTERNAL
#define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)
#define ADC_1ST_CHANNEL_ID 0
#define ADC_1ST_CHANNEL_INPUT_POSITIVE NRF_SAADC_INPUT_AIN1 // Not using AIN0 as it is positioned on other size of board. 
#define ADC_1ST_CHANNEL_INPUT_NEGATIVE NRF_SAADC_INPUT_AIN2

#endif

static const struct adc_channel_cfg m_1st_channel_cfg = {
	.gain = ADC_GAIN,
	.reference = ADC_REFERENCE,
	.acquisition_time = ADC_ACQUISITION_TIME,
	.channel_id = ADC_1ST_CHANNEL_ID,
#if defined(CONFIG_ADC_CONFIGURABLE_INPUTS)
	.input_positive = ADC_1ST_CHANNEL_INPUT_POSITIVE,
	.input_negative = ADC_1ST_CHANNEL_INPUT_NEGATIVE,
	.differential   = 1,
#endif
};

#define BUFFER_SIZE 1
static s16_t m_sample_buffer[BUFFER_SIZE];

static int adc_sample(void)
{
	int ret;

	const struct adc_sequence sequence = {
		.channels = BIT(ADC_1ST_CHANNEL_ID),
		.buffer = m_sample_buffer,
		.buffer_size = sizeof(m_sample_buffer),
		.resolution = ADC_RESOLUTION,
	};

	if (!adc_dev) {
		return -1;
	}

	ret = adc_read(adc_dev, &sequence);
//	printk("ADC read err: %d\n", ret);

	/* Print the AIN0 values */
	for (int i = 0; i < BUFFER_SIZE; i++) {

		float adc_voltage = 0;
		adc_voltage = (float)(((float)m_sample_buffer[i] / 1023.0f) *
				      3600.0f);
//		printk("ADC raw value: %d\n", m_sample_buffer[i]);
		printf("Measured voltage : %f mV\n", adc_voltage);
		
	}
		
		return ret;
}







void main(void)
{

int err;
	int count;

	printk("Pressure Test Selected\n");

	count =0;

	adc_dev = device_get_binding("ADC_0");
	if (!adc_dev) {
		printk("device_get_binding ADC_0 failed\n");
	}
	err = adc_channel_setup(adc_dev, &m_1st_channel_cfg);
	if (err) {
		printk("Error in adc setup: %d\n", err);
	}

	/* Trigger offset calibration
	 * As this generates a _DONE and _RESULT event
	 * the first result will be incorrect.
	 */
	NRF_SAADC_NS->TASKS_CALIBRATEOFFSET = 1;

	for(count = 1; count < 3; count++) {

		err = adc_sample();

//		printk("Err Value: %f\n", err);

		
		if (err) {
			printk("Error in adc sampling: %d\n", err);
		}



		k_sleep(500);
	}


}

To ensure things aren't going stale, I'm doing an rm -rf build/* before each cmake -GNinja ..

On the tty, I'm just getting text from the Secure environment where it is initializing the peripherals, but it seems to be corrupted (as if two processes are asynchronously writing over each other) and it just spins forever.

Any help would be appreciated.

Regards,

Ben

Parents Reply Children
No Data
Related