Error -12 trying to connect on NRF9160

Hi again,

Running into an issue getting the client connected. Trying to get the client to connect after I bring up the LTE modem results in the following issue:

Everything I can tell points towards the network connection being active and connected including my ability to contact a time server over the network for setting an RTC.

My Configuration is as follows:

#MCUBoot
#CONFIG_BOOTLOADER_MCUBOOT=y

#C library stuff
CONFIG_NEWLIB_LIBC_NANO=n
CONFIG_NEWLIB_LIBC=y

#General Stuff
CONFIG_COMMON_LIBC_MALLOC=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256

#Other Stuff so far
CONFIG_PM_DEVICE=y
CONFIG_POSIX_API=y

#Shell Stuff
CONFIG_SHELL=y
CONFIG_FILE_SYSTEM_SHELL=y
CONFIG_SHELL_BACKEND_SERIAL=y

#I2C Stuff
CONFIG_I2C=y
CONFIG_RTC=y
CONFIG_RTC_PCF8523=y

#SPI Stuff
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

#Flash Stuff
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

#LittleFS
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y

#Settings
CONFIG_SETTINGS=y
CONFIG_SETTINGS_SHELL=y
CONFIG_SETTINGS_FILE=y
CONFIG_SETTINGS_FILE_PATH="/lfs/settings"
CONFIG_SETTINGS_LOG_LEVEL_INF=y

#Logging
CONFIG_LOG=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_NRF_MODEM_LOG=y

#Networking
CONFIG_NETWORKING=y
CONFIG_NET_SHELL=n
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_NRF_MODEM_LIB=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
CONFIG_NET_SOCKETS=y
CONFIG_LTE_LINK_CONTROL=y
CONFIG_MODEM_INFO=y
CONFIG_SNTP=y
CONFIG_COAP=y

#From Golioth Example
CONFIG_NET_SOCKETS_TLS_PRIORITY=35
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_NET_NATIVE=n
CONFIG_NET_OFFLOAD=y



# TLS configuration
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=10240
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048


#Golioth Stuff
CONFIG_GOLIOTH=y
CONFIG_GOLIOTH_SYSTEM_CLIENT=y
CONFIG_GOLIOTH_AUTH_METHOD_PSK=y
CONFIG_GOLIOTH_SAMPLES_COMMON=y
CONFIG_GOLIOTH_SAMPLE_HARDCODED_CREDENTIALS=y
CONFIG_GOLIOTH_SAMPLE_HARDCODED_PSK_ID="XXXXXXXXXXXXXX"
CONFIG_GOLIOTH_SAMPLE_HARDCODED_PSK="XXXXXXXXXXXXXXXXX"
CONFIG_GOLIOTH_SYSTEM_CLIENT_RX_TIMEOUT_SEC=660
CONFIG_GOLIOTH_SYSTEM_CLIENT_PING_INTERVAL_SEC=600
CONFIG_GOLIOTH_LOG_LEVEL_DBG=y
#Disable options y-selected by NCS for no good reason
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED=n
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=n

# Increased sysworkq size, due to LTE connectivity
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

#Debug
CONFIG_DEBUG=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_COREDUMP=y
CONFIG_AT_SHELL=y```

Hi Camry,
It could be unrelated, but I get the same error for my ESP32 board and I struggle to fix this. Here is the thread.

Best,
Michał

@Camry I remember running into this issue when my mbedtls heap was too small. I would expect yours to not be an issue for Golioth as I do see the setting in your prj.conf file. Is there something else that might be using that memory?

I just tested out here by making the value ridiculously small (CONFIG_MBEDTLS_HEAP_SIZE=4096) and I see the same behavior as shown in your logs:

Perhaps try to increase that value and see if it solves the issue?

Bingo!

So it turns out the application needed quite a bit more memory then I thought it was going to. Got a sucesful connection to the cloud with a heap size of 65kb. Tried at 32kb but that wasnt quite enough it sems.

CONFIG_MBEDTLS_HEAP_SIZE=65536

Really, really appreciate the help on this one!. You’d think there would have been a more informative log message coming out of zephyr or mbedTls but alas.

Thank you,

1 Like

I find in Zephyr I’m always finding myself on the “error number” page. That helps point us in the right direction when looking at the cryptic errors that are thrown. Here’s the relevant error for “12”

Arguably, ‘not enough core’ isn’t all that useful either! :smiley:

https://docs.zephyrproject.org/apidoc/latest/group__system__errno.html#ga6a05c923dad0c1208043e9c20a58c8e5

Awesome, glad to hear you are unstuck!

Got a sucesful connection to the cloud with a heap size of 65kb. Tried at 32kb but that wasnt quite enough it sems.

Wow, that’s a huge chunk of RAM. I’d be interested to know what your app is doing that is calling for that much. I think most of the Golioth samples have that set closer to 10k.