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

ADC on nRF9160 DK - Example code problems

Hi,

I am trying to get the ADC up and running on the nRF9160 DK. I had a look for example code and the latest I found was here.

https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/adc/src

Can anyone suggest an alternative?

So, when I run this, I get an error

Secure Boot: MSP_NS 200209b8

Secure Boot: prepare to jump to Non-Secure image

***** BUS FAULT *****

  Precise data bus error

  BFAR Address: 0x4000e104

***** Hardware exception *****

Current thread ID = 0x200200b4

Faulting instruction address = 0x42612

Fatal fault in essential thread! Spinning...

Looking in the code, there is a comment about setting SSADC to non secure .

I tried this in the Konfg file in the secure_boot application

config SB_NRF_SAADC_NS
bool "ADC is Non-Secure"
default y

But,Im not sure if this is correct.

Would appreciate your help.

Regards,

Rod

  • Hi Rod, 

    If you look in the commit for the secure_boot in that repo you can see that there has been added three lines.

    If you add that and reflash you should be good.


    Also adding the precompiled .hex if you have any issues: secure_boot.hex

    Use nrfjprog to flash the file, with the command: nrfjprog --program secure_boot.hex -f nrf91 --sectorerase -r --verify

  • Hey Martin, thank you for the speedy reply, I will try this (hopefully) later today and let you know, Regards,

    Rod

  • Hi Martin,

    Sorry, Im missing something obvious here, so obvious I can't see it!

    I have copied the source for the secure boot as above, and try to compile using..

    cmake -GNinja -DBOARD=nrf9160_pca10090 ..

    then, when I run ninja, I get...

    Watts-MacBook-Pro:build Watt$ ninja

    [26/105] Building C object CMakeFiles/app.dir/src/main.c.obj

    FAILED: CMakeFiles/app.dir/src/main.c.obj 

    ccache /Users/Watt/gnuarmemb/bin/arm-none-eabi-gcc -DBUILD_VERSION=v1.14.0-rc1-1246-g959abdf1c9c9 -DKERNEL -DNRF9160_XXAA -D_FORTIFY_SOURCE=2 -D__ZEPHYR__=1 -I/Users/Watt/zephyrproject/zephyr/kernel/include -I/Users/Watt/zephyrproject/zephyr/arch/arm/include -I/Users/Watt/zephyrproject/zephyr/include -I/Users/Watt/zephyrproject/zephyr/include/drivers -Izephyr/include/generated -I/Users/Watt/zephyrproject/zephyr/soc/arm/nordic_nrf/nrf91 -I/Users/Watt/zephyrproject/zephyr/soc/arm/nordic_nrf/include -I/Users/Watt/zephyrproject/zephyr/lib/libc/minimal/include -I/Users/Watt/zephyrproject/zephyr/ext/hal/cmsis/Include -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx/drivers/include -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx/hal -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx/mdk -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/. -isystem /Users/Watt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/include -isystem /Users/Watt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/include-fixed -Os -nostdinc -g -Wall -Wformat -Wformat-security -Wno-format-zero-length -imacros /Users/Watt/SD_Connect/ncs/nrf/samples/nrf9160/secure_boot/build/zephyr/include/generated/autoconf.h -ffreestanding -Wno-main -fno-common -mthumb -mcpu=cortex-m33 -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -Wno-pointer-sign -Wno-unused-but-set-variable -fno-reorder-functions -fno-defer-pop -Werror=implicit-int -Wpointer-arith -ffunction-sections -fdata-sections -mabi=aapcs -march=armv8-m.main+dsp -mcmse -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj   -c ../src/main.c

    ../src/main.c: In function 'secure_boot_config_peripherals':

    ../src/main.c:305:26: error: 'NRF_GPIO' undeclared (first use in this function); did you mean 'NRF_GPIOTE'?

       NRFX_PERIPHERAL_ID_GET(NRF_GPIO), 0);

                              ^

    ../src/main.c:83:23: note: in definition of macro 'NRFX_PERIPHERAL_ID_GET'

      (uint8_t)((uint32_t)(base_addr) >> 12)

                           ^~~~~~~~~

    ../src/main.c:305:26: note: each undeclared identifier is reported only once for each function it appears in

       NRFX_PERIPHERAL_ID_GET(NRF_GPIO), 0);

                              ^

    ../src/main.c:83:23: note: in definition of macro 'NRFX_PERIPHERAL_ID_GET'

      (uint8_t)((uint32_t)(base_addr) >> 12)

                           ^~~~~~~~~

    ../src/main.c: In function 'secure_boot_jump':

    ../src/main.c:377:13: warning: Macro is deprecated

      u32_t *vtor_ns = (u32_t *)FLASH_AREA_IMAGE_0_NONSECURE_OFFSET_0;

                 ^~~~~~~~~~~~~~~~~~~~~

    [35/105] Building C object zephyr/CMakeFiles/zephyr.dir/drivers/timer/nrf_rtc_timer.c.obj

    ninja: build stopped: subcommand failed.

    Watts-MacBook-Pro:build Watt$ 

    I guess I'm pointing to an old .h file somewhere?

    So, then I tried using your .hex file.I was able to program the board successfully with secure boot.

    When I try to build the ads code, I get more errors

    Watts-MacBook-Pro:build Watt$ ninja

    [121/128] Building C object CMakeFiles/app.dir/src/main.c.obj

    FAILED: CMakeFiles/app.dir/src/main.c.obj 

    ccache /Users/Watt/gnuarmemb/bin/arm-none-eabi-gcc -DBUILD_VERSION=v1.14.0-rc1-1246-g959abdf1c9c9 -DKERNEL -DNRF9160_XXAA -DNRF_TRUSTZONE_NONSECURE -D_FORTIFY_SOURCE=2 -D__ZEPHYR__=1 -I/Users/Watt/zephyrproject/zephyr/kernel/include -I/Users/Watt/zephyrproject/zephyr/arch/arm/include -I/Users/Watt/zephyrproject/zephyr/include -I/Users/Watt/zephyrproject/zephyr/include/drivers -Izephyr/include/generated -I/Users/Watt/zephyrproject/zephyr/soc/arm/nordic_nrf/nrf91 -I/Users/Watt/zephyrproject/zephyr/soc/arm/nordic_nrf/include -I/Users/Watt/zephyrproject/zephyr/lib/libc/minimal/include -I/Users/Watt/zephyrproject/zephyr/ext/hal/cmsis/Include -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx/drivers/include -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx/hal -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/nrfx/mdk -I/Users/Watt/zephyrproject/zephyr/ext/hal/nordic/. -I/Users/Watt/zephyrproject/zephyr/subsys/net/lib/sockets/. -isystem /Users/Watt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/include -isystem /Users/Watt/gnuarmemb/bin/../lib/gcc/arm-none-eabi/7.3.1/include-fixed -Os -nostdinc -g -Wall -Wformat -Wformat-security -Wno-format-zero-length -imacros /Users/Watt/Documents/Switch_That/Nordic_Semi_Code/ADC_Test/build/zephyr/include/generated/autoconf.h -ffreestanding -Wno-main -fno-common -mthumb -mcpu=cortex-m33 -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -Wno-pointer-sign -Wno-unused-but-set-variable -fno-reorder-functions -fno-defer-pop -Werror=implicit-int -Wpointer-arith -ffunction-sections -fdata-sections -mabi=aapcs -march=armv8-m.main+dsp -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj   -c ../src/main.c

    ../src/main.c:36:10: error: 'ADC_GAIN' undeclared here (not in a function); did you mean 'ADC_GAIN_8'?

      .gain = ADC_GAIN,

              ^~~~~~~~

              ADC_GAIN_8

    ../src/main.c:37:15: error: 'ADC_REFERENCE' undeclared here (not in a function); did you mean 'ADC_REF_VDD_1'?

      .reference = ADC_REFERENCE,

                   ^~~~~~~~~~~~~

                   ADC_REF_VDD_1

    ../src/main.c:38:22: error: 'ADC_ACQUISITION_TIME' undeclared here (not in a function); did you mean 'ADC_ACQ_TIME'?

      .acquisition_time = ADC_ACQUISITION_TIME,

                          ^~~~~~~~~~~~~~~~~~~~

                          ADC_ACQ_TIME

    ../src/main.c:39:16: error: 'ADC_1ST_CHANNEL_ID' undeclared here (not in a function)

      .channel_id = ADC_1ST_CHANNEL_ID,

                    ^~~~~~~~~~~~~~~~~~

    ../src/main.c:41:20: error: 'ADC_1ST_CHANNEL_INPUT' undeclared here (not in a function); did you mean 'ADC_1ST_CHANNEL_ID'?

      .input_positive = ADC_1ST_CHANNEL_INPUT,

                        ^~~~~~~~~~~~~~~~~~~~~

                        ADC_1ST_CHANNEL_ID

    ../src/main.c: In function 'adc_sample':

    ../src/main.c:56:17: error: 'ADC_RESOLUTION' undeclared (first use in this function)

       .resolution = ADC_RESOLUTION,

                     ^~~~~~~~~~~~~~

    ../src/main.c:56:17: note: each undeclared identifier is reported only once for each function it appears in

    ninja: build stopped: subcommand failed.

    Watts-MacBook-Pro:build Watt$ 

    Again, looks like eIm pointing to an incorrect .h file?

    I went through the errors and replaced the definitions .n the adc code, for example, replaced ADC_1ST_CHANNEL_INPUT with ADC_1ST_CHANNEL_ID. I can get the code to build but get the bus error again, but I guess Im just working round the main problem of my include files?

    Sorry for being stupid here, Im a h/w guy trying to make it in a s/w world!

    Rod

     

  • Hi Martin, I am pretty sure I have this set up OK, I cant be sure as Im away on business away from my development machine at this minute but will check on my return. If not, I will reinstall 

    Regards,

    Rod

1 2