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

Routine NVS initialization returns -22

I'm attempting to make a custom program using a few different libraries based on the samples. In attempting to initialize nvs, it returns -22. I've been able to trace it deep into nvs_startup using the debugger. I see that -22 means "invalid argument", but it's unclear what is invalid and where it's being passed. The project loads and builds correctly.

main.c:

// gps

#include <zephyr.h>
#include <nrf_socket.h>
#include <net/socket.h>
#include <stdio.h>

// nvs

#include <zephyr.h>
#include <misc/reboot.h>
#include <device.h>
#include <string.h>
#include <flash.h>
#include <nvs/nvs.h>

// led

#include <zephyr.h>
#include <device.h>
#include <gpio.h>



#include <gps_.h>


struct nvs_fs fs;

int nvs_setup(){
  int retval = 0;
  struct flash_pages_info info;

  fs.offset = DT_FLASH_AREA_STORAGE_OFFSET;
//  fs.offset = PM_MCUBOOT_STORAGE_ADDRESS;
  retval = flash_get_page_info_by_offs(device_get_binding(DT_FLASH_DEV_NAME), fs.offset, &info);
  if(retval){
    printk("Unable to get page info");
    return retval;
  }

  fs.sector_size = info.size;
  fs.sector_count = 3U;

  retval = nvs_init(&fs, DT_FLASH_DEV_NAME);
  if(retval){
    printk("Flash Init failed: %d\n", retval);
    return retval;
  }
  return 0;
}


void test_(){

    //nvs  
    nvs_setup();

    //gps

//    spoof(true);
//
//    GPS_Init();
//    printk("\nGPS Initialized");
//    GPS_Enable();
//    printk("\nGPS Enabled");
//    GPS_Logging_On();
//
//    s64_t loop_timer = k_uptime_get();
//    while(1){
//        GPS_State_Machine(&fs);
//
//        while(k_uptime_get()-loop_timer <= 20);
//        loop_timer = k_uptime_get();
//    }

}


int main(){
    

    printk("running");
    test_();

    return 0;
}

prj.conf:

# gps-----------------

CONFIG_BSD_LIBRARY=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_SOCKETS=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# Disable native network stack to save some memory
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=n
CONFIG_NET_UDP=n
CONFIG_NET_TCP=n


# nvs---------------------
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y

CONFIG_NVS=y
CONFIG_LOG=y
CONFIG_NVS_LOG_LEVEL_DBG=y
CONFIG_REBOOT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y


# led---------------------
CONFIG_GPIO=y
# CONFIG_SERIAL=n








CMakeLists:

#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

cmake_minimum_required(VERSION 3.13.1)

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

# NORDIC SDK APP START
target_sources(app PRIVATE src/main.c)

# new stuff
target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/subsys/fs/nvs C:/Users/user/Desktop/includes)

target_sources(app PRIVATE C:/Users/user/Desktop/includes/gps_.c)
target_sources(app PRIVATE C:/Users/user/Desktop/includes/led.c)

# NORDIC SDK APP END

Running this gives me this output:

***** Booting Zephyr OS v1.14.99-ncs2 *****                                     
Flash region            Domain          Permissions                             
00 0x00000 0x08000      Secure          rwxl                                    
01 0x08000 0x10000      Non-Secure      rwxl                                    
02 0x10000 0x18000      Non-Secure      rwxl                                    
03 0x18000 0x20000      Non-Secure      rwxl                                    
04 0x20000 0x28000      Non-Secure      rwxl                                    
05 0x28000 0x30000      Non-Secure      rwxl                                    
06 0x30000 0x38000      Non-Secure      rwxl                                    
07 0x38000 0x40000      Non-Secure      rwxl                                    
08 0x40000 0x48000      Non-Secure      rwxl                                    
09 0x48000 0x50000      Non-Secure      rwxl                                    
10 0x50000 0x58000      Non-Secure      rwxl                                    
11 0x58000 0x60000      Non-Secure      rwxl                                    
12 0x60000 0x68000      Non-Secure      rwxl                                    
13 0x68000 0x70000      Non-Secure      rwxl                                    
14 0x70000 0x78000      Non-Secure      rwxl                                    
15 0x78000 0x80000      Non-Secure      rwxl                                    
16 0x80000 0x88000      Non-Secure      rwxl                                    
17 0x88000 0x90000      Non-Secure      rwxl                                    
18 0x90000 0x98000      Non-Secure      rwxl                                    
19 0x98000 0xa0000      Non-Secure      rwxl                                    
20 0xa0000 0xa8000      Non-Secure      rwxl                                    
21 0xa8000 0xb0000      Non-Secure      rwxl                                    
22 0xb0000 0xb8000      Non-Secure      rwxl                                    
23 0xb8000 0xc0000      Non-Secure      rwxl                                    
24 0xc0000 0xc8000      Non-Secure      rwxl                                    
25 0xc8000 0xd0000      Non-Secure      rwxl                                    
26 0xd0000 0xd8000      Non-Secure      rwxl                                    
27 0xd8000 0xe0000      Non-Secure      rwxl                                    
28 0xe0000 0xe8000      Non-Secure      rwxl                                    
29 0xe8000 0xf0000      Non-Secure      rwxl                                    
30 0xf0000 0xf8000      Non-Secure      rwxl                                    
31 0xf8000 0x100000     Non-Secure      rwxl                                    
Non-secure callable region 0 placed in flash region 0 with size 32.             
                                                                                
                                                                                
SRAM region             Domain          Permissions                             
00 0x00000 0x02000      Secure          rwxl                                    
01 0x02000 0x04000      Secure          rwxl                                    
02 0x04000 0x06000      Secure          rwxl                                    
03 0x06000 0x08000      Secure          rwxl                                    
04 0x08000 0x0a000      Secure          rwxl                                    
05 0x0a000 0x0c000      Secure          rwxl                                    
06 0x0c000 0x0e000      Secure          rwxl                                    
07 0x0e000 0x10000      Secure          rwxl                                    
08 0x10000 0x12000      Non-Secure      rwxl                                    
09 0x12000 0x14000      Non-Secure      rwxl                                    
10 0x14000 0x16000      Non-Secure      rwxl                                    
11 0x16000 0x18000      Non-Secure      rwxl                                    
12 0x18000 0x1a000      Non-Secure      rwxl                                    
13 0x1a000 0x1c000      Non-Secure      rwxl                                    
14 0x1c000 0x1e000      Non-Secure      rwxl                                    
15 0x1e000 0x20000      Non-Secure      rwxl                                    
16 0x20000 0x22000      Non-Secure      rwxl                                    
17 0x22000 0x24000      Non-Secure      rwxl                                    
18 0x24000 0x26000      Non-Secure      rwxl                                    
19 0x26000 0x28000      Non-Secure      rwxl                                    
20 0x28000 0x2a000      Non-Secure      rwxl                                    
21 0x2a000 0x2c000      Non-Secure      rwxl                                    
22 0x2c000 0x2e000      Non-Secure      rwxl                                    
23 0x2e000 0x30000      Non-Secure      rwxl                                    
24 0x30000 0x32000      Non-Secure      rwxl                                    
25 0x32000 0x34000      Non-Secure      rwxl                                    
26 0x34000 0x36000      Non-Secure      rwxl                                    
27 0x36000 0x38000      Non-Secure      rwxl                                    
28 0x38000 0x3a000      Non-Secure      rwxl                                    
29 0x3a000 0x3c000      Non-Secure      rwxl                                    
30 0x3c000 0x3e000      Non-Secure      rwxl                                    
31 0x3e000 0x40000      Non-Sec***** Booting Zephyr OS v1.14.99-ncs2 *****      
Flash region            Domain          Permissions                             
00 0x00000 0x08000      Secure          rwxl                                    
01 0x08000 0x10000      Non-Secure      rwxl                                    
02 0x10000 0x18000      Non-Secure      rwxl                                    
03 0x18000 0x20000      Non-Secure      rwxl                                    
04 0x20000 0x28000      Non-Secure      rwxl                                    
05 0x28000 0x30000      Non-Secure      rwxl                                    
06 0x30000 0x38000      Non-Secure      rwxl                                    
07 0x38000 0x40000      Non-Secure      rwxl                                    
08 0x40000 0x48000      Non-Secure      rwxl                                    
09 0x48000 0x50000      Non-Secure      rwxl                                    
10 0x50000 0x58000      Non-Secure      rwxl                                    
11 0x58000 0x60000      Non-Secure      rwxl                                    
12 0x60000 0x68000      Non-Secure      rwxl                                    
13 0x68000 0x70000      Non-Secure      rwxl                                    
14 0x70000 0x78000      Non-Secure      rwxl                                    
15 0x78000 0x80000      Non-Secure      rwxl                                    
16 0x80000 0x88000      Non-Secure      rwxl                                    
17 0x88000 0x90000      Non-Secure      rwxl                                    
18 0x90000 0x98000      Non-Secure      rwxl                                    
19 0x98000 0xa0000      Non-Secure      rwxl                                    
20 0xa0000 0xa8000      Non-Secure      rwxl                                    
21 0xa8000 0xb0000      Non-Secure      rwxl                                    
22 0xb0000 0xb8000      Non-Secure      rwxl                                    
23 0xb8000 0xc0000      Non-Secure      rwxl                                    
24 0xc0000 0xc8000      Non-Secure      rwxl                                    
25 0xc8000 0xd0000      Non-Secure      rwxl                                    
26 0xd0000 0xd8000      Non-Secure      rwxl                                    
27 0xd8000 0xe0000      Non-Secure      rwxl                                    
28 0xe0000 0xe8000      Non-Secure      rwxl                                    
29 0xe8000 0xf0000      Non-Secure      rwxl                                    
30 0xf0000 0xf8000      Non-Secure      rwxl                                    
31 0xf8000 0x100000     Non-Secure      rwxl                                    
Non-secure callable region 0 placed in flash region 0 with size 32.             
                                                                                
                                                                                
SRAM region             Domain          Permissions                             
00 0x00000 0x02000      Secure          rwxl                                    
01 0x02000 0x04000      Secure          rwxl                                    
02 0x04000 0x06000      Secure          rwxl                                    
03 0x06000 0x08000      Secure          rwxl                                    
04 0x08000 0x0a000      Secure          rwxl                                    
05 0x0a000 0x0c000      Secure          rwxl                                    
06 0x0c000 0x0e000      Secure          rwxl                                    
07 0x0e000 0x10000      Secure          rwxl                                    
08 0x10000 0x12000      Non-Secure      rwxl                                    
09 0x12000 0x14000      Non-Secure      rwxl                                    
10 0x14000 0x16000      Non-Secure      rwxl                                    
11 0x16000 0x18000      Non-Secure      rwxl                                    
12 0x18000 0x1a000      Non-Secure      rwxl                                    
13 0x1a000 0x1c000      Non-Secure      rwxl                                    
14 0x1c000 0x1e000      Non-Secure      rwxl                                    
15 0x1e000 0x20000      Non-Secure      rwxl                                    
16 0x20000 0x22000      Non-Secure      rwxl                                    
17 0x22000 0x24000      Non-Secure      rwxl                                    
18 0x24000 0x26000      Non-Secure      rwxl                                    
19 0x26000 0x28000      Non-Secure      rwxl                                    
20 0x28000 0x2a000      Non-Secure      rwxl                                    
21 0x2a000 0x2c000      Non-Secure      rwxl                                    
22 0x2c000 0x2e000      Non-Secure      rwxl                                    
23 0x2e000 0x30000      Non-Secure      rwxl                                    
24 0x30000 0x32000      Non-Secure      rwxl                                    
25 0x32000 0x34000      Non-Secure      rwxl                                    
26 0x34000 0x36000      Non-Secure      rwxl                                    
27 0x36000 0x38000      Non-Secure      rwxl                                    
28 0x38000 0x3a000      Non-Secure      rwxl                                    
29 0x3a000 0x3c000      Non-Secure      rwxl                                    
30 0x3c000 0x3e000      Non-Secure      rwxl                                    
31 0x3e000 0x40000      Non-Secure      rwxl                                    
                                                                                
Peripheral              Domain          Status                                  
00 NRF_P0               Non-Secure      OK                                      
01 NRF_CLOCK            Non-Secure      OK                                      
02 NRF_RTC1             Non-Secure      OK                                      
03 NRF_NVMC             Non-Secure      OK                                      
04 NRF_UARTE1           Non-Secure      OK                                      
05 NRF_UARTE2           Secure          SKIP                                    
06 NRF_TWIM2            Non-Secure      OK                                      
07 NRF_SPIM3            Non-Secure      OK                                      
08 NRF_TIMER0           Non-Secure      OK                                      
09 NRF_TIMER1           Non-Secure      OK                                      
10 NRF_TIMER2           Non-Secure      OK                                      
11 NRF_SAADC            Non-Secure      OK                                      
12 NRF_PWM0             Non-Secure      OK                                      
13 NRF_PWM1             Non-Secure      OK                                      
14 NRF_PWM2             Non-Secure      OK                                      
15 NRF_PWM3             Non-Secure      OK                                      
16 NRF_IPC              Non-Secure      OK                                      
17 NRF_VMC              Non-Secure      OK                                      
18 NRF_FPU              Non-Secure      OK                                      
19 NRF_EGU1             Non-Secure      OK                                      
20 NRF_EGU2             Non-Secure      OK                                      
21 NRF_GPIOTE1          Non-Secure      OK                                      
                                                                                
SPM: NS image at 0xc000                                                         
SPM: NS MSP at 0x20024368                                                       
SPM: NS reset vector at 0x13f39                                                 
SPM: prepare to jump to Non-Secure image.                                       
***** Booting Zephyr OS v1.14.99-ncs2 *****                                     
running-22NVS Startup Failed                                                    
Flash Init failed: -22 

I get the same -22 error running the nvs sample code found in zephyr/samples/subsys

How do I fix this?

Thanks

Parents Reply Children
No Data
Related