diff --git a/samples/cellular/nrf_cloud_multi_service/onomondo.conf b/samples/cellular/nrf_cloud_multi_service/onomondo.conf new file mode 100644 index 000000000000..669396046969 --- /dev/null +++ b/samples/cellular/nrf_cloud_multi_service/onomondo.conf @@ -0,0 +1,57 @@ +### Onomondo SoftSIM ### +CONFIG_SOFTSIM_DEBUG=n +CONFIG_SOFTSIM_LOG_LEVEL_INF=y +CONFIG_SOFTSIM_BUNDLE_TEMPLATE_HEX=y +### Onomondo SoftSIM ### + +# Configured to allow a reboot following the provisioning of a profile +CONFIG_REBOOT=y + +# Reduce the size of TF-M by disabling the PS +CONFIG_TFM_PARTITION_PROTECTED_STORAGE=n +CONFIG_PSA_CRYPTO_DRIVER_CC3XX=n + +# Reduce the size of the TF-M partition +# when combined with static partitioning +CONFIG_PM_PARTITION_SIZE_TFM=0x10000 + +# The bootloader adds a small mcuboot_pad partition, +# whose size must be subtracted from the TF-M partition +#CONFIG_BOOTLOADER_MCUBOOT=y +#CONFIG_PM_PARTITION_SIZE_TFM=0xfe00 + +# From modules/lib/onomondo-softsim/overlay-softsim.conf +### Onomondo SoftSIM ### +# Onomondo SoftSIM Configurations +CONFIG_SOFTSIM=y +CONFIG_SOFTSIM_AUTO_INIT=y + +# NVS Configurations +CONFIG_NVS=y +CONFIG_NVS_LOG_LEVEL_ERR=y +CONFIG_PM_PARTITION_SIZE_NVS_STORAGE=0x8000 + +# Flash Configurations +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_MPU_ALLOW_FLASH_WRITE=y + +# Stack and Heap Configurations +CONFIG_MAIN_STACK_SIZE=5000 +CONFIG_HEAP_MEM_POOL_SIZE=30000 + +# TF-M Configurations +CONFIG_BUILD_WITH_TFM=y +CONFIG_TFM_PROFILE_TYPE_NOT_SET=y +CONFIG_TFM_LOG_LEVEL_SILENCE=y + +# PSA Crypto Configurations +CONFIG_PSA_WANT_ALG_CBC_NO_PADDING=y +CONFIG_PSA_WANT_ALG_ECB_NO_PADDING=y +CONFIG_PSA_WANT_ALG_CMAC=y +CONFIG_PSA_WANT_KEY_TYPE_AES=y + +# Libraries +CONFIG_NEWLIB_LIBC=y +CONFIG_FP_SOFTABI=y diff --git a/samples/cellular/nrf_cloud_multi_service/prj.conf b/samples/cellular/nrf_cloud_multi_service/prj.conf index 08d7eafaea42..83da8d256aab 100644 --- a/samples/cellular/nrf_cloud_multi_service/prj.conf +++ b/samples/cellular/nrf_cloud_multi_service/prj.conf @@ -11,7 +11,9 @@ CONFIG_MULTI_SERVICE_LOG_LEVEL_INF=y # General config CONFIG_EVENTS=y -CONFIG_PICOLIBC_IO_FLOAT=y +CONFIG_NEWLIB_LIBC=y +CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y +#CONFIG_PICOLIBC_IO_FLOAT=y CONFIG_RESET_ON_FATAL_ERROR=y CONFIG_NCS_SAMPLES_DEFAULTS=y @@ -78,10 +80,10 @@ CONFIG_NRF_CLOUD_MQTT=y # This also enables FOTA by implicitly setting CONFIG_NR CONFIG_MQTT_KEEPALIVE=120 # MCUBOOT - Needed by FOTA -CONFIG_BOOTLOADER_MCUBOOT=y -CONFIG_IMG_MANAGER=y -CONFIG_MCUBOOT_IMG_MANAGER=y -CONFIG_STREAM_FLASH_ERASE=y +#CONFIG_BOOTLOADER_MCUBOOT=y +#CONFIG_IMG_MANAGER=y +#CONFIG_MCUBOOT_IMG_MANAGER=y +#CONFIG_STREAM_FLASH_ERASE=y # Location Services configuration CONFIG_LOCATION=y diff --git a/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c b/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c index 9095da21acc7..04feb752ea54 100644 --- a/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c +++ b/samples/cellular/nrf_cloud_multi_service/src/cloud_connection.c @@ -7,11 +7,19 @@ #include #include #include +#include +#include #include #include #include #include #include +#if defined(CONFIG_SOFTSIM) +#include +#include +#include +#include +#endif #if defined(CONFIG_NRF_CLOUD_COAP) #include #include "fota_support_coap.h" @@ -35,6 +43,97 @@ LOG_MODULE_REGISTER(cloud_connection, CONFIG_MULTI_SERVICE_LOG_LEVEL); #define DATE_TIME_KNOWN BIT(4) static K_EVENT_DEFINE(cloud_events); +#if defined(CONFIG_SOFTSIM) +#define PROFILE_MAX_SIZE 360 +static const struct device *const uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0)); +K_SEM_DEFINE(profile_received, 0, 1); + +struct rx_buf_t { + char *buf; + size_t len; + size_t pos; +}; + +/* read profile from uart */ +void serial_cb(const struct device *dev, void *user_data) +{ + int rx_recv = 0; + struct rx_buf_t *rx = (struct rx_buf_t *)user_data; + char *rx_buf = rx->buf; + size_t *rx_buf_pos = &rx->pos; + + if (!uart_irq_update(uart_dev)) { + return; + } + + while (uart_irq_rx_ready(uart_dev)) { + rx_recv = uart_fifo_read(uart_dev, &rx_buf[*rx_buf_pos], 1); + + /* Search for those end of line characters */ + if ((rx_buf[*rx_buf_pos] == '\n') || + (rx_buf[*rx_buf_pos] == '\r')) { + rx_buf[*rx_buf_pos] = 0; + k_sem_give(&profile_received); + return; + } + } + + *rx_buf_pos += rx_recv; +} + +void check_for_softsim(void) +{ + if (nrf_softsim_check_provisioned()) { + LOG_INF("SoftSIM is provisioned."); + return; + } + + LOG_INF("Waiting for SoftSIM profile..."); + + if (!device_is_ready(uart_dev)) { + LOG_ERR("UART device not found!"); + return; + } + + char *profile_read_from_external_source = k_malloc(PROFILE_MAX_SIZE); + + __ASSERT_NO_MSG(profile_read_from_external_source != NULL); + + struct rx_buf_t rx = { + .buf = profile_read_from_external_source, + .len = PROFILE_MAX_SIZE, + .pos = 0, + }; + + uart_irq_callback_user_data_set(uart_dev, serial_cb, &rx); + uart_irq_rx_enable(uart_dev); + + do { + LOG_INF("Transfer SoftSIM profile using serial COM port, " + "terminate by newline character (return key)"); + } while (k_sem_take(&profile_received, K_SECONDS(20))); + + LOG_INF("Profile received: %d characters in total", rx.pos); + + uart_irq_rx_disable(uart_dev); + + if (nrf_softsim_provision((uint8_t *)profile_read_from_external_source, rx.pos) != 0) { + LOG_ERR("SoftSIM Profile provisioning failed"); + } + + if (profile_read_from_external_source != NULL) { + k_free(profile_read_from_external_source); + } + + /* Soft reset to free uart for AT host/monitor */ + while (log_data_pending()) { + log_process(); + k_yield(); + } + sys_reboot(0); +} +#endif /* CONFIG_SOFTSIM */ + /* Atomic status flag tracking whether an initial association is in progress. */ atomic_t initial_association; @@ -559,6 +658,10 @@ static void check_credentials(void) void cloud_connection_thread_fn(void) { +#if defined(CONFIG_SOFTSIM) + check_for_softsim(); +#endif + long_led_pattern(LED_WAITING); LOG_INF("Enabling connectivity...");