Voice Activity Detection example application added
Change-Id: I720d54e6c3c3db601b2fd7e90011dc9307296aef
Co-authored-by: Bence Balogh <bence.balogh@arm.com>
Signed-off-by: Mark Horvath <mark.horvath@arm.com>
diff --git a/examples/examples_readme.rst b/examples/examples_readme.rst
index 9b7faac..feddd68 100755
--- a/examples/examples_readme.rst
+++ b/examples/examples_readme.rst
@@ -40,6 +40,19 @@
-----------
Jianliang Shen `<jianliang.shen@arm.com> <jianliang.shen@arm.com>`_
+vad_an552
+=========
+
+Description
+-----------
+Example application for the AN552 FPGA image, details can be found
+`here </examples/vad_an552/readme.rst>`.
+
+Maintainers
+-----------
+- Gabor Toth `<gabor.toth@arm.com> <gabor.toth@arm.com>`_
+- Mark Horvath `<mark.horvath@arm.com> <mark.horvath@arm.com>`_
+
---------------------------
*Copyright (c) 2021-2022, Arm Limited. All rights reserved.*
diff --git a/examples/vad_an552/ns_side/CMakeLists.txt b/examples/vad_an552/ns_side/CMakeLists.txt
new file mode 100644
index 0000000..9a78606
--- /dev/null
+++ b/examples/vad_an552/ns_side/CMakeLists.txt
@@ -0,0 +1,377 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+############################# Configuration ############################################
+set(VAD_AN552_NO_CONNECTIVITY OFF CACHE BOOL "If turned on the network is not used")
+
+############################# External Dependencies ############################################
+
+set(AMAZON_FREERTOS_SRC_PATH "DOWNLOAD" CACHE PATH "Path to Amazon FreeRTOS (or DOWNLOAD to fetch automatically")
+set(FREERTOS_KERNEL_SRC_PATH "DOWNLOAD" CACHE PATH "Path to FreeRTOS kernel (or DOWNLOAD to fetch automatically")
+set(PKCS11_PSA_SRC_PATH "DOWNLOAD" CACHE PATH "Path to freertos-pkcs11-psa (or DOWNLOAD to fetch automatically")
+set(OTA_FOR_AWS_SRC_PATH "DOWNLOAD" CACHE PATH "Path to OTA for AWS (or DOWNLOAD to fetch automatically")
+set(OTA_PAL_PSA_SRC_PATH "DOWNLOAD" CACHE PATH "Path to freertos-ota-pal-psa (or DOWNLOAD to fetch automatically")
+
+add_subdirectory(ext/amazon-freertos)
+add_subdirectory(ext/freertos-kernel)
+add_subdirectory(ext/freertos-pkcs11-psa)
+add_subdirectory(ext/ota-for-aws)
+add_subdirectory(ext/freertos-ota-pal-psa)
+
+############################# Common variables ############################################
+
+# In actual NS integration, NS side build should include the source files
+# exported by TF-M build.
+# Directly include interface folder to simplify the NS build in this demo, since
+# install always occurs at the end of build.
+set(INTERFACE_SRC_DIR ${CMAKE_SOURCE_DIR}/interface/src)
+set(INTERFACE_INC_DIR ${CMAKE_SOURCE_DIR}/interface/include)
+
+#################### TF-M NS interface (header only) ###########################
+
+add_library(tfm_ns_interface INTERFACE)
+
+# Include interface headers exported by TF-M
+target_include_directories(tfm_ns_interface
+ INTERFACE
+ ${INTERFACE_INC_DIR}
+ ${CMAKE_BINARY_DIR}/generated/interface/include
+)
+
+# PSA interface files are generated from a template
+add_dependencies(tfm_ns_interface
+ tfm_generated_files
+)
+
+# Include selection of Secure Partitions from TF-M build.
+# It can be replaced by NS side configurations later.
+target_link_libraries(tfm_ns_interface
+ INTERFACE
+ tfm_partition_defs
+)
+
+target_compile_definitions(tfm_ns_interface
+ INTERFACE
+ TFM_PSA_API
+)
+
+############################# TFM NS app #######################################
+
+add_executable(tfm_ns)
+
+target_sources(tfm_ns
+ PRIVATE
+ main_ns.c
+ smsc9220_eth_drv.c
+ NetworkInterface.c
+ platform_eth_dev.c
+ ota_provision.c
+ print_log.c
+ amazon-freertos/publish_aws.c
+
+ # aws demo
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/demo_runner/aws_demo.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/demo_runner/aws_demo_network_addr.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/demo_runner/iot_demo_freertos.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/demo_runner/iot_demo_runner.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/network_manager/aws_iot_network_manager.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/common/mqtt_subscription_manager/mqtt_subscription_manager.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/dev_mode_key_provisioning/src/aws_dev_mode_key_provisioning.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/ota/ota_demo_core_mqtt/ota_demo_core_mqtt.c
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/common/pkcs11_helpers/pkcs11_helpers.c
+ # freeRTOS kernel files
+ ${FREERTOS_KERNEL_SRC_PATH}/portable/GCC/ARM_CM55_NTZ/non_secure/port.c
+ ${FREERTOS_KERNEL_SRC_PATH}/portable/GCC/ARM_CM55_NTZ/non_secure/portasm.c
+ ${FREERTOS_KERNEL_SRC_PATH}/list.c
+ ${FREERTOS_KERNEL_SRC_PATH}/queue.c
+ ${FREERTOS_KERNEL_SRC_PATH}/tasks.c
+ ${FREERTOS_KERNEL_SRC_PATH}/stream_buffer.c
+ ${FREERTOS_KERNEL_SRC_PATH}/timers.c
+ ${FREERTOS_KERNEL_SRC_PATH}/event_groups.c
+ ${FREERTOS_KERNEL_SRC_PATH}/portable/MemMang/heap_4.c
+ ${FREERTOS_KERNEL_SRC_PATH}/portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c
+ # freertos plus tcp
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/portable/BufferManagement/BufferAllocation_2.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_ARP.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_DHCP.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_DNS.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_IP.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_Sockets.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_Stream_Buffer.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_TCP_IP.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_TCP_WIN.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/FreeRTOS_UDP_IP.c
+ # amazon-freertos platform layer
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/freertos/iot_clock_freertos.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/freertos/iot_metrics.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/freertos/iot_network_freertos.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/freertos/iot_threads_freertos.c
+ # secure sockets
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/secure_sockets/freertos_plus_tcp/iot_secure_sockets.c
+ # c sdk common
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/common/iot_init.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/common/taskpool/iot_taskpool.c
+ # core MQTT
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT/source/core_mqtt.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT/source/core_mqtt_state.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT/source/core_mqtt_serializer.c
+ # MQTT agent
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/mqtt_agent/freertos_command_pool.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/mqtt_agent/freertos_agent_message.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT-Agent/source/core_mqtt_agent.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT-Agent/source/core_mqtt_agent_command_functions.c
+ # backoff algorithm
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/backoff_algorithm/source/backoff_algorithm.c
+ # secure sockets
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/transport/secure_sockets/transport_secure_sockets.c
+ # tls
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/tls/src/iot_tls.c
+ # freertos plus standard crypto
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/crypto/src/iot_crypto.c
+ # pkcs11
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/pkcs11/corePKCS11/source/core_pkcs11.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/pkcs11/corePKCS11/source/core_pki_utils.c
+ ${PKCS11_PSA_SRC_PATH}/iot_pkcs11_psa.c
+ ${PKCS11_PSA_SRC_PATH}/iot_pkcs11_psa_input_format.c
+ ${PKCS11_PSA_SRC_PATH}/iot_pkcs11_psa_object_management.c
+ # OTA for aws
+ ${OTA_FOR_AWS_SRC_PATH}/source/portable/os/ota_os_freertos.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/ota_base64.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/ota_cbor.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/ota_interface.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/ota_mqtt.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/ota.c
+ # OTA PAL
+ ${OTA_PAL_PSA_SRC_PATH}/ota_pal.c
+ ${OTA_PAL_PSA_SRC_PATH}/version/application_version.c
+ # Core JSON
+ ${OTA_FOR_AWS_SRC_PATH}/source/dependency/coreJSON/source/core_json.c
+ # CBOR
+ ${OTA_FOR_AWS_SRC_PATH}/source/dependency/3rdparty/tinycbor/src/cborencoder.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/dependency/3rdparty/tinycbor/src/cborparser.c
+ ${OTA_FOR_AWS_SRC_PATH}/source/dependency/3rdparty/tinycbor/src/cborencoder_close_container_checked.c
+ # mbedTLS
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls_utils/mbedtls_error.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls_utils/mbedtls_utils.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/aes.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/aesni.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/arc4.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/aria.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/asn1parse.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/asn1write.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/base64.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/bignum.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/blowfish.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/camellia.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ccm.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/certs.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/chacha20.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/chachapoly.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/cipher.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/cipher_wrap.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/cmac.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ctr_drbg.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/debug.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/des.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/dhm.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ecdh.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ecdsa.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ecjpake.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ecp.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ecp_curves.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/entropy.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/entropy_poll.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/error.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/gcm.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/havege.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/hkdf.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/hmac_drbg.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/md.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/md_wrap.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/md2.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/md4.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/md5.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/memory_buffer_alloc.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/net_sockets.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/nist_kw.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/oid.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/padlock.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pem.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pk.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pk_wrap.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pkcs11.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pkcs12.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pkcs5.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pkparse.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/pkwrite.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/platform.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/platform_util.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/poly1305.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ripemd160.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/rsa.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/rsa_internal.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/sha1.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/sha256.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/sha512.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_cache.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_ciphersuites.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_cli.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_cookie.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_srv.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_ticket.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/ssl_tls.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/threading.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/timing.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/version.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/version_features.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509_create.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509_crl.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509_crt.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509_csr.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509write_crt.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/x509write_csr.c
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/library/xtea.c
+)
+
+target_include_directories(tfm_ns
+ PRIVATE
+ .
+ ${TFM_TEST_PATH}/../ns_interface
+ ${INTERFACE_INC_DIR}/
+ ../../../partitions/vad_an552_sp/ns_interface
+ amazon-freertos
+
+ # aws demo
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/include
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/network_manager/
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/dev_mode_key_provisioning/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/common/mqtt_subscription_manager
+ ${AMAZON_FREERTOS_SRC_PATH}/demos/common/pkcs11_helpers
+ # freeRTOS kernel
+ ${FREERTOS_KERNEL_SRC_PATH}/include/
+ ${FREERTOS_KERNEL_SRC_PATH}/portable/GCC/ARM_CM55_NTZ/non_secure/
+ # freertos plus tcp
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_tcp/portable/Compiler/GCC
+ # amazon-freertos platform layer
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/freertos/include
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/freertos/include/platform
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/include/platform
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/platform/include/types
+ # secure sockets
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/secure_sockets/include/
+ # c sdk common
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/common/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/common/include/types
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/common/include/private
+ # c sdk mqtt
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/mqtt/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/mqtt/include/types/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/c_sdk/standard/mqtt/src/private/
+ # core MQTT
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT/source/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT/source/interface/
+ # MQTT agent
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/mqtt_agent/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/coreMQTT-Agent/source/include
+ # backoff algorithm
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/backoff_algorithm/source/include
+ # secure sockets
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/transport/secure_sockets
+ # tls
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/tls/include
+ # freertos plus standard crypto
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/crypto/include
+ # mbedtls
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls/include
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls_config
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/mbedtls_utils
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/posix/include/
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/posix/include/FreeRTOS_POSIX
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/freertos_plus/standard/freertos_plus_posix/include
+ # pkcs11
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/3rdparty/pkcs11
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/pkcs11/corePKCS11/source/include
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/pkcs11/corePKCS11/source/dependency/3rdparty/mbedtls_utils
+ ${AMAZON_FREERTOS_SRC_PATH}/libraries/abstractions/pkcs11/corePKCS11/source/dependency/3rdparty/pkcs11
+ ${PKCS11_PSA_SRC_PATH}
+ # OTA for AWS
+ ${OTA_FOR_AWS_SRC_PATH}/source/include
+ ${OTA_FOR_AWS_SRC_PATH}/source/portable/os
+ # OTA PAL PSA
+ ${OTA_PAL_PSA_SRC_PATH}
+ # CBOR
+ ${OTA_FOR_AWS_SRC_PATH}/source/dependency/3rdparty/tinycbor/src
+ # CoreJSON
+ ${OTA_FOR_AWS_SRC_PATH}/source/dependency/coreJSON/source/include/
+)
+
+target_compile_definitions(tfm_ns
+ PRIVATE
+ MBEDTLS_CONFIG_FILE="aws_mbedtls_config.h"
+ $<$<BOOL:${VAD_AN552_NO_CONNECTIVITY}>:VAD_AN552_NO_CONNECTIVITY>
+)
+
+target_link_libraries(tfm_ns
+ PRIVATE
+ platform_ns
+ tfm_api_ns
+ tfm_s_veneers
+)
+
+set_target_properties(tfm_ns PROPERTIES
+ SUFFIX ".axf"
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
+)
+
+target_link_options(tfm_ns
+ PRIVATE
+ $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
+ $<$<C_COMPILER_ID:ARMClang>:--map>
+ $<$<C_COMPILER_ID:IAR>:--map\;${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
+)
+
+add_convert_to_bin_target(tfm_ns)
+
+###################### TF-M NS interface api (NS lib) ##########################
+
+add_library(tfm_api_ns STATIC)
+
+target_sources(tfm_api_ns PRIVATE
+ $<$<BOOL:${TFM_PARTITION_PLATFORM}>:${INTERFACE_SRC_DIR}/tfm_platform_ipc_api.c>
+ $<$<BOOL:${TFM_PARTITION_PROTECTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_ps_ipc_api.c>
+ $<$<BOOL:${TFM_PARTITION_INTERNAL_TRUSTED_STORAGE}>:${INTERFACE_SRC_DIR}/tfm_its_ipc_api.c>
+ $<$<BOOL:${TFM_PARTITION_CRYPTO}>:${INTERFACE_SRC_DIR}/tfm_crypto_ipc_api.c>
+ $<$<BOOL:${TFM_PARTITION_INITIAL_ATTESTATION}>:${INTERFACE_SRC_DIR}/tfm_initial_attestation_ipc_api.c>
+ $<$<BOOL:${TFM_PARTITION_FIRMWARE_UPDATE}>:${INTERFACE_SRC_DIR}/tfm_firmware_update_ipc_api.c>
+
+ # vad_an552 secure partition is needed for this demo
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../partitions/vad_an552_sp/ns_interface/vad_an552_ipc_api.c
+)
+
+target_sources(tfm_api_ns PRIVATE
+ ${INTERFACE_SRC_DIR}/tfm_psa_ns_api.c
+ ${TFM_TEST_REPO_PATH}/app/tfm_ns_interface.c
+)
+
+target_include_directories(tfm_api_ns PRIVATE
+ ${TFM_TEST_REPO_PATH}/ns_interface
+)
+
+target_link_libraries(tfm_api_ns
+ PUBLIC
+ tfm_ns_interface
+ PRIVATE
+ platform_ns
+)
+
+############################# CMSIS ############################################
+
+# Platform cmake config adds sources to CMSIS_5_tfm_ns, so we need to define it, but it is unused.
+add_library(CMSIS_5_tfm_ns INTERFACE)
diff --git a/examples/vad_an552/ns_side/NetworkInterface.c b/examples/vad_an552/ns_side/NetworkInterface.c
new file mode 100644
index 0000000..6928a8e
--- /dev/null
+++ b/examples/vad_an552/ns_side/NetworkInterface.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "FreeRTOS.h"
+#include "task.h"
+#include "FreeRTOS_IP.h"
+#include "FreeRTOS_Sockets.h"
+#include "NetworkBufferManagement.h"
+#include "NetworkInterface.h"
+#include "FreeRTOS_IP_Private.h"
+#include "semphr.h"
+
+#include "cmsis.h"
+#include "platform_eth_dev.h"
+#include "smsc9220_eth_drv.h"
+
+static TaskHandle_t xReceiveTaskHandle = NULL;
+static SemaphoreHandle_t xTXSemaphore;
+
+static void smsc9220_Receive_task(void *pvParameters);
+
+static void wait_ms(int sleep_ms)
+{
+ vTaskDelay(pdMS_TO_TICKS(sleep_ms));
+}
+
+BaseType_t xNetworkInterfaceInitialise(void)
+{
+ enum smsc9220_error_t ret = SMSC9220_ERROR_NONE;
+ char MACaddr[ipMAC_ADDRESS_LENGTH_BYTES] = {0};
+
+ ret = smsc9220_init(Ð_DEV, &wait_ms);
+
+ if (ret != SMSC9220_ERROR_NONE) {
+ FreeRTOS_debug_printf(("Error in SMSC 9220 Ethernet init.\n"));
+ return pdFALSE;
+ } else {
+ FreeRTOS_debug_printf(("SMSC 9220 Ethernet driver initialized.\n"));
+ }
+
+ /* Init FIFO level interrupts: use Rx status level irq to trigger
+ * interrupts for any non-processed packets, while Tx is not irq driven */
+ smsc9220_set_fifo_level_irq(Ð_DEV,
+ SMSC9220_FIFO_LEVEL_IRQ_RX_STATUS_POS,
+ SMSC9220_FIFO_LEVEL_IRQ_LEVEL_MIN);
+
+ smsc9220_read_mac_address(Ð_DEV, MACaddr);
+ FreeRTOS_UpdateMACAddress((const uint8_t *)MACaddr);
+
+ xTXSemaphore = xSemaphoreCreateMutex();
+
+ /* Create receiver task */
+ xTaskCreate(smsc9220_Receive_task, "smsc9220 receive", 4096, NULL,
+ configMAX_PRIORITIES-2, &xReceiveTaskHandle);
+
+ return pdTRUE;
+}
+
+BaseType_t xNetworkInterfaceOutput(
+ NetworkBufferDescriptor_t * const pxDescriptor,
+ BaseType_t xReleaseAfterSend)
+{
+ enum smsc9220_error_t ret;
+ xSemaphoreTake(xTXSemaphore, portMAX_DELAY);
+ ret = smsc9220_send_by_chunks(Ð_DEV,
+ (uint32_t)pxDescriptor->xDataLength, true,
+ (char*)pxDescriptor->pucEthernetBuffer,
+ (uint32_t)pxDescriptor->xDataLength);
+ xSemaphoreGive(xTXSemaphore);
+
+ if (ret != SMSC9220_ERROR_NONE) {
+ FreeRTOS_debug_printf(("error in send_by_chunks\r\n"));
+ }
+
+ /* Call the standard trace macro to log the send event. */
+ iptraceNETWORK_INTERFACE_TRANSMIT();
+
+ if (xReleaseAfterSend == pdTRUE) {
+ vReleaseNetworkBufferAndDescriptor(pxDescriptor);
+ }
+
+ return pdTRUE;
+}
+
+void ETHERNET_Handler(void)
+{
+ BaseType_t taskWoken = pdFALSE;
+ if (smsc9220_get_interrupt(Ð_DEV,
+ SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL)) {
+
+ smsc9220_disable_interrupt(Ð_DEV,
+ SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL);
+ smsc9220_clear_interrupt(Ð_DEV,
+ SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL);
+ NVIC_ClearPendingIRQ(ETHERNET_IRQn);
+
+ vTaskNotifyGiveFromISR(xReceiveTaskHandle, &taskWoken);
+ portYIELD_FROM_ISR(taskWoken);
+ }
+}
+
+static void smsc9220_Receive_task(void *pvParameters)
+{
+ FreeRTOS_debug_printf(("smsc9220 ethernet receive task created\r\n"));
+ uint32_t message_length = 0;
+ NetworkBufferDescriptor_t *pxBufferDescriptor;
+ IPStackEvent_t xRxEvent;
+
+ NVIC_SetPriority(ETHERNET_IRQn, configMAC_INTERRUPT_PRIORITY);
+ NVIC_EnableIRQ(ETHERNET_IRQn);
+
+ while (1) {
+ smsc9220_enable_interrupt(Ð_DEV,
+ SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL);
+ /* Sleep thread until notified from Ethernet ISR */
+ ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
+
+ /* Peak transfer size */
+ message_length = smsc9220_peek_next_packet_size(Ð_DEV);
+ if (message_length == 0) {
+ /* There are no packets to read */
+ continue;
+ }
+
+ /* Allocate a network buffer descriptor that points to a buffer
+ large enough to hold the received frame. As this is the simple
+ rather than efficient example the received data will just be copied
+ into this buffer. */
+ pxBufferDescriptor =
+ pxGetNetworkBufferWithDescriptor(message_length, 0);
+
+ if(pxBufferDescriptor != NULL) {
+ if( SMSC9220_ERROR_NONE != smsc9220_get_received_packet(Ð_DEV,
+ (char *)pxBufferDescriptor->pucEthernetBuffer,
+ message_length)) {
+ /* Packet size mismatch, try again at next interrupt */
+ continue;
+ }
+
+ pxBufferDescriptor->xDataLength = message_length;
+
+ if(eConsiderFrameForProcessing(
+ pxBufferDescriptor->pucEthernetBuffer) != eProcessBuffer) {
+ vReleaseNetworkBufferAndDescriptor(pxBufferDescriptor);
+ continue;
+ }
+
+ xRxEvent.eEventType = eNetworkRxEvent;
+
+ xRxEvent.pvData = (void *) pxBufferDescriptor;
+
+ /* Send the data to the TCP/IP stack. */
+ if( xSendEventStructToIPTask(&xRxEvent, 0) == pdFALSE )
+ {
+ /* Buffer send failed */
+ vReleaseNetworkBufferAndDescriptor(pxBufferDescriptor);
+ iptraceETHERNET_RX_EVENT_LOST();
+ }
+ else
+ {
+ /* Send successful */
+ iptraceNETWORK_INTERFACE_RECEIVE();
+ }
+ }
+ else
+ {
+ /* Event was lost */
+ iptraceETHERNET_RX_EVENT_LOST();
+ }
+
+ }
+}
diff --git a/examples/vad_an552/ns_side/amazon-freertos/FreeRTOSConfig.h b/examples/vad_an552/ns_side/amazon-freertos/FreeRTOSConfig.h
new file mode 100644
index 0000000..27dd4fc
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/FreeRTOSConfig.h
@@ -0,0 +1,181 @@
+/*
+ * FreeRTOS Kernel V10.2.0
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+#ifndef FREERTOS_CONFIG_H
+#define FREERTOS_CONFIG_H
+
+#include "system_core_init.h"
+
+#define configENABLE_FPU 0
+#define configENABLE_MPU 0
+#define configENABLE_MVE 1
+#define configENABLE_TRUSTZONE 0
+#define configRUN_FREERTOS_SECURE_ONLY 0
+
+#include "print_log.h"
+#define configPRINT_STRING( X ) vLoggingPrint X
+
+#define configUSE_PREEMPTION 1
+#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
+#define configUSE_TICKLESS_IDLE 0
+#define configCPU_CLOCK_HZ ( ( unsigned long ) SystemCoreClock )
+#define configSYSTICK_CLOCK_HZ ( ( unsigned long ) SystemCoreClock )
+#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
+#define configMAX_PRIORITIES 5
+#define configMINIMAL_STACK_SIZE 1024
+#define configMAX_TASK_NAME_LEN 16
+#define configUSE_16_BIT_TICKS 0
+#define configIDLE_SHOULD_YIELD 1
+#define configUSE_TASK_NOTIFICATIONS 1
+#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
+#define configUSE_MUTEXES 1
+#define configUSE_RECURSIVE_MUTEXES 1
+#define configUSE_COUNTING_SEMAPHORES 1
+#define configQUEUE_REGISTRY_SIZE 10
+#define configUSE_QUEUE_SETS 0
+#define configUSE_TIME_SLICING 0
+#define configUSE_NEWLIB_REENTRANT 0
+#define configENABLE_BACKWARD_COMPATIBILITY 0
+#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
+#define configSTACK_DEPTH_TYPE uint32_t
+#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
+
+/* Memory allocation related definitions. */
+#define configSUPPORT_STATIC_ALLOCATION 1
+#define configSUPPORT_DYNAMIC_ALLOCATION 1
+#define configTOTAL_HEAP_SIZE 0x60000
+#define configAPPLICATION_ALLOCATED_HEAP 0
+
+/* Hook function related definitions. */
+#define configUSE_IDLE_HOOK 0
+#define configUSE_TICK_HOOK 0
+#define configCHECK_FOR_STACK_OVERFLOW 0
+#define configUSE_MALLOC_FAILED_HOOK 0
+#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
+
+/* Run time and task stats gathering related definitions. */
+#define configGENERATE_RUN_TIME_STATS 0
+#define configUSE_TRACE_FACILITY 0
+#define configUSE_STATS_FORMATTING_FUNCTIONS 0
+
+/* Co-routine related definitions. */
+#define configUSE_CO_ROUTINES 0
+#define configMAX_CO_ROUTINE_PRIORITIES 1
+
+/* Software timer related definitions. */
+#define configUSE_TIMERS 1
+#define configTIMER_TASK_PRIORITY 3
+#define configTIMER_QUEUE_LENGTH 10
+#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
+
+/* FreeRTOS MPU specific definitions. */
+#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0
+#define configTOTAL_MPU_REGIONS 16
+#define configENFORCE_SYSTEM_CALLS_FROM_KERNEL_ONLY 1
+
+/* Optional functions - most linkers will remove unused functions anyway. */
+#define INCLUDE_vTaskPrioritySet 1
+#define INCLUDE_uxTaskPriorityGet 1
+#define INCLUDE_vTaskDelete 1
+#define INCLUDE_vTaskSuspend 1
+#define INCLUDE_xResumeFromISR 1
+#define INCLUDE_vTaskDelayUntil 1
+#define INCLUDE_vTaskDelay 1
+#define INCLUDE_xTaskGetSchedulerState 1
+#define INCLUDE_xTaskGetCurrentTaskHandle 1
+#define INCLUDE_uxTaskGetStackHighWaterMark 0
+#define INCLUDE_xTaskGetIdleTaskHandle 0
+#define INCLUDE_eTaskGetState 0
+#define INCLUDE_xEventGroupSetBitFromISR 1
+#define INCLUDE_xTimerPendFunctionCall 0
+#define INCLUDE_xTaskAbortDelay 0
+#define INCLUDE_xTaskGetHandle 1
+#define INCLUDE_xTaskResumeFromISR 1
+
+/* Cortex-M specific definitions. */
+#ifdef __NVIC_PRIO_BITS
+ /* __NVIC_PRIO_BITS will be specified when CMSIS is being used. */
+ #define configPRIO_BITS __NVIC_PRIO_BITS
+#else
+ #define configPRIO_BITS 3 /* 8 priority levels. */
+#endif
+
+/* The lowest interrupt priority that can be used in a call to a "set priority"
+function. */
+#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
+
+/* The highest interrupt priority that can be used by any interrupt service
+routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
+INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
+PRIORITY THAN THIS! (higher priorities are lower numeric values. */
+#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 2
+
+/* Interrupt priorities used by the kernel port layer itself. These are generic
+to all Cortex-M ports, and do not rely on any particular library functions. */
+#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
+See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
+#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+
+#define configMAC_INTERRUPT_PRIORITY 7
+
+/* MAC is read from HW */
+#define configMAC_ADDR0 0
+#define configMAC_ADDR1 0
+#define configMAC_ADDR2 0
+#define configMAC_ADDR3 0
+#define configMAC_ADDR4 0
+#define configMAC_ADDR5 0
+
+/* Default IP address configuration. Used if ipconfigUSE_DHCP is set to 0, or
+ * ipconfigUSE_DHCP is set to 1 but a DNS server cannot be contacted. */
+#define configIP_ADDR0 0
+#define configIP_ADDR1 0
+#define configIP_ADDR2 0
+#define configIP_ADDR3 0
+
+/* Default gateway IP address configuration. Used if ipconfigUSE_DHCP is set to
+ * 0, or ipconfigUSE_DHCP is set to 1 but a DNS server cannot be contacted. */
+#define configGATEWAY_ADDR0 0
+#define configGATEWAY_ADDR1 0
+#define configGATEWAY_ADDR2 0
+#define configGATEWAY_ADDR3 0
+
+/* Default DNS server configuration. OpenDNS addresses are 208.67.222.222 and
+ * 208.67.220.220. Used in ipconfigUSE_DHCP is set to 0, or ipconfigUSE_DHCP is
+ * set to 1 but a DNS server cannot be contacted.*/
+#define configDNS_SERVER_ADDR0 208
+#define configDNS_SERVER_ADDR1 67
+#define configDNS_SERVER_ADDR2 222
+#define configDNS_SERVER_ADDR3 222
+
+/* Default netmask configuration. Used if ipconfigUSE_DHCP is set to 0, or
+ * ipconfigUSE_DHCP is set to 1 but a DNS server cannot be contacted. */
+#define configNET_MASK0 0
+#define configNET_MASK1 0
+#define configNET_MASK2 0
+#define configNET_MASK3 0
+
+#endif /* FREERTOS_CONFIG_H */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/FreeRTOSIPConfig.h b/examples/vad_an552/ns_side/amazon-freertos/FreeRTOSIPConfig.h
new file mode 100644
index 0000000..4339652
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/FreeRTOSIPConfig.h
@@ -0,0 +1,235 @@
+/*
+ * FreeRTOS Kernel V10.2.0
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+
+/*****************************************************************************
+*
+* See the following URL for configuration information.
+* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
+*
+*****************************************************************************/
+
+#ifndef FREERTOS_IP_CONFIG_H
+#define FREERTOS_IP_CONFIG_H
+
+/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
+ * network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
+ * is not set to 1 then the network event hook will never be called. See:
+ * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml.
+ */
+#define ipconfigUSE_NETWORK_EVENT_HOOK 1
+
+/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
+ * on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
+#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
+
+/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
+ * then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
+ * stack repeating the checksum calculations. */
+#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
+
+/* Several API's will block until the result is known, or the action has been
+ * performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
+ * set per socket, using setsockopt(). If not set, the times below will be
+ * used as defaults. */
+#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 10000 )
+#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 10000 )
+
+/* Include support for DNS caching. For TCP, having a small DNS cache is very
+ * useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
+ * and also DNS may use small timeouts. If a DNS reply comes in after the DNS
+ * socket has been destroyed, the result will be stored into the cache. The next
+ * call to FreeRTOS_gethostbyname() will return immediately, without even creating
+ * a socket. */
+#define ipconfigUSE_DNS_CACHE ( 1 )
+#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
+
+/* The IP stack executes it its own task (although any application task can make
+ * use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
+ * sets the priority of the task that executes the IP stack. The priority is a
+ * standard FreeRTOS task priority so can take any value from 0 (the lowest
+ * priority) to (configMAX_PRIORITIES - 1) (the highest priority).
+ * configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
+ * FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
+ * the priority assigned to the task executing the IP stack relative to the
+ * priority assigned to tasks that use the IP stack. */
+#define ipconfigIP_TASK_PRIORITY configMAX_PRIORITIES-1
+
+/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
+ * task. This setting is less important when the FreeRTOS Win32 simulator is used
+ * as the Win32 simulator only stores a fixed amount of information on the task
+ * stack. FreeRTOS includes optional stack overflow detection, see:
+ * http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
+#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 10 )
+
+/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
+ * address, netmask, DNS server address and gateway address from a DHCP server. If
+ * ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
+ * stack will revert to using the static IP address even when ipconfigUSE_DHCP is
+ * set to 1 if a valid configuration cannot be obtained from a DHCP server for any
+ * reason. The static configuration used is that passed into the stack by the
+ * FreeRTOS_IPInit() function call. */
+#define ipconfigUSE_DHCP 1
+#define ipconfigDHCP_REGISTER_HOSTNAME 0
+#define ipconfigDHCP_USES_UNICAST 1
+
+/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
+ * provide an implementation of the DHCP callback function,
+ * xApplicationDHCPUserHook(). */
+#define ipconfigUSE_DHCP_HOOK 0
+
+/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
+ * stack can only send a UDP message to a remove IP address if it knowns the MAC
+ * address associated with the IP address, or the MAC address of the router used to
+ * contact the remote IP address. When a UDP message is received from a remote IP
+ * address the MAC address and IP address are added to the ARP cache. When a UDP
+ * message is sent to a remote IP address that does not already appear in the ARP
+ * cache then the UDP message is replaced by a ARP message that solicits the
+ * required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
+ * number of entries that can exist in the ARP table at any one time. */
+#define ipconfigARP_CACHE_ENTRIES 6
+
+/* ARP requests that do not result in an ARP response will be re-transmitted a
+ * maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
+ * aborted. */
+#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
+
+/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
+ * table being created or refreshed and the entry being removed because it is stale.
+ * New ARP requests are sent for ARP cache entries that are nearing their maximum
+ * age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
+ * equal to 1500 seconds (or 25 minutes). */
+#define ipconfigMAX_ARP_AGE 150
+
+/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
+ * routines, which are relatively large. To save code space the full
+ * FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
+ * alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
+ * takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
+ * FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
+ * (for example, 192, 168, 0, 1) as its parameters. If
+ * ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
+ * FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
+ * not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
+#define ipconfigINCLUDE_FULL_INET_ADDR 1
+
+/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
+ * are available to the IP stack. The total number of network buffers is limited
+ * to ensure the total amount of RAM that can be consumed by the IP stack is capped
+ * to a pre-determinable value. */
+#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
+
+/* A FreeRTOS queue is used to send events from application tasks to the IP
+ * stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
+ * be queued for processing at any one time. The event queue must be a minimum of
+ * 5 greater than the total number of network buffers. */
+#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
+
+/* The address of a socket is the combination of its IP address and its port
+ * number. FreeRTOS_bind() is used to manually allocate a port number to a socket
+ * (to 'bind' the socket to a port), but manual binding is not normally necessary
+ * for client sockets (those sockets that initiate outgoing connections rather than
+ * wait for incoming connections on a known port number). If
+ * ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
+ * FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
+ * stack automatically binding the socket to a port number from the range
+ * socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
+ * ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
+ * on a socket that has not yet been bound will result in the send operation being
+ * aborted. */
+#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
+
+/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
+#define ipconfigUDP_TIME_TO_LIVE 128
+/* Also defined in FreeRTOSIPConfigDefaults.h. */
+#define ipconfigTCP_TIME_TO_LIVE 128
+
+/* USE_TCP: Use TCP and all its features. */
+#define ipconfigUSE_TCP ( 1 )
+
+/* USE_WIN: Let TCP use windowing mechanism. */
+#define ipconfigUSE_TCP_WIN ( 1 )
+
+/* The MTU is the maximum number of bytes the payload of a network frame can
+ * contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
+ * lower value can save RAM, depending on the buffer management scheme used. If
+ * ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
+ * be divisible by 8. */
+#define ipconfigNETWORK_MTU 1500U
+
+/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
+ * through the FreeRTOS_gethostbyname() API function. */
+#define ipconfigUSE_DNS 1
+
+/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
+ * generate replies to incoming ICMP echo (ping) requests. */
+#define ipconfigREPLY_TO_INCOMING_PINGS 1
+
+/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
+ * FreeRTOS_SendPingRequest() API function is available. */
+#define ipconfigSUPPORT_OUTGOING_PINGS 0
+
+/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
+ * (and associated) API function is available. */
+#define ipconfigSUPPORT_SELECT_FUNCTION 0
+
+/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
+ * that are not in Ethernet II format will be dropped. This option is included for
+ * potential future IP stack developments. */
+#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
+
+/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
+ * responsibility of the Ethernet interface to filter out packets that are of no
+ * interest. If the Ethernet interface does not implement this functionality, then
+ * set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
+ * perform the filtering instead (it is much less efficient for the stack to do it
+ * because the packet will already have been passed into the stack). If the
+ * Ethernet driver does all the necessary filtering in hardware then software
+ * filtering can be removed by using a value other than 1 or 0. */
+#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
+
+/* Advanced only: in order to access 32-bit fields in the IP packets with
+ * 32-bit memory instructions, all packets will be stored 32-bit-aligned,
+ * plus 16-bits. This has to do with the contents of the IP-packets: all
+ * 32-bit fields are 32-bit-aligned, plus 16-bit. */
+#define ipconfigPACKET_FILLER_SIZE 2
+
+/* Define the size of the pool of TCP window descriptors. On the average, each
+ * TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
+ * outstanding packets (for Rx and Tx). When using up to 10 TP sockets
+ * simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
+#define ipconfigTCP_WIN_SEG_COUNT 240
+
+/* Include support for TCP keep-alive messages. */
+#define ipconfigTCP_KEEP_ALIVE ( 1 )
+#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
+
+/* The socket semaphore is used to unblock the MQTT task. */
+#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 0 )
+
+#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
+#define ipconfigUSE_CALLBACKS ( 0 )
+
+#endif /* FREERTOS_IP_CONFIG_H */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/LICENSE b/examples/vad_an552/ns_side/amazon-freertos/LICENSE
new file mode 100644
index 0000000..48f8587
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/LICENSE
@@ -0,0 +1,27 @@
+The files of this directory are orginally copied from amazon-freertos:
+https://github.com/aws/amazon-freertos/tree/202107.00
+
+Below is the copy of the amazon-freertos license file.
+
+
+MIT License
+
+Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential.h b/examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential.h
new file mode 100644
index 0000000..c3bda36
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential.h
@@ -0,0 +1,81 @@
+/*
+ * FreeRTOS V202012.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+#ifndef __AWS_CLIENTCREDENTIAL__H__
+#define __AWS_CLIENTCREDENTIAL__H__
+
+/*
+ * @brief MQTT Broker endpoint.
+ *
+ * @todo Set this to the fully-qualified DNS name of your MQTT broker.
+ */
+#define clientcredentialMQTT_BROKER_ENDPOINT ""
+
+/*
+ * @brief Host name.
+ *
+ * @todo Set this to the unique name of your IoT Thing.
+ * Please note that for convenience of demonstration only we
+ * are using a #define here. In production scenarios the thing
+ * name can be something unique to the device that can be read
+ * by software, such as a production serial number, rather
+ * than a hard coded constant.
+ */
+#define clientcredentialIOT_THING_NAME ""
+
+/*
+ * @brief Port number the MQTT broker is using.
+ */
+#define clientcredentialMQTT_BROKER_PORT 8883
+
+/*
+ * @brief Port number the Green Grass Discovery use for JSON retrieval from cloud is using.
+ */
+#define clientcredentialGREENGRASS_DISCOVERY_PORT 8443
+
+/*
+ * @brief Wi-Fi network to join.
+ *
+ * @todo If you are using Wi-Fi, set this to your network name.
+ */
+#define clientcredentialWIFI_SSID ""
+
+/*
+ * @brief Password needed to join Wi-Fi network.
+ * @todo If you are using WPA, set this to your network password.
+ */
+#define clientcredentialWIFI_PASSWORD ""
+
+/*
+ * @brief Wi-Fi network security type.
+ *
+ * @see WIFISecurity_t.
+ *
+ * @note Possible values are eWiFiSecurityOpen, eWiFiSecurityWEP, eWiFiSecurityWPA,
+ * eWiFiSecurityWPA2 (depending on the support of your device Wi-Fi radio).
+ */
+#define clientcredentialWIFI_SECURITY eWiFiSecurityWPA2
+
+#endif /* ifndef __AWS_CLIENTCREDENTIAL__H__ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential_keys.h b/examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential_keys.h
new file mode 100644
index 0000000..ac861f2
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential_keys.h
@@ -0,0 +1,93 @@
+/*
+ * FreeRTOS V202012.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+/*
+ ****************************************************************************
+ * NOTE!
+ * This file is for ease of demonstration only. Secret information should not
+ * be pasted into the header file in production devices. Do not paste
+ * production secrets here! Production devices should store secrets such as
+ * private keys securely, such as within a secure element. See our examples that
+ * demonstrate how to use the PKCS #11 API for secure keys access.
+ ****************************************************************************
+ */
+
+#ifndef AWS_CLIENT_CREDENTIAL_KEYS_H
+#define AWS_CLIENT_CREDENTIAL_KEYS_H
+
+/*
+ * @brief PEM-encoded client certificate.
+ *
+ * @todo If you are running one of the FreeRTOS demo projects, set this
+ * to the certificate that will be used for TLS client authentication.
+ *
+ * @note Must include the PEM header and footer:
+ * "-----BEGIN CERTIFICATE-----\n"\
+ * "...base64 data...\n"\
+ * "-----END CERTIFICATE-----\n"
+ */
+#define keyCLIENT_CERTIFICATE_PEM NULL
+
+/*
+ * @brief PEM-encoded issuer certificate for AWS IoT Just In Time Registration (JITR).
+ *
+ * @todo If you are using AWS IoT Just in Time Registration (JITR), set this to
+ * the issuer (Certificate Authority) certificate of the client certificate above.
+ *
+ * @note This setting is required by JITR because the issuer is used by the AWS
+ * IoT gateway for routing the device's initial request. (The device client
+ * certificate must always be sent as well.) For more information about JITR, see:
+ * https://docs.aws.amazon.com/iot/latest/developerguide/jit-provisioning.html,
+ * https://aws.amazon.com/blogs/iot/just-in-time-registration-of-device-certificates-on-aws-iot/.
+ *
+ * If you're not using JITR, set below to NULL.
+ *
+ * Must include the PEM header and footer:
+ * "-----BEGIN CERTIFICATE-----\n"\
+ * "...base64 data...\n"\
+ * "-----END CERTIFICATE-----\n"
+ */
+#define keyJITR_DEVICE_CERTIFICATE_AUTHORITY_PEM NULL
+
+/*
+ * @brief PEM-encoded client private key.
+ *
+ * @todo If you are running one of the FreeRTOS demo projects, set this
+ * to the private key that will be used for TLS client authentication.
+ * Please note pasting a key into the header file in this manner is for
+ * convenience of demonstration only and should not be done in production.
+ * Never past a production private key here!. Production devices should
+ * store keys securely, such as within a secure element. Additionally,
+ * we provide the corePKCS library that further enhances security by
+ * enabling keys to be used without exposing them to software.
+ *
+ * @note Must include the PEM header and footer:
+ * "-----BEGIN RSA PRIVATE KEY-----\n"\
+ * "...base64 data...\n"\
+ * "-----END RSA PRIVATE KEY-----\n"
+ */
+#define keyCLIENT_PRIVATE_KEY_PEM NULL
+
+#endif /* AWS_CLIENT_CREDENTIAL_KEYS_H */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/aws_demo_config.h b/examples/vad_an552/ns_side/amazon-freertos/aws_demo_config.h
new file mode 100644
index 0000000..c97a3cc
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/aws_demo_config.h
@@ -0,0 +1,37 @@
+/*
+ * FreeRTOS V1.4.7
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+#ifndef _AWS_DEMO_CONFIG_H_
+#define _AWS_DEMO_CONFIG_H_
+
+/* It is mandatory to enable the OTA demo, other demos are not supported */
+#define CONFIG_OTA_MQTT_UPDATE_DEMO_ENABLED
+
+/* Default configuration for all demos. Individual demos can override these below */
+#define democonfigDEMO_STACKSIZE (configMINIMAL_STACK_SIZE * 8)
+#define democonfigDEMO_PRIORITY (configMAX_PRIORITIES - 2)
+#define democonfigNETWORK_TYPES (AWSIOT_NETWORK_TYPE_ETH)
+
+#endif /* _AWS_DEMO_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/aws_iot_network_config.h b/examples/vad_an552/ns_side/amazon-freertos/aws_iot_network_config.h
new file mode 100644
index 0000000..2c616db
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/aws_iot_network_config.h
@@ -0,0 +1,57 @@
+/*
+* FreeRTOS
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+
+/**
+ * @file aws_iot_network_config.h
+ * @brief Configuration file which enables different network types.
+ */
+#ifndef AWS_IOT_NETWORK_CONFIG_H_
+#define AWS_IOT_NETWORK_CONFIG_H_
+
+/**
+ * @brief Configuration flag used to specify all supported network types by the board.
+ *
+ * The configuration is fixed per board and should never be changed.
+ * More than one network interfaces can be enabled by using 'OR' operation with flags for
+ * each network types supported. Flags for all supported network types can be found
+ * in "aws_iot_network.h"
+ */
+
+#define configSUPPORTED_NETWORKS ( AWSIOT_NETWORK_TYPE_ETH )
+
+/**
+ * @brief Configuration flag which is used to enable one or more network interfaces for a board.
+ *
+ * The configuration can be changed any time to keep one or more network enabled or disabled.
+ * More than one network interfaces can be enabled by using 'OR' operation with flags for
+ * each network types supported. Flags for all supported network types can be found
+ * in "aws_iot_network.h"
+ *
+ */
+
+#define configENABLED_NETWORKS ( AWSIOT_NETWORK_TYPE_ETH )
+
+#endif /* CONFIG_FILES_AWS_IOT_NETWORK_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/core_mqtt_config.h b/examples/vad_an552/ns_side/amazon-freertos/core_mqtt_config.h
new file mode 100644
index 0000000..bd8859a
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/core_mqtt_config.h
@@ -0,0 +1,70 @@
+/*
+ * coreMQTT v1.1.0
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file core_mqtt_config.h
+ * @brief This header sets configuration macros for the MQTT library.
+ */
+#ifndef CORE_MQTT_CONFIG_H_
+#define CORE_MQTT_CONFIG_H_
+
+/* Log configuration */
+#include "logging_levels.h"
+#ifndef LOG_LEVEL
+ #define LOG_LEVEL LOG_NONE
+#endif
+#include "logging_stack.h"
+
+/**
+ * @brief Timeout for which MQTT library keeps polling the transport interface,
+ * when no byte is received.
+ *
+ * The timeout is honoured only after the first byte is read and while
+ * remaining bytes are read from network interface. Keeping this timeout to a
+ * sufficiently large value so as to account for delay of receipt of a large
+ * block of message.
+ */
+#define MQTT_RECV_POLLING_TIMEOUT_MS ( 1000U )
+
+/**
+ * @brief The length of the queue used to hold commands for the agent.
+ */
+#define MQTT_AGENT_COMMAND_QUEUE_LENGTH ( 25 )
+
+/**
+ * @brief Dimensions the buffer used to serialise and deserialise MQTT packets.
+ * @note Specified in bytes. Must be large enough to hold the maximum
+ * anticipated MQTT payload.
+ */
+#define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 5000 )
+
+/**
+ * @brief Maximum time MQTT agent waits in the queue for any pending MQTT
+ * operations.
+ *
+ * The wait time is kept smallest possible to increase the responsiveness of
+ * MQTT agent while processing pending MQTT operations as well as receive
+ * packets from network.
+ */
+#define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1U )
+
+#endif /* ifndef CORE_MQTT_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/core_pkcs11_config.h b/examples/vad_an552/ns_side/amazon-freertos/core_pkcs11_config.h
new file mode 100644
index 0000000..3efddc2
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/core_pkcs11_config.h
@@ -0,0 +1,139 @@
+/*
+ * FreeRTOS V1.1.4
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+/**
+ * @file aws_pkcs11_config.h
+ * @brief PCKS#11 config options.
+ */
+
+
+#ifndef _AWS_PKCS11_CONFIG_H_
+#define _AWS_PKCS11_CONFIG_H_
+
+#include "FreeRTOS.h"
+
+/* Log configuration */
+#include "logging_levels.h"
+#ifndef LOG_LEVEL
+ #define LOG_LEVEL LOG_ERROR
+#endif
+#include "logging_stack.h"
+
+/**
+ * @brief Malloc API used by core_pkcs11.h
+ */
+#define PKCS11_MALLOC pvPortMalloc
+
+/**
+ * @brief Free API used by core_pkcs11.h
+ */
+#define PKCS11_FREE vPortFree
+
+/**
+ * @brief PKCS #11 default user PIN.
+ *
+ * The PKCS #11 standard specifies the presence of a user PIN. That feature is
+ * sensible for applications that have an interactive user interface and memory
+ * protections. However, since typical microcontroller applications lack one or
+ * both of those, the user PIN is assumed to be used herein for interoperability
+ * purposes only, and not as a security feature.
+ */
+#define configPKCS11_DEFAULT_USER_PIN "0000"
+
+/**
+ * @brief Maximum length (in characters) for a PKCS #11 CKA_LABEL
+ * attribute.
+ */
+#define pkcs11configMAX_LABEL_LENGTH 32
+
+/**
+ * @brief Maximum number of token objects that can be stored
+ * by the PKCS #11 module.
+ */
+#define pkcs11configMAX_NUM_OBJECTS 6
+
+/**
+* @brief Set to 1 if a PAL destroy object is implemented.
+*
+* If set to 0, no PAL destroy object is implemented, and this functionality
+* is implemented in the common PKCS #11 layer.
+*/
+#define pkcs11configPAL_DESTROY_SUPPORTED 0
+
+/**
+* @brief Set to 1 if PAL supports storage for JITP certificate,
+* code verify certificate, and trusted server root certificate.
+*
+* If set to 0, PAL does not support storage mechanism for these, and
+* they are accessed via headers compiled into the code.
+*/
+#define pkcs11configJITP_CODEVERIFY_ROOT_CERT_SUPPORTED 0
+
+/**
+ * @brief The PKCS #11 label for device private key.
+ *
+ * Private key for connection to AWS IoT endpoint. The corresponding
+ * public key should be registered with the AWS IoT endpoint.
+ */
+#define pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS "Device Priv TLS Key"
+
+/**
+ * @brief The PKCS #11 label for device public key.
+ *
+ * The public key corresponding to pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS.
+ */
+#define pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS "Device Pub TLS Key"
+
+/**
+ * @brief The PKCS #11 label for the device certificate.
+ *
+ * Device certificate corresponding to pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS.
+ */
+#define pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS "Device Cert"
+
+/**
+ * @brief The PKCS #11 label for the object to be used for code verification.
+ *
+ * Used by over-the-air update code to verify an incoming signed image.
+ */
+#define pkcs11configLABEL_CODE_VERIFICATION_KEY "Code Verify Key"
+
+/**
+ * @brief The PKCS #11 label for Just-In-Time-Provisioning.
+ *
+ * The certificate corresponding to the issuer of the device certificate
+ * (pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS) when using the JITR or
+ * JITP flow.
+ */
+#define pkcs11configLABEL_JITP_CERTIFICATE "JITP Cert"
+
+/**
+ * @brief The PKCS #11 label for the AWS Trusted Root Certificate.
+ *
+ * @see aws_default_root_certificates.h
+ */
+#define pkcs11configLABEL_ROOT_CERTIFICATE "Root Cert"
+
+#endif /* __AWS_PKCS11_CONFIG_H__ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/iot_config.h b/examples/vad_an552/ns_side/amazon-freertos/iot_config.h
new file mode 100644
index 0000000..49828eb
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/iot_config.h
@@ -0,0 +1,42 @@
+/*
+ * FreeRTOS V202012.00
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+/* This file contains configuration settings for the demos. */
+
+#ifndef IOT_CONFIG_H_
+#define IOT_CONFIG_H_
+
+#include "FreeRTOS.h"
+#include "platform/iot_platform_types_freertos.h"
+
+#define IotThreads_Free vPortFree
+
+/* Platform thread stack size and priority. */
+#define IOT_THREAD_DEFAULT_PRIORITY (tskIDLE_PRIORITY)
+#define IOT_THREAD_DEFAULT_STACK_SIZE (configMINIMAL_STACK_SIZE * 2)
+#define IOT_NETWORK_RECEIVE_TASK_PRIORITY (tskIDLE_PRIORITY + 1)
+#define IOT_NETWORK_RECEIVE_TASK_STACK_SIZE (configMINIMAL_STACK_SIZE * 2)
+
+#endif /* ifndef IOT_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/iot_mqtt_agent_config.h b/examples/vad_an552/ns_side/amazon-freertos/iot_mqtt_agent_config.h
new file mode 100644
index 0000000..8f110cc
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/iot_mqtt_agent_config.h
@@ -0,0 +1,39 @@
+/*
+ * Amazon FreeRTOS V1.1.4
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+/**
+ * @file iot_mqtt_agent_config.h
+ * @brief MQTT agent config options.
+ */
+
+#ifndef _AWS_MQTT_AGENT_CONFIG_H_
+#define _AWS_MQTT_AGENT_CONFIG_H_
+
+/**
+ * @brief The maximum time in ticks for which the MQTT task is permitted to block.
+ */
+#define mqttconfigMQTT_TASK_MAX_BLOCK_TICKS ( 1000 )
+
+#endif /* _AWS_MQTT_AGENT_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/iot_secure_sockets_config.h b/examples/vad_an552/ns_side/amazon-freertos/iot_secure_sockets_config.h
new file mode 100644
index 0000000..ac18495
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/iot_secure_sockets_config.h
@@ -0,0 +1,48 @@
+/*
+ * FreeRTOS V202107.00
+ * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
+
+/**
+ * @file iot_secure_sockets_config.h
+ * @brief Secure sockets configuration options.
+ */
+
+#ifndef _IOT_SECURE_SOCKETS_CONFIG_H_
+#define _IOT_SECURE_SOCKETS_CONFIG_H_
+
+/* Log configuration */
+#include "logging_levels.h"
+#ifndef LOG_LEVEL
+ #define LOG_LEVEL LOG_ERROR
+#endif
+#include "logging_stack.h"
+
+/**
+ * @brief Byte order of the target MCU.
+ *
+ * Valid values are pdLITTLE_ENDIAN and pdBIG_ENDIAN.
+ */
+#define socketsconfigBYTE_ORDER pdLITTLE_ENDIAN
+
+#endif /* _IOT_SECURE_SOCKETS_CONFIG_H_ */
\ No newline at end of file
diff --git a/examples/vad_an552/ns_side/amazon-freertos/logging_levels.h b/examples/vad_an552/ns_side/amazon-freertos/logging_levels.h
new file mode 100644
index 0000000..f3f4f64
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/logging_levels.h
@@ -0,0 +1,109 @@
+/*
+ * FreeRTOS Common V1.1.3
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file logging_levels.h
+ * @brief Defines the logging level macros.
+ */
+
+#ifndef LOGGING_LEVELS_H_
+#define LOGGING_LEVELS_H_
+
+/**
+ * @constantspage{logging,logging library}
+ *
+ * @section logging_constants_levels Log levels
+ * @brief Log levels for the libraries in this SDK.
+ *
+ * Each library should specify a log level by setting @ref LIBRARY_LOG_LEVEL.
+ * All log messages with a level at or below the specified level will be printed
+ * for that library.
+ *
+ * Currently, there are 4 log levels. In the order of lowest to highest, they are:
+ * - #LOG_NONE <br>
+ * @copybrief LOG_NONE
+ * - #LOG_ERROR <br>
+ * @copybrief LOG_ERROR
+ * - #LOG_WARN <br>
+ * @copybrief LOG_WARN
+ * - #LOG_INFO <br>
+ * @copybrief LOG_INFO
+ * - #LOG_DEBUG <br>
+ * @copybrief LOG_DEBUG
+ */
+
+/**
+ * @brief No log messages.
+ *
+ * When @ref LIBRARY_LOG_LEVEL is #LOG_NONE, logging is disabled and no
+ * logging messages are printed.
+ */
+#define LOG_NONE 0
+
+/**
+ * @brief Represents erroneous application state or event.
+ *
+ * These messages describe the situations when a library encounters an error from
+ * which it cannot recover.
+ *
+ * These messages are printed when @ref LIBRARY_LOG_LEVEL is defined as either
+ * of #LOG_ERROR, #LOG_WARN, #LOG_INFO or #LOG_DEBUG.
+ */
+#define LOG_ERROR 1
+
+/**
+ * @brief Message about an abnormal event.
+ *
+ * These messages describe the situations when a library encounters
+ * abnormal event that may be indicative of an error. Libraries continue
+ * execution after logging a warning.
+ *
+ * These messages are printed when @ref LIBRARY_LOG_LEVEL is defined as either
+ * of #LOG_WARN, #LOG_INFO or #LOG_DEBUG.
+ */
+#define LOG_WARN 2
+
+/**
+ * @brief A helpful, informational message.
+ *
+ * These messages describe normal execution of a library. They provide
+ * the progress of the program at a coarse-grained level.
+ *
+ * These messages are printed when @ref LIBRARY_LOG_LEVEL is defined as either
+ * of #LOG_INFO or #LOG_DEBUG.
+ */
+#define LOG_INFO 3
+
+/**
+ * @brief Detailed and excessive debug information.
+ *
+ * Debug log messages are used to provide the
+ * progress of the program at a fine-grained level. These are mostly used
+ * for debugging and may contain excessive information such as internal
+ * variables, buffers, or other specific information.
+ *
+ * These messages are only printed when @ref LIBRARY_LOG_LEVEL is defined as
+ * #LOG_DEBUG.
+ */
+#define LOG_DEBUG 4
+
+#endif /* ifndef LOGGING_LEVELS_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/logging_stack.h b/examples/vad_an552/ns_side/amazon-freertos/logging_stack.h
new file mode 100644
index 0000000..0c0fc6c
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/logging_stack.h
@@ -0,0 +1,60 @@
+/*
+ * FreeRTOS Common V1.1.3
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file logging_stack.h
+ * @brief Reference implementation of Logging stack as a header-only library.
+ */
+
+#ifndef LOGGING_STACK_H_
+#define LOGGING_STACK_H_
+
+#include "print_log.h"
+
+#if LOG_LEVEL == LOG_DEBUG
+ #define LogError( X ) vLoggingPrintf X
+ #define LogWarn( X ) vLoggingPrintf X
+ #define LogInfo( X ) vLoggingPrintf X
+ #define LogDebug( X ) vLoggingPrintf X
+#elif LOG_LEVEL == LOG_INFO
+ #define LogError( X ) vLoggingPrintf X
+ #define LogWarn( X ) vLoggingPrintf X
+ #define LogInfo( X ) vLoggingPrintf X
+ #define LogDebug( X )
+#elif LOG_LEVEL == LOG_WARN
+ #define LogError( X ) vLoggingPrintf X
+ #define LogWarn( X ) vLoggingPrintf X
+ #define LogInfo( X )
+ #define LogDebug( X )
+#elif LOG_LEVEL == LOG_ERROR
+ #define LogError( X ) vLoggingPrintf X
+ #define LogWarn( X )
+ #define LogInfo( X )
+ #define LogDebug( X )
+#else
+ #define LogError( X )
+ #define LogWarn( X )
+ #define LogInfo( X )
+ #define LogDebug( X )
+#endif
+
+#endif /* ifndef LOGGING_STACK_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/ota_config.h b/examples/vad_an552/ns_side/amazon-freertos/ota_config.h
new file mode 100644
index 0000000..5ee66c0
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/ota_config.h
@@ -0,0 +1,91 @@
+/*
+ * FreeRTOS V202104.00
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file ota_config.h
+ * @brief OTA user configurable settings.
+ */
+
+#ifndef OTA_CONFIG_H_
+#define OTA_CONFIG_H_
+
+/* Log configuration */
+#include "logging_levels.h"
+#ifndef LOG_LEVEL
+ #define LOG_LEVEL LOG_INFO
+#endif
+#include "logging_stack.h"
+
+/* errno is required for OTA sources */
+extern int errno;
+
+/**
+ * @brief Log base 2 of the size of the file data block message (excluding the
+ * header).
+ *
+ * <b>Possible values:</b> Any unsigned 32 integer. <br>
+ */
+#define otaconfigLOG2_FILE_BLOCK_SIZE 12UL
+
+/**
+ * @brief Size of the file data block message (excluding the header).
+ */
+#define otaconfigFILE_BLOCK_SIZE (1UL << otaconfigLOG2_FILE_BLOCK_SIZE)
+
+/**
+ * @brief The protocol selected for OTA control operations.
+ *
+ * @note This configurations parameter sets the default protocol for all the
+ * OTA control operations like requesting OTA job, updating the job status etc.
+ *
+ * @note Only MQTT is supported at this time for control operations.
+ *
+ * <b>Possible values:</b> OTA_CONTROL_OVER_MQTT <br>
+ */
+#define configENABLED_CONTROL_PROTOCOL (OTA_CONTROL_OVER_MQTT)
+
+/**
+ * @brief The protocol selected for OTA data operations.
+ *
+ * @note This configurations parameter sets the protocols selected for the data
+ * operations like requesting file blocks from the service.
+ *
+ * <b>Possible values:</b><br>
+ * Enable data over MQTT - ( OTA_DATA_OVER_MQTT ) <br>
+ * Enable data over HTTP - ( OTA_DATA_OVER_HTTP ) <br>
+ * Enable data over both MQTT & HTTP - ( OTA_DATA_OVER_MQTT | OTA_DATA_OVER_HTTP ) <br>
+ */
+#define configENABLED_DATA_PROTOCOLS (OTA_DATA_OVER_MQTT)
+
+/**
+ * @brief The preferred protocol selected for OTA data operations.
+ *
+ * @note Primary data protocol will be the protocol used for downloading file
+ * if more than one protocol is selected while creating OTA job.
+ *
+ * <b>Possible values:</b><br>
+ * Data over MQTT - ( OTA_DATA_OVER_MQTT ) <br>
+ * Data over HTTP - ( OTA_DATA_OVER_HTTP ) <br>
+ */
+#define configOTA_PRIMARY_DATA_PROTOCOL (OTA_DATA_OVER_MQTT)
+
+#endif /* OTA_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/ota_demo_config.h b/examples/vad_an552/ns_side/amazon-freertos/ota_demo_config.h
new file mode 100644
index 0000000..6dff1b5
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/ota_demo_config.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file ota_demo_config.h
+ * @brief Configuration options for the OTA related demos.
+ */
+
+#ifndef OTA_DEMO_CONFIG_H_
+#define OTA_DEMO_CONFIG_H_
+
+/* Required for build */
+
+#endif /* OTA_DEMO_CONFIG_H_ */
diff --git a/examples/vad_an552/ns_side/amazon-freertos/publish_aws.c b/examples/vad_an552/ns_side/amazon-freertos/publish_aws.c
new file mode 100644
index 0000000..bb56ede
--- /dev/null
+++ b/examples/vad_an552/ns_side/amazon-freertos/publish_aws.c
@@ -0,0 +1,617 @@
+/*
+ * FreeRTOS V202107.00
+ * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://www.FreeRTOS.org
+ * http://aws.amazon.com/freertos
+ *
+ */
+
+/* Reduced version of original file:
+ * https://github.com/aws/amazon-freertos/blob/202107.00/demos/coreMQTT/mqtt_demo_mutual_auth.c
+ *
+ * Insted of running the original demo only one message published to the
+ * predefined topic with backoff retries.
+ */
+
+/* Standard includes. */
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Log configuration */
+#include "logging_levels.h"
+#ifndef LOG_LEVEL
+ #define LOG_LEVEL LOG_ERROR
+#endif
+#include "logging_stack.h"
+
+/* Include common demo header. */
+#include "aws_demo.h"
+
+/* Kernel includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+
+/* Retry utilities include. */
+#include "backoff_algorithm.h"
+
+/* Include PKCS11 helpers header. */
+#include "pkcs11_helpers.h"
+
+/* Transport interface implementation include header for TLS. */
+#include "transport_secure_sockets.h"
+
+/* MQTT library includes. */
+#include "core_mqtt.h"
+
+/* Include header for connection configurations. */
+#include "aws_clientcredential.h"
+
+/* Include header for client credentials. */
+#include "aws_clientcredential_keys.h"
+
+/* Include header for root CA certificates. */
+#include "iot_default_root_certificates.h"
+
+#define democonfigNETWORK_BUFFER_SIZE ( 1500 )
+
+/**
+ * @brief The maximum number of retries for network operation with server.
+ */
+#define RETRY_MAX_ATTEMPTS ( 5U )
+
+/**
+ * @brief The maximum back-off delay (in milliseconds) for retrying failed operation
+ * with server.
+ */
+#define RETRY_MAX_BACKOFF_DELAY_MS ( 5000U )
+
+/**
+ * @brief The base back-off delay (in milliseconds) to use for network operation retry
+ * attempts.
+ */
+#define RETRY_BACKOFF_BASE_MS ( 500U )
+
+/**
+ * @brief Timeout for receiving CONNACK packet in milliseconds.
+ */
+#define mqttexampleCONNACK_RECV_TIMEOUT_MS ( 1000U )
+
+/**
+ * @brief The topic to subscribe and publish to in the example.
+ *
+ * The topic name starts with the client identifier to ensure that each demo
+ * interacts with a unique topic name.
+ */
+#define mqttexampleTOPIC clientcredentialIOT_THING_NAME "/vad_an552"
+
+/**
+ * @brief Timeout for MQTT_ProcessLoop in milliseconds.
+ */
+#define mqttexamplePROCESS_LOOP_TIMEOUT_MS ( 700U )
+
+/**
+ * @brief The maximum number of times to call MQTT_ProcessLoop() when polling
+ * for a specific packet from the broker.
+ */
+#define MQTT_PROCESS_LOOP_PACKET_WAIT_COUNT_MAX ( 30U )
+
+/**
+ * @brief Keep alive time reported to the broker while establishing
+ * an MQTT connection.
+ *
+ * It is the responsibility of the Client to ensure that the interval between
+ * Control Packets being sent does not exceed the this Keep Alive value. In the
+ * absence of sending any other Control Packets, the Client MUST send a
+ * PINGREQ Packet.
+ */
+#define mqttexampleKEEP_ALIVE_TIMEOUT_SECONDS ( 60U )
+
+/**
+ * @brief Transport timeout in milliseconds for transport send and receive.
+ */
+#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 500U )
+
+/**
+ * @brief Milliseconds per second.
+ */
+#define MILLISECONDS_PER_SECOND ( 1000U )
+
+/**
+ * @brief Milliseconds per FreeRTOS tick.
+ */
+#define MILLISECONDS_PER_TICK ( MILLISECONDS_PER_SECOND / configTICK_RATE_HZ )
+
+/*-----------------------------------------------------------*/
+
+/**
+ * @brief Each compilation unit that consumes the NetworkContext must define it.
+ * It should contain a single pointer to the type of your desired transport.
+ * When using multiple transports in the same compilation unit, define this pointer as void *.
+ *
+ * @note Transport stacks are defined in amazon-freertos/libraries/abstractions/transport/secure_sockets/transport_secure_sockets.h.
+ */
+struct NetworkContext
+{
+ SecureSocketsTransportParams_t * pParams;
+};
+
+/*-----------------------------------------------------------*/
+
+/**
+ * @brief Calculate and perform an exponential backoff with jitter delay for
+ * the next retry attempt of a failed network operation with the server.
+ *
+ * The function generates a random number, calculates the next backoff period
+ * with the generated random number, and performs the backoff delay operation if the
+ * number of retries have not exhausted.
+ *
+ * @note The PKCS11 module is used to generate the random number as it allows access
+ * to a True Random Number Generator (TRNG) if the vendor platform supports it.
+ * It is recommended to seed the random number generator with a device-specific entropy
+ * source so that probability of collisions from devices in connection retries is mitigated.
+ *
+ * @note The backoff period is calculated using the backoffAlgorithm library.
+ *
+ * @param[in, out] pxRetryAttempts The context to use for backoff period calculation
+ * with the backoffAlgorithm library.
+ *
+ * @return pdPASS if calculating the backoff period was successful; otherwise pdFAIL
+ * if there was failure in random number generation OR all retry attempts had exhausted.
+ */
+static BaseType_t prvBackoffForRetry( BackoffAlgorithmContext_t * pxRetryParams );
+
+/**
+ * @brief Connect to MQTT broker with reconnection retries.
+ *
+ * If connection fails, retry is attempted after a timeout.
+ * Timeout value will exponentially increase until maximum
+ * timeout value is reached or the number of attempts are exhausted.
+ *
+ * @param[out] pxNetworkContext The output parameter to return the created network context.
+ *
+ * @return pdFAIL on failure; pdPASS on successful TLS+TCP network connection.
+ */
+static BaseType_t prvConnectToServerWithBackoffRetries( NetworkContext_t * pNetworkContext );
+
+/**
+ * @brief Sends an MQTT Connect packet over the already connected TLS over TCP connection.
+ *
+ * @param[in, out] pxMQTTContext MQTT context pointer.
+ * @param[in] xNetworkContext Network context.
+ *
+ * @return pdFAIL on failure; pdPASS on successful MQTT connection.
+ */
+static BaseType_t prvCreateMQTTConnectionWithBroker( MQTTContext_t * pxMQTTContext,
+ NetworkContext_t * pxNetworkContext );
+
+/**
+ * @brief Publishes a message mqttexampleMESSAGE on mqttexampleTOPIC topic.
+ *
+ * @param[in] pxMQTTContext MQTT context pointer.
+ *
+ * @return pdFAIL on failure; pdPASS on successful PUBLISH operation.
+ */
+static BaseType_t prvMQTTPublishToTopic( MQTTContext_t * pxMQTTContext, const char *msg );
+
+/**
+ * @brief The timer query function provided to the MQTT context.
+ *
+ * @return Time in milliseconds.
+ */
+static uint32_t prvGetTimeMs( void );
+
+/**
+ * @brief The application callback function for getting the incoming publishes,
+ * incoming acks, and ping responses reported from the MQTT library.
+ *
+ * @param[in] pxMQTTContext MQTT context pointer.
+ * @param[in] pxPacketInfo Packet Info pointer for the incoming packet.
+ * @param[in] pxDeserializedInfo Deserialized information from the incoming packet.
+ */
+static void prvEventCallback( MQTTContext_t * pxMQTTContext,
+ MQTTPacketInfo_t * pxPacketInfo,
+ MQTTDeserializedInfo_t * pxDeserializedInfo );
+
+/**
+ * @brief Helper function to wait for a specific incoming packet from the
+ * broker.
+ *
+ * @param[in] pxMQTTContext MQTT context pointer.
+ * @param[in] usPacketType Packet type to wait for.
+ *
+ * @return The return status from call to #MQTT_ProcessLoop API.
+ */
+static MQTTStatus_t prvWaitForPacket( MQTTContext_t * pxMQTTContext,
+ uint16_t usPacketType );
+
+/*-----------------------------------------------------------*/
+
+/**
+ * @brief Static buffer used to hold MQTT messages being sent and received.
+ */
+static uint8_t ucSharedBuffer[ democonfigNETWORK_BUFFER_SIZE ];
+
+/**
+ * @brief Global entry time into the application to use as a reference timestamp
+ * in the #prvGetTimeMs function. #prvGetTimeMs will always return the difference
+ * between the current time and the global entry time. This will reduce the chances
+ * of overflow for the 32 bit unsigned integer used for holding the timestamp.
+ */
+static uint32_t ulGlobalEntryTimeMs;
+
+/**
+ * @brief Packet Identifier generated when Publish request was sent to the broker;
+ * it is used to match received Publish ACK to the transmitted Publish packet.
+ */
+static uint16_t usPublishPacketIdentifier;
+
+/**
+ * @brief MQTT packet type received from the MQTT broker.
+ *
+ * @note Only on receiving incoming PUBLISH, SUBACK, and UNSUBACK, this
+ * variable is updated. For MQTT packets PUBACK and PINGRESP, the variable is
+ * not updated since there is no need to specifically wait for it in this demo.
+ * A single variable suffices as this demo uses single task and requests one operation
+ * (of PUBLISH, SUBSCRIBE, UNSUBSCRIBE) at a time before expecting response from
+ * the broker. Hence it is not possible to receive multiple packets of type PUBLISH,
+ * SUBACK, and UNSUBACK in a single call of #prvWaitForPacket.
+ * For a multi task application, consider a different method to wait for the packet, if needed.
+ */
+static uint16_t usPacketTypeReceived = 0U;
+
+/** @brief Static buffer used to hold MQTT messages being sent and received. */
+static MQTTFixedBuffer_t xBuffer =
+{
+ ucSharedBuffer,
+ democonfigNETWORK_BUFFER_SIZE
+};
+
+/*-----------------------------------------------------------*/
+
+/*
+ * @brief Publishes a message to AWS cloud with backoff retries
+ */
+void publishToAWSTopic( const char *msg )
+{
+ NetworkContext_t xNetworkContext = { 0 };
+ MQTTContext_t xMQTTContext = { 0 };
+ TransportSocketStatus_t xNetworkStatus;
+ SecureSocketsTransportParams_t secureSocketsTransportParams = { 0 };
+ BaseType_t xStatus = pdFAIL;
+
+ xNetworkContext.pParams = &secureSocketsTransportParams;
+
+ xStatus = prvConnectToServerWithBackoffRetries( &xNetworkContext );
+
+ if( xStatus == pdPASS )
+ {
+ /* Sends an MQTT Connect packet over the already established TLS connection,
+ * and waits for connection acknowledgment (CONNACK) packet. */
+ LogInfo( ( "Creating an MQTT connection to %s.", clientcredentialMQTT_BROKER_ENDPOINT ) );
+ xStatus = prvCreateMQTTConnectionWithBroker( &xMQTTContext, &xNetworkContext );
+ if( xStatus == pdPASS )
+ {
+ LogInfo( ( "Publish to the MQTT topic %s.", mqttexampleTOPIC ) );
+ prvMQTTPublishToTopic( &xMQTTContext, msg );
+ MQTT_Disconnect( &xMQTTContext );
+ }
+
+ xNetworkStatus = SecureSocketsTransport_Disconnect( &xNetworkContext );
+
+ if( xNetworkStatus != TRANSPORT_SOCKET_STATUS_SUCCESS )
+ {
+ LogError( ( "SecureSocketsTransport_Disconnect() failed to close the network connection. "
+ "StatusCode=%d.", ( int ) xNetworkStatus ) );
+ }
+ }
+
+}
+
+/*-----------------------------------------------------------*/
+
+static BaseType_t prvBackoffForRetry( BackoffAlgorithmContext_t * pxRetryParams )
+{
+ BaseType_t xReturnStatus = pdFAIL;
+ uint16_t usNextRetryBackOff = 0U;
+ BackoffAlgorithmStatus_t xBackoffAlgStatus = BackoffAlgorithmSuccess;
+
+ /**
+ * To calculate the backoff period for the next retry attempt, we will
+ * generate a random number to provide to the backoffAlgorithm library.
+ *
+ * Note: The PKCS11 module is used to generate the random number as it allows access
+ * to a True Random Number Generator (TRNG) if the vendor platform supports it.
+ * It is recommended to use a random number generator seeded with a device-specific
+ * entropy source so that probability of collisions from devices in connection retries
+ * is mitigated.
+ */
+ uint32_t ulRandomNum = 0;
+
+ if( xPkcs11GenerateRandomNumber( ( uint8_t * ) &ulRandomNum,
+ sizeof( ulRandomNum ) ) == pdPASS )
+ {
+ /* Get back-off value (in milliseconds) for the next retry attempt. */
+ xBackoffAlgStatus = BackoffAlgorithm_GetNextBackoff( pxRetryParams, ulRandomNum, &usNextRetryBackOff );
+
+ if( xBackoffAlgStatus == BackoffAlgorithmRetriesExhausted )
+ {
+ LogError( ( "All retry attempts have exhausted. Operation will not be retried" ) );
+ }
+ else if( xBackoffAlgStatus == BackoffAlgorithmSuccess )
+ {
+ /* Perform the backoff delay. */
+ vTaskDelay( pdMS_TO_TICKS( usNextRetryBackOff ) );
+
+ xReturnStatus = pdPASS;
+
+ LogInfo( ( "Retry attempt %lu out of maximum retry attempts %lu.",
+ ( pxRetryParams->attemptsDone + 1 ),
+ pxRetryParams->maxRetryAttempts ) );
+ }
+ }
+ else
+ {
+ LogError( ( "Unable to retry operation with broker: Random number generation failed" ) );
+ }
+
+ return xReturnStatus;
+}
+
+/*-----------------------------------------------------------*/
+
+static BaseType_t prvConnectToServerWithBackoffRetries( NetworkContext_t * pxNetworkContext )
+{
+ ServerInfo_t xServerInfo = { 0 };
+
+ SocketsConfig_t xSocketsConfig = { 0 };
+ TransportSocketStatus_t xNetworkStatus = TRANSPORT_SOCKET_STATUS_SUCCESS;
+ BackoffAlgorithmContext_t xReconnectParams;
+ BaseType_t xBackoffStatus = pdFALSE;
+
+ /* Set the credentials for establishing a TLS connection. */
+ /* Initializer server information. */
+ xServerInfo.pHostName = clientcredentialMQTT_BROKER_ENDPOINT;
+ xServerInfo.hostNameLength = strlen( clientcredentialMQTT_BROKER_ENDPOINT );
+ xServerInfo.port = clientcredentialMQTT_BROKER_PORT;
+
+ /* Configure credentials for TLS mutual authenticated session. */
+ xSocketsConfig.enableTls = true;
+ xSocketsConfig.pAlpnProtos = NULL;
+ xSocketsConfig.maxFragmentLength = 0;
+ xSocketsConfig.disableSni = false;
+ xSocketsConfig.pRootCa = tlsATS1_ROOT_CERTIFICATE_PEM;
+ xSocketsConfig.rootCaSize = sizeof( tlsATS1_ROOT_CERTIFICATE_PEM );
+ xSocketsConfig.sendTimeoutMs = mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS;
+ xSocketsConfig.recvTimeoutMs = mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS;
+
+ /* Initialize reconnect attempts and interval. */
+ BackoffAlgorithm_InitializeParams( &xReconnectParams,
+ RETRY_BACKOFF_BASE_MS,
+ RETRY_MAX_BACKOFF_DELAY_MS,
+ RETRY_MAX_ATTEMPTS );
+
+ /* Attempt to connect to MQTT broker. If connection fails, retry after
+ * a timeout. Timeout value will exponentially increase till maximum
+ * attempts are reached.
+ */
+ do
+ {
+ /* Establish a TLS session with the MQTT broker. This example connects to
+ * the MQTT broker as specified in democonfigMQTT_BROKER_ENDPOINT and
+ * democonfigMQTT_BROKER_PORT at the top of this file. */
+ LogInfo( ( "Creating a TLS connection to %s:%u.",
+ clientcredentialMQTT_BROKER_ENDPOINT,
+ clientcredentialMQTT_BROKER_PORT ) );
+ /* Attempt to create a mutually authenticated TLS connection. */
+ xNetworkStatus = SecureSocketsTransport_Connect( pxNetworkContext,
+ &xServerInfo,
+ &xSocketsConfig );
+
+ if( xNetworkStatus != TRANSPORT_SOCKET_STATUS_SUCCESS )
+ {
+ LogWarn( ( "Connection to the broker failed. Attempting connection retry after backoff delay." ) );
+
+ /* As the connection attempt failed, we will retry the connection after an
+ * exponential backoff with jitter delay. */
+
+ /* Calculate the backoff period for the next retry attempt and perform the wait operation. */
+ xBackoffStatus = prvBackoffForRetry( &xReconnectParams );
+ }
+ } while( ( xNetworkStatus != TRANSPORT_SOCKET_STATUS_SUCCESS ) && ( xBackoffStatus == pdPASS ) );
+
+ return ( xNetworkStatus == TRANSPORT_SOCKET_STATUS_SUCCESS ) ? pdPASS : pdFAIL;
+}
+
+/*-----------------------------------------------------------*/
+
+static BaseType_t prvCreateMQTTConnectionWithBroker( MQTTContext_t * pxMQTTContext,
+ NetworkContext_t * pxNetworkContext )
+{
+ MQTTStatus_t xResult;
+ MQTTConnectInfo_t xConnectInfo;
+ bool xSessionPresent;
+ TransportInterface_t xTransport;
+ BaseType_t xStatus = pdFAIL;
+
+ /* Fill in Transport Interface send and receive function pointers. */
+ xTransport.pNetworkContext = pxNetworkContext;
+ xTransport.send = SecureSocketsTransport_Send;
+ xTransport.recv = SecureSocketsTransport_Recv;
+
+ /* Initialize MQTT library. */
+ xResult = MQTT_Init( pxMQTTContext, &xTransport, prvGetTimeMs, prvEventCallback, &xBuffer );
+ configASSERT( xResult == MQTTSuccess );
+
+ /* Some fields are not used in this demo so start with everything at 0. */
+ ( void ) memset( ( void * ) &xConnectInfo, 0x00, sizeof( xConnectInfo ) );
+
+ /* Start with a clean session i.e. direct the MQTT broker to discard any
+ * previous session data. Also, establishing a connection with clean session
+ * will ensure that the broker does not store any data when this client
+ * gets disconnected. */
+ xConnectInfo.cleanSession = true;
+
+ /* The client identifier is used to uniquely identify this MQTT client to
+ * the MQTT broker. In a production device the identifier can be something
+ * unique, such as a device serial number. */
+ xConnectInfo.pClientIdentifier = clientcredentialIOT_THING_NAME;
+ xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( clientcredentialIOT_THING_NAME );
+
+ /* Set MQTT keep-alive period. If the application does not send packets at an interval less than
+ * the keep-alive period, the MQTT library will send PINGREQ packets. */
+ xConnectInfo.keepAliveSeconds = mqttexampleKEEP_ALIVE_TIMEOUT_SECONDS;
+
+ /* Send MQTT CONNECT packet to broker. LWT is not used in this demo, so it
+ * is passed as NULL. */
+ xResult = MQTT_Connect( pxMQTTContext,
+ &xConnectInfo,
+ NULL,
+ mqttexampleCONNACK_RECV_TIMEOUT_MS,
+ &xSessionPresent );
+
+ if( xResult != MQTTSuccess )
+ {
+ LogError( ( "Failed to establish MQTT connection: Server=%s, MQTTStatus=%s",
+ clientcredentialMQTT_BROKER_ENDPOINT, MQTT_Status_strerror( xResult ) ) );
+ }
+ else
+ {
+ /* Successfully established and MQTT connection with the broker. */
+ LogInfo( ( "An MQTT connection is established with %s.", clientcredentialMQTT_BROKER_ENDPOINT ) );
+ xStatus = pdPASS;
+ }
+
+ return xStatus;
+}
+
+/*-----------------------------------------------------------*/
+
+static BaseType_t prvMQTTPublishToTopic( MQTTContext_t * pxMQTTContext, const char *msg )
+{
+ MQTTStatus_t xResult;
+ MQTTPublishInfo_t xMQTTPublishInfo;
+ BaseType_t xStatus = pdPASS;
+
+ /* Some fields are not used by this demo so start with everything at 0. */
+ ( void ) memset( ( void * ) &xMQTTPublishInfo, 0x00, sizeof( xMQTTPublishInfo ) );
+
+ /* This demo uses QoS1. */
+ xMQTTPublishInfo.qos = MQTTQoS1;
+ xMQTTPublishInfo.retain = false;
+ xMQTTPublishInfo.pTopicName = mqttexampleTOPIC;
+ xMQTTPublishInfo.topicNameLength = ( uint16_t ) strlen( mqttexampleTOPIC );
+ xMQTTPublishInfo.pPayload = msg;
+ xMQTTPublishInfo.payloadLength = strlen( msg );
+
+ /* Get a unique packet id. */
+ usPublishPacketIdentifier = MQTT_GetPacketId( pxMQTTContext );
+
+ /* Send PUBLISH packet. Packet ID is not used for a QoS1 publish. */
+ xResult = MQTT_Publish( pxMQTTContext, &xMQTTPublishInfo, usPublishPacketIdentifier );
+
+ if( xResult != MQTTSuccess )
+ {
+ xStatus = pdFAIL;
+ LogError( ( "Failed to send PUBLISH message to broker: Topic=%s, Error=%s",
+ mqttexampleTOPIC,
+ MQTT_Status_strerror( xResult ) ) );
+ }
+
+ prvWaitForPacket(pxMQTTContext, MQTT_PACKET_TYPE_SUBACK);
+
+ return xStatus;
+}
+
+/*-----------------------------------------------------------*/
+
+static void prvEventCallback( MQTTContext_t * pxMQTTContext,
+ MQTTPacketInfo_t * pxPacketInfo,
+ MQTTDeserializedInfo_t * pxDeserializedInfo )
+{
+ /* The MQTT context is not used.*/
+ ( void ) pxMQTTContext;
+
+ if( pxPacketInfo->type == MQTT_PACKET_TYPE_PUBACK )
+ {
+ LogInfo( ( "PUBACK received for packet Id %u.", pxDeserializedInfo->packetIdentifier ) );
+ /* Make sure ACK packet identifier matches with Request packet identifier. */
+ configASSERT( usPublishPacketIdentifier == pxDeserializedInfo->packetIdentifier );
+ usPacketTypeReceived = MQTT_PACKET_TYPE_SUBACK;
+ }
+ else
+ {
+ LogWarn( ( "Unexpected packet received with type:(%02X).", pxPacketInfo->type ) );
+ }
+}
+
+/*-----------------------------------------------------------*/
+
+static uint32_t prvGetTimeMs( void )
+{
+ TickType_t xTickCount = 0;
+ uint32_t ulTimeMs = 0UL;
+
+ /* Get the current tick count. */
+ xTickCount = xTaskGetTickCount();
+
+ /* Convert the ticks to milliseconds. */
+ ulTimeMs = ( uint32_t ) xTickCount * MILLISECONDS_PER_TICK;
+
+ /* Reduce ulGlobalEntryTimeMs from obtained time so as to always return the
+ * elapsed time in the application. */
+ ulTimeMs = ( uint32_t ) ( ulTimeMs - ulGlobalEntryTimeMs );
+
+ return ulTimeMs;
+}
+
+/*-----------------------------------------------------------*/
+
+static MQTTStatus_t prvWaitForPacket( MQTTContext_t * pxMQTTContext,
+ uint16_t usPacketType )
+{
+ uint8_t ucCount = 0U;
+ MQTTStatus_t xMQTTStatus = MQTTSuccess;
+
+ /* Reset the packet type received. */
+ usPacketTypeReceived = 0U;
+
+ while( ( usPacketTypeReceived != usPacketType ) &&
+ ( ucCount++ < MQTT_PROCESS_LOOP_PACKET_WAIT_COUNT_MAX ) &&
+ ( xMQTTStatus == MQTTSuccess ) )
+ {
+ /* Event callback will set #usPacketTypeReceived when receiving appropriate packet. This
+ * will wait for at most mqttexamplePROCESS_LOOP_TIMEOUT_MS. */
+ xMQTTStatus = MQTT_ProcessLoop( pxMQTTContext, mqttexamplePROCESS_LOOP_TIMEOUT_MS );
+ }
+
+ if( ( xMQTTStatus != MQTTSuccess ) || ( usPacketTypeReceived != usPacketType ) )
+ {
+ LogError( ( "MQTT_ProcessLoop failed to receive packet: Packet type=%02X, LoopDuration=%u, Status=%s",
+ usPacketType,
+ ( mqttexamplePROCESS_LOOP_TIMEOUT_MS * ucCount ),
+ MQTT_Status_strerror( xMQTTStatus ) ) );
+ }
+
+ return xMQTTStatus;
+}
+
+/*-----------------------------------------------------------*/
diff --git a/examples/vad_an552/ns_side/ext/amazon-freertos/CMakeLists.txt b/examples/vad_an552/ns_side/ext/amazon-freertos/CMakeLists.txt
new file mode 100644
index 0000000..f240d32
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/amazon-freertos/CMakeLists.txt
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+# Needed to specfy submodule list
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
+ cmake_policy(SET CMP0097 NEW)
+endif()
+
+if ("${AMAZON_FREERTOS_SRC_PATH}" STREQUAL "DOWNLOAD")
+ find_package(Git)
+
+ FetchContent_Declare(amazon_freertos
+ GIT_REPOSITORY https://github.com/aws/amazon-freertos.git
+ GIT_TAG 202107.00
+ GIT_SUBMODULES "libraries/freertos_plus/standard/freertos_plus_tcp
+ libraries/coreMQTT
+ libraries/coreMQTT-Agent
+ libraries/abstractions/backoff_algorithm
+ libraries/abstractions/pkcs11/corePKCS11
+ libraries/3rdparty/mbedtls"
+ )
+ FetchContent_GetProperties(amazon_freertos)
+ if (NOT amazon_freertos)
+ FetchContent_Populate(amazon_freertos)
+ set(AMAZON_FREERTOS_SRC_PATH ${amazon_freertos_SOURCE_DIR} CACHE PATH "Path to Amazon FreeRTOS (or DOWNLOAD to fetch automatically" FORCE)
+ endif ()
+endif ()
diff --git a/examples/vad_an552/ns_side/ext/freertos-kernel/CMakeLists.txt b/examples/vad_an552/ns_side/ext/freertos-kernel/CMakeLists.txt
new file mode 100644
index 0000000..340826d
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/freertos-kernel/CMakeLists.txt
@@ -0,0 +1,26 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+# Needed to specfy submodule list
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
+ cmake_policy(SET CMP0097 NEW)
+endif()
+
+if ("${FREERTOS_KERNEL_SRC_PATH}" STREQUAL "DOWNLOAD")
+ find_package(Git)
+ FetchContent_Declare(freertos_kernel
+ GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git
+ GIT_TAG 030e76681b981335ca4f25f0adce09612bf757a5
+ )
+ FetchContent_GetProperties(freertos_kernel)
+ if (NOT freertos_kernel)
+ FetchContent_Populate(freertos_kernel)
+ set(FREERTOS_KERNEL_SRC_PATH ${freertos_kernel_SOURCE_DIR} CACHE PATH "Path to FreeRTOS kernel (or DOWNLOAD to fetch automatically" FORCE)
+ endif ()
+endif ()
diff --git a/examples/vad_an552/ns_side/ext/freertos-ota-pal-psa/0001-Chunk-writing-added-for-otaPal_WriteBlock.patch b/examples/vad_an552/ns_side/ext/freertos-ota-pal-psa/0001-Chunk-writing-added-for-otaPal_WriteBlock.patch
new file mode 100644
index 0000000..cf285b3
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/freertos-ota-pal-psa/0001-Chunk-writing-added-for-otaPal_WriteBlock.patch
@@ -0,0 +1,73 @@
+From 5e22888b7cd7ef348f905627de7fece18bb94de7 Mon Sep 17 00:00:00 2001
+From: Mark Horvath <mark.horvath@arm.com>
+Date: Fri, 12 Nov 2021 12:22:00 +0100
+Subject: [PATCH 1/1] Chunk writing added for otaPal_WriteBlock
+
+If file block size is bigger then PSA_FWU_MAX_BLOCK_SIZE flash is
+written in chunks.
+
+Signed-off-by: Mark Horvath <mark.horvath@arm.com>
+---
+ ota_pal.c | 21 +++++++++++++++++++--
+ ota_pal.h | 2 +-
+ 2 files changed, 20 insertions(+), 3 deletions(-)
+
+diff --git a/ota_pal.c b/ota_pal.c
+index 40654a8..7659b62 100644
+--- a/ota_pal.c
++++ b/ota_pal.c
+@@ -295,19 +295,36 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const pFileContext )
+ */
+ int16_t otaPal_WriteBlock( OtaFileContext_t * const pFileContext,
+ uint32_t ulOffset,
+- uint8_t * const pcData,
++ const uint8_t * pcData,
+ uint32_t ulBlockSize )
+ {
++ uint32_t remaining_blocksize = ulBlockSize;
++
+ if( (pFileContext == NULL) || (pFileContext != pxSystemContext ) || ( xOTAImageID == TFM_FWU_INVALID_IMAGE_ID ) )
+ {
+ return -1;
+ }
+
+ /* Call the TF-M Firmware Update service to write image data. */
++ while(remaining_blocksize > PSA_FWU_MAX_BLOCK_SIZE)
++ {
++ if( psa_fwu_write( ( psa_image_id_t ) xOTAImageID,
++ ( size_t ) ulOffset,
++ ( const void * )pcData,
++ PSA_FWU_MAX_BLOCK_SIZE ) != PSA_SUCCESS )
++ {
++ return -1;
++ }
++
++ ulOffset += PSA_FWU_MAX_BLOCK_SIZE;
++ pcData += PSA_FWU_MAX_BLOCK_SIZE;
++ remaining_blocksize -= PSA_FWU_MAX_BLOCK_SIZE;
++ }
++
+ if( psa_fwu_write( ( psa_image_id_t ) xOTAImageID,
+ ( size_t ) ulOffset,
+ ( const void * )pcData,
+- ( size_t ) ulBlockSize ) != PSA_SUCCESS )
++ ( size_t ) remaining_blocksize ) != PSA_SUCCESS )
+ {
+ return -1;
+ }
+diff --git a/ota_pal.h b/ota_pal.h
+index c837b96..7a0fcf2 100644
+--- a/ota_pal.h
++++ b/ota_pal.h
+@@ -136,7 +136,7 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const pFileContext );
+ */
+ int16_t otaPal_WriteBlock( OtaFileContext_t * const pFileContext,
+ uint32_t ulOffset,
+- uint8_t * const pData,
++ const uint8_t * pData,
+ uint32_t ulBlockSize );
+
+ /**
+--
+2.25.1
+
diff --git a/examples/vad_an552/ns_side/ext/freertos-ota-pal-psa/CMakeLists.txt b/examples/vad_an552/ns_side/ext/freertos-ota-pal-psa/CMakeLists.txt
new file mode 100644
index 0000000..70c842c
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/freertos-ota-pal-psa/CMakeLists.txt
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+if ("${OTA_PAL_PSA_SRC_PATH}" STREQUAL "DOWNLOAD")
+ find_package(Git)
+ file(GLOB PATCH_FILES *.patch)
+
+ FetchContent_Declare(freertos_ota_pal_psa
+ GIT_REPOSITORY https://github.com/Linaro/freertos-ota-pal-psa.git
+ GIT_TAG 0b6db7d7cc0260fbb1e54a26ad6ff25cdcde3697
+ PATCH_COMMAND ${GIT_EXECUTABLE} apply ${PATCH_FILES}
+ )
+ FetchContent_GetProperties(freertos_ota_pal_psa)
+ if (NOT freertos_ota_pal_psa)
+ FetchContent_Populate(freertos_ota_pal_psa)
+ set(OTA_PAL_PSA_SRC_PATH ${freertos_ota_pal_psa_SOURCE_DIR} CACHE PATH "Path to freertos-ota-pal-psa (or DOWNLOAD to fetch automatically" FORCE)
+ endif ()
+endif ()
diff --git a/examples/vad_an552/ns_side/ext/freertos-pkcs11-psa/0001-Align-with-TF-M-1.4-release.patch b/examples/vad_an552/ns_side/ext/freertos-pkcs11-psa/0001-Align-with-TF-M-1.4-release.patch
new file mode 100644
index 0000000..1a0e4b9
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/freertos-pkcs11-psa/0001-Align-with-TF-M-1.4-release.patch
@@ -0,0 +1,123 @@
+From c18197c62a0fb0ca46e05b7709245d1652e160fd Mon Sep 17 00:00:00 2001
+From: Mark Horvath <mark.horvath@arm.com>
+Date: Thu, 28 Oct 2021 10:19:10 +0200
+Subject: [PATCH 1/1] Align with TF-M 1.4 release
+
+TF-M stepped mbedtls to 3.0.0 which requires some minor changes.
+
+Signed-off-by: Mark Horvath <mark.horvath@arm.com>
+---
+ iot_pkcs11_psa.c | 4 +--
+ iot_pkcs11_psa_object_management.c | 44 ++++++++++++++++++++----------
+ 2 files changed, 31 insertions(+), 17 deletions(-)
+
+diff --git a/iot_pkcs11_psa.c b/iot_pkcs11_psa.c
+index 7b4dafa..123714a 100644
+--- a/iot_pkcs11_psa.c
++++ b/iot_pkcs11_psa.c
+@@ -3502,7 +3502,7 @@ CK_DEFINE_FUNCTION( CK_RV, C_GenerateKeyPair )( CK_SESSION_HANDLE xSession,
+ if( xResult == CKR_OK )
+ {
+ uxAlgorithm = PSA_ALG_ECDSA( PSA_ALG_SHA_256 );
+- uxKeyType = PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP256R1 );
++ uxKeyType = PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 );
+ if( strcmp( pxPrivateLabel->pValue,
+ pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS ) == 0 )
+ {
+@@ -3539,7 +3539,7 @@ CK_DEFINE_FUNCTION( CK_RV, C_GenerateKeyPair )( CK_SESSION_HANDLE xSession,
+ }
+ if ( uxStatus == PSA_SUCCESS )
+ {
+- uxKeyType = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1);
++ uxKeyType = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_FAMILY_SECP_R1);
+ uxAlgorithm = PSA_ALG_ECDSA( PSA_ALG_SHA_256 );
+ if( strcmp( pxPublicLabel->pValue,
+ pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS ) == 0 )
+diff --git a/iot_pkcs11_psa_object_management.c b/iot_pkcs11_psa_object_management.c
+index 5f5ef79..64c8e83 100644
+--- a/iot_pkcs11_psa_object_management.c
++++ b/iot_pkcs11_psa_object_management.c
+@@ -38,6 +38,20 @@
+ extern int convert_pem_to_der( const unsigned char * pucInput, size_t xLen,
+ unsigned char * pucOutput, size_t * pxOlen );
+
++/*
++ * Defines the maximum export size of a key with given key_type and key_bits.
++ */
++
++#define PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits) \
++ (PSA_KEY_TYPE_IS_UNSTRUCTURED(key_type) ? PSA_BITS_TO_BYTES(key_bits) : \
++ (key_type) == PSA_KEY_TYPE_RSA_KEY_PAIR ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) : \
++ (key_type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \
++ (key_type) == PSA_KEY_TYPE_DSA_KEY_PAIR ? PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits) : \
++ (key_type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY ? PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \
++ PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) ? PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) : \
++ PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \
++ 0)
++
+ /*
+ * This is the context of the PKCS#11 PSA object. It is placed in a section.
+ * named "tasks_share". If MPU is enabled, tasks that call PKCS#11 APIs should
+@@ -53,36 +67,36 @@ P11KeyConfig_t P11KeyConfig __attribute__(( section( "tasks_share" ) ));
+ * @return PSA ECC group ID.
+ */
+
+-static psa_ecc_curve_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid )
++static psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid )
+ {
+ switch( grpid )
+ {
+ case MBEDTLS_ECP_DP_SECP192R1:
+- return( PSA_ECC_CURVE_SECP192R1 );
++ return( PSA_ECC_FAMILY_SECP_R1 );
+ case MBEDTLS_ECP_DP_SECP224R1:
+- return( PSA_ECC_CURVE_SECP224R1 );
++ return( PSA_ECC_FAMILY_SECP_R1 );
+ case MBEDTLS_ECP_DP_SECP256R1:
+- return( PSA_ECC_CURVE_SECP256R1 );
++ return( PSA_ECC_FAMILY_SECP_R1 );
+ case MBEDTLS_ECP_DP_SECP384R1:
+- return( PSA_ECC_CURVE_SECP384R1 );
++ return( PSA_ECC_FAMILY_SECP_R1 );
+ case MBEDTLS_ECP_DP_SECP521R1:
+- return( PSA_ECC_CURVE_SECP521R1 );
++ return( PSA_ECC_FAMILY_SECP_R1 );
+ case MBEDTLS_ECP_DP_BP256R1:
+- return( PSA_ECC_CURVE_BRAINPOOL_P256R1 );
++ return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 );
+ case MBEDTLS_ECP_DP_BP384R1:
+- return( PSA_ECC_CURVE_BRAINPOOL_P384R1 );
++ return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 );
+ case MBEDTLS_ECP_DP_BP512R1:
+- return( PSA_ECC_CURVE_BRAINPOOL_P512R1 );
++ return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 );
+ case MBEDTLS_ECP_DP_CURVE25519:
+- return( PSA_ECC_CURVE_CURVE25519 );
++ return( PSA_ECC_FAMILY_MONTGOMERY );
+ case MBEDTLS_ECP_DP_SECP192K1:
+- return( PSA_ECC_CURVE_SECP192K1 );
++ return( PSA_ECC_FAMILY_SECP_K1 );
+ case MBEDTLS_ECP_DP_SECP224K1:
+- return( PSA_ECC_CURVE_SECP224K1 );
++ return( PSA_ECC_FAMILY_SECP_K1 );
+ case MBEDTLS_ECP_DP_SECP256K1:
+- return( PSA_ECC_CURVE_SECP256K1 );
++ return( PSA_ECC_FAMILY_SECP_K1 );
+ case MBEDTLS_ECP_DP_CURVE448:
+- return( PSA_ECC_CURVE_CURVE448 );
++ return( PSA_ECC_FAMILY_MONTGOMERY );
+ default:
+ return( 0 );
+ }
+@@ -115,7 +129,7 @@ CK_OBJECT_HANDLE PKCS11PSASaveObject( CK_ATTRIBUTE_PTR pxClass,
+ CK_RV xBytesWritten = 0;
+ CK_RV xReturn;
+ psa_status_t uxStatus = PSA_SUCCESS;
+- psa_ecc_curve_t curve_id;
++ psa_ecc_family_t curve_id;
+ const mbedtls_ecp_keypair *ec;
+ unsigned char cPrivateKeyRaw[EC_PRIVATE_KEY_MAX_LENGTH];
+ size_t xPrivateKeyRawSize = 0;
+--
+2.25.1
+
diff --git a/examples/vad_an552/ns_side/ext/freertos-pkcs11-psa/CMakeLists.txt b/examples/vad_an552/ns_side/ext/freertos-pkcs11-psa/CMakeLists.txt
new file mode 100644
index 0000000..82f73b9
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/freertos-pkcs11-psa/CMakeLists.txt
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+if ("${PKCS11_PSA_SRC_PATH}" STREQUAL "DOWNLOAD")
+ find_package(Git)
+ file(GLOB PATCH_FILES *.patch)
+
+ FetchContent_Declare(freertos_pkcs11_psa
+ GIT_REPOSITORY https://github.com/Linaro/freertos-pkcs11-psa.git
+ GIT_TAG 80292d24f4978891b0fd35feeb5f1d6f6f0fff06
+ PATCH_COMMAND ${GIT_EXECUTABLE} apply ${PATCH_FILES}
+ )
+ FetchContent_GetProperties(freertos_pkcs11_psa)
+ if (NOT freertos_pkcs11_psa)
+ FetchContent_Populate(freertos_pkcs11_psa)
+ set(PKCS11_PSA_SRC_PATH ${freertos_pkcs11_psa_SOURCE_DIR} CACHE PATH "Path to freertos-pkcs11-psa (or DOWNLOAD to fetch automatically" FORCE)
+ endif ()
+endif ()
diff --git a/examples/vad_an552/ns_side/ext/ota-for-aws/0001-Remove-const-qualifier-from-appFirmwareVersion.patch b/examples/vad_an552/ns_side/ext/ota-for-aws/0001-Remove-const-qualifier-from-appFirmwareVersion.patch
new file mode 100644
index 0000000..de01a98
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/ota-for-aws/0001-Remove-const-qualifier-from-appFirmwareVersion.patch
@@ -0,0 +1,28 @@
+From 35470d82fcf3be2ef68b54c7a999bde69b8a6a03 Mon Sep 17 00:00:00 2001
+From: Mark Horvath <mark.horvath@arm.com>
+Date: Thu, 28 Oct 2021 18:25:23 +0200
+Subject: [PATCH 1/1] Remove const qualifier from appFirmwareVersion
+
+The PSA implementation of the OTA PAL fills the application version at
+runtime.
+
+Signed-off-by: Mark Horvath <mark.horvath@arm.com>
+---
+ source/include/ota_appversion32.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/source/include/ota_appversion32.h b/source/include/ota_appversion32.h
+index 4db4e77..3fa0fae 100644
+--- a/source/include/ota_appversion32.h
++++ b/source/include/ota_appversion32.h
+@@ -64,6 +64,6 @@ typedef struct
+ } u; /*!< @brief Version based on configuration in big endian or little endian. */
+ } AppVersion32_t;
+
+-extern const AppVersion32_t appFirmwareVersion; /*!< @brief Making the version number available globally through external linkage. */
++extern AppVersion32_t appFirmwareVersion; /*!< @brief Making the version number available globally through external linkage. */
+
+ #endif /* ifndef IOT_APPVERSION32_H */
+--
+2.25.1
+
diff --git a/examples/vad_an552/ns_side/ext/ota-for-aws/CMakeLists.txt b/examples/vad_an552/ns_side/ext/ota-for-aws/CMakeLists.txt
new file mode 100644
index 0000000..bcb588f
--- /dev/null
+++ b/examples/vad_an552/ns_side/ext/ota-for-aws/CMakeLists.txt
@@ -0,0 +1,29 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+# Needed to specfy submodule list
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
+ cmake_policy(SET CMP0097 NEW)
+endif()
+
+if ("${OTA_FOR_AWS_SRC_PATH}" STREQUAL "DOWNLOAD")
+ find_package(Git)
+ file(GLOB PATCH_FILES *.patch)
+
+ FetchContent_Declare(ota_for_aws
+ GIT_REPOSITORY https://github.com/aws/ota-for-aws-iot-embedded-sdk.git
+ GIT_TAG 666241d
+ PATCH_COMMAND ${GIT_EXECUTABLE} apply ${PATCH_FILES}
+ )
+ FetchContent_GetProperties(ota_for_aws)
+ if (NOT ota_for_aws)
+ FetchContent_Populate(ota_for_aws)
+ set(OTA_FOR_AWS_SRC_PATH ${ota_for_aws_SOURCE_DIR} CACHE PATH "OTA for AWS (or DOWNLOAD to fetch automatically" FORCE)
+ endif ()
+endif ()
diff --git a/examples/vad_an552/ns_side/main_ns.c b/examples/vad_an552/ns_side/main_ns.c
new file mode 100644
index 0000000..c77f530
--- /dev/null
+++ b/examples/vad_an552/ns_side/main_ns.c
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 2017-2022 Arm Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stdio.h"
+#include "string.h"
+#include "stdbool.h"
+#include "uart_stdout.h"
+#include "print_log.h"
+
+#include "FreeRTOS.h"
+#include "task.h"
+#include "FreeRTOS_IP.h"
+
+#include "psa/protected_storage.h"
+#include "psa/crypto.h"
+#include "psa/update.h"
+#include "psa/internal_trusted_storage.h"
+#include "vad_an552.h"
+
+#include "aws_dev_mode_key_provisioning.h"
+#include "ota_provision.h"
+
+#include "version/application_version.h"
+#include "aws_demo.h"
+#include "ota.h"
+
+#define FIRST_BOOT_ITS_UID (1U)
+#define BOOT_PATTERN (0x55)
+
+extern uint32_t tfm_ns_interface_init(void);
+extern void vApplicationIPInit(void);
+extern int mbedtls_platform_set_calloc_free(
+ void* (*calloc_func)(size_t, size_t),
+ void (*free_func)(void *));
+extern void publishToAWSTopic(const char *msg);
+
+static void* prvCalloc(size_t xNmemb, size_t xSize);
+static bool is_first_boot(void);
+static void write_boot_pattern(void);
+static void accept_primary_slot_image(void);
+
+/*
+ * Semihosting is a mechanism that enables code running on an ARM target
+ * to communicate and use the Input/Output facilities of a host computer
+ * that is running a debugger.
+ * There is an issue where if you use armclang at -O0 optimisation with
+ * no parameters specified in the main function, the initialisation code
+ * contains a breakpoint for semihosting by default. This will stop the
+ * code from running before main is reached.
+ * Semihosting can be disabled by defining __ARM_use_no_argv symbol
+ * (or using higher optimization level).
+ */
+#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
+__asm(" .global __ARM_use_no_argv\n");
+#endif
+
+/*
+ * With current clib settings there is no support for errno in case of Armclang
+ * but OTA sources require it.
+ */
+#if defined (__ARMCC_VERSION)
+int errno;
+#endif
+
+psa_key_handle_t xOTACodeVerifyKeyHandle = 0xAA;
+
+static void accept_primary_slot_image(void)
+{
+ psa_image_id_t running_image = \
+ (psa_image_id_t)FWU_CALCULATE_IMAGE_ID(FWU_IMAGE_ID_SLOT_ACTIVE,
+ FWU_IMAGE_TYPE_FULL,
+ 0);
+ vLoggingPrintf("Accepting image by setting image_ok flag to 0x1 in MCUBOOT trailer");
+ if (psa_fwu_accept(running_image) != PSA_SUCCESS) {
+ vLoggingPrintf("Accept failed");
+ }
+}
+
+static bool is_first_boot(void)
+{
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR;
+ const psa_storage_uid_t uid = FIRST_BOOT_ITS_UID;
+ uint8_t boot_pattern_in_its = 0;
+ size_t read_data_length = 0;
+
+ status = psa_its_get(uid, 0, 1, &boot_pattern_in_its,
+ &read_data_length);
+ if(status != PSA_SUCCESS) {
+ vLoggingPrintf("Could not read ITS to determine boot counter");
+ vLoggingPrintf("Assuming first boot");
+ return true;
+ }
+
+ if(boot_pattern_in_its == BOOT_PATTERN) {
+ vLoggingPrintf("Boot pattern in ITS matches, not first boot");
+ return false;
+ }
+ else {
+ vLoggingPrintf("Boot pattern in ITS doesn't match, first boot");
+ return true;
+ }
+}
+
+static void write_boot_pattern(void)
+{
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR;
+ const psa_storage_uid_t uid = FIRST_BOOT_ITS_UID;
+ const psa_storage_create_flags_t flags = PSA_STORAGE_FLAG_NONE;
+ uint8_t first_boot_pattern = BOOT_PATTERN;
+
+ /* Write the pattern to ITS */
+ status = psa_its_set(uid, 1, &first_boot_pattern, flags);
+ if(status == PSA_SUCCESS) {
+ vLoggingPrintf("Boot pattern has been written to the ITS");
+ }
+ else {
+ vLoggingPrintf("Couldn't write boot pattern to ITS");
+ }
+}
+
+static void mainTask(void *pvParameters)
+{
+ uint32_t vad_status;
+ uint32_t vad_freq;
+ OtaState_t ota_state;
+ TickType_t base_tick, curr_tick;
+ char message[256];
+
+#ifdef VAD_AN552_NO_CONNECTIVITY
+ while(1) {
+ vad_an552_start_vad();
+
+ do {
+ vad_an552_query_vad(&vad_status);
+ } while (vad_status != VAD_VOICE_RECORDED);
+
+ vad_an552_get_freq(&vad_freq);
+
+ vLoggingPrintf("Voice detected with most energy at %d Hz", vad_freq);
+ }
+#else
+ while(1) {
+ vLoggingPrintf("==== Start OTA task ====");
+ DEMO_RUNNER_RunDemos();
+
+ do {
+ vTaskDelay(pdMS_TO_TICKS(10));
+ ota_state = OTA_GetState();
+ }
+ while (ota_state == OtaAgentStateInit ||
+ ota_state == OtaAgentStateReady ||
+ ota_state == OtaAgentStateStopped ||
+ ota_state == OtaAgentStateRequestingJob);
+
+ vTaskDelay(pdMS_TO_TICKS(5000));
+
+ if (OtaAgentStateWaitingForJob == OTA_GetState()) {
+ vLoggingPrintf("==== Stop OTA task ====");
+
+ OTA_Shutdown(0, 1);
+ while (xTaskGetHandle("iot_thread") != NULL) {
+ vTaskDelay(pdMS_TO_TICKS(100));
+ }
+
+ base_tick = xTaskGetTickCount();
+
+ vLoggingPrintf("==== Start listening ====");
+ vad_an552_start_vad();
+
+ while(1) {
+ vad_an552_query_vad(&vad_status);
+ if (vad_status == VAD_VOICE_RECORDED) {
+ vad_an552_get_freq(&vad_freq);
+
+ vLoggingPrintf("Voice detected with most energy at %d Hz",
+ vad_freq);
+ vLoggingPrintf("==== Send message to cloud ====");
+ sprintf(message, "Voice detected with most energy at %d Hz",
+ vad_freq);
+ publishToAWSTopic(message);
+
+ /* Message sending takes some time so timeout checked
+ * before restarting the mic algorithm. */
+ curr_tick = xTaskGetTickCount();
+ if ((curr_tick - base_tick) > pdMS_TO_TICKS(60000)) {
+ vad_an552_stop_vad();
+ break;
+ }
+
+ vLoggingPrintf("==== Start listening ====");
+ vad_an552_start_vad();
+ }
+
+ curr_tick = xTaskGetTickCount();
+ if ((curr_tick - base_tick) > pdMS_TO_TICKS(60000)) {
+ vLoggingPrintf("==== Stop listening ====");
+ vad_an552_stop_vad();
+ break;
+ }
+ }
+ } else {
+ /* OTA started, nothing to do */
+ while (1) {
+ vTaskDelay(pdMS_TO_TICKS(10000));
+ }
+ }
+ }
+#endif
+}
+
+int main()
+{
+ stdio_init();
+ vUARTLockInit();
+ tfm_ns_interface_init();
+
+ GetImageVersionPSA(FWU_IMAGE_TYPE_FULL);
+ vLoggingPrintf("Application firmware version: %d.%d.%d",
+ appFirmwareVersion.u.x.major,
+ appFirmwareVersion.u.x.minor,
+ appFirmwareVersion.u.x.build);
+
+#ifdef VAD_AN552_NO_CONNECTIVITY
+ xTaskCreate(mainTask, "main task", configMINIMAL_STACK_SIZE*2, NULL,
+ configMAX_PRIORITIES-2, NULL);
+#else
+ mbedtls_platform_set_calloc_free(prvCalloc, vPortFree);
+
+ if(is_first_boot()) {
+ accept_primary_slot_image();
+ vDevModeKeyProvisioning();
+ ota_privision_code_signing_key(&xOTACodeVerifyKeyHandle);
+ write_boot_pattern();
+ }
+
+ /* Initialise the RTOS's TCP/IP stack. The tasks that use the network
+ are created in the vApplicationIPNetworkEventHook() hook function
+ below. The hook function is called when the network connects. */
+ vApplicationIPInit();
+#endif
+
+ vLoggingPrintf("Starting FreeRTOS scheduler");
+#ifndef VAD_AN552_NO_CONNECTIVITY
+ vLoggingPrintf("Waiting for network");
+#endif
+ /* Start the scheduler itself. */
+ vTaskStartScheduler();
+
+ while (1)
+ {
+ }
+}
+
+void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent)
+{
+#ifndef VAD_AN552_NO_CONNECTIVITY
+ if (eNetworkEvent == eNetworkUp) {
+ vLoggingPrintf("Network connection established");
+ xTaskCreate(mainTask, "main task", configMINIMAL_STACK_SIZE*2, NULL,
+ configMAX_PRIORITIES-4, NULL);
+ }
+#endif
+}
+
+/* Functions needed for mbedtls build */
+static void * prvCalloc(size_t xNmemb,
+ size_t xSize)
+{
+ void * pvNew = pvPortMalloc(xNmemb * xSize);
+
+ if( NULL != pvNew ) {
+ memset(pvNew, 0, xNmemb * xSize);
+ }
+
+ return pvNew;
+}
+
+int mbedtls_hardware_poll(void *data,
+ unsigned char *output, size_t len, size_t *olen)
+{
+ psa_status_t status;
+
+ (void) (data);
+
+ if (output == NULL || olen == NULL) {
+ return -1;
+ }
+
+ status = psa_generate_random(output, len);
+ if (status != PSA_SUCCESS) {
+ return -1;
+ }
+
+ *olen = len;
+
+ return 0;
+}
diff --git a/examples/vad_an552/ns_side/ota_provision.c b/examples/vad_an552/ns_side/ota_provision.c
new file mode 100644
index 0000000..621187d
--- /dev/null
+++ b/examples/vad_an552/ns_side/ota_provision.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2020-2022 Arm Limited. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+/* Key provisioning include. */
+#include "ota_provision.h"
+
+/* This is the public key which is derivated from TF-M's default S key:
+ * bl2/ext/mcuboot/root-rsa-2048.pem.
+ * If you used a different key to sign the image, then please replace the values here
+ * with your public key. Also please note that the OTA service only support RSA2048.
+ * (RSA3072 is not supported).
+ */
+static const char cOTARSAPublicKey[] =
+ "-----BEGIN PUBLIC KEY-----\n"
+ "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0QYIGhhELBjo+/33DaNP\n"
+ "H7vuXvmq0ksY01rpbRiAGfnwnDQby/O8dNtC54x/EFN+Q14NVyxE0WcIDw27XO7s\n"
+ "s5nf4E2EC6p3QWDtFShJpwG0PBDmaYwvX6xBTZ5cFN/y+M89Hm/nW7q0qciIfkc8\n"
+ "lMN3Z1RLqo04NcpiYX634RXbd3PUvntyIYlpJPv4ZW5kPsgO14XVXErkUw0v/7f9\n"
+ "8xM5gz+jrtIPp2qd+f64zvoqvq+44PqCN1T0PuEr0NMIWBj2XkzIiIExrV+wghfy\n"
+ "imknI/Orhz6TGh3+6PgaJGZZ+Byr3M5oG2ZkNez6DRGdr1w6p9FnxkfvsUssYuHR\n"
+ "yQIDAQAB\n"
+ "-----END PUBLIC KEY-----";
+
+/* This function can be found in amazon-freertos at libraries/3rdparty/mbedtls_utils/mbedtls_utils.c. */
+extern int convert_pem_to_der( const unsigned char * pucInput,
+ size_t xLen,
+ unsigned char * pucOutput,
+ size_t * pxOlen );
+
+int ota_privision_code_signing_key(psa_key_handle_t * key_handle)
+{
+ uint8_t public_key_der[310];
+ size_t xLength = 310;
+ int result;
+ psa_status_t status;
+ psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
+
+ result = convert_pem_to_der( ( const unsigned char * ) cOTARSAPublicKey,
+ sizeof( cOTARSAPublicKey ),
+ public_key_der,
+ &xLength );
+ if( result != 0 )
+ {
+ return result;
+ }
+
+ psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
+ psa_set_key_algorithm( &attributes, PSA_ALG_RSA_PSS_ANY_SALT( PSA_ALG_SHA_256 ) );
+ psa_set_key_type( &attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY );
+ psa_set_key_bits( &attributes, 2048 );
+ psa_set_key_lifetime( &attributes, PSA_KEY_LIFETIME_PERSISTENT );
+ psa_set_key_id( &attributes, *key_handle );
+ status = psa_import_key(&attributes, ( const uint8_t *)public_key_der, xLength, key_handle );
+
+ return status;
+}
diff --git a/examples/vad_an552/ns_side/ota_provision.h b/examples/vad_an552/ns_side/ota_provision.h
new file mode 100644
index 0000000..503b87e
--- /dev/null
+++ b/examples/vad_an552/ns_side/ota_provision.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2020-2021 Arm Limited. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _OTA_PROVISION_
+#define _OTA_PROVISION_
+
+#include "psa/crypto.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ota_privision_code_signing_key(psa_key_handle_t * key_handle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/examples/vad_an552/ns_side/platform_eth_dev.c b/examples/vad_an552/ns_side/platform_eth_dev.c
new file mode 100644
index 0000000..5ebcdbe
--- /dev/null
+++ b/examples/vad_an552/ns_side/platform_eth_dev.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "smsc9220_eth_drv.h"
+#include "platform_base_address.h"
+#include "platform_eth_dev.h"
+
+static struct smsc9220_eth_dev_cfg_t SMSC9220_ETH_DEV_CFG_NS = {
+ .base = ETHERNET_BASE_NS
+};
+
+static struct smsc9220_eth_dev_data_t SMSC9220_ETH_DEV_DATA_NS = {
+ .state = 0,
+ .wait_ms = 0,
+ .ongoing_packet_length = 0,
+ .ongoing_packet_length_sent = 0,
+};
+
+struct smsc9220_eth_dev_t SMSC9220_ETH_DEV_NS = {
+ .cfg = &(SMSC9220_ETH_DEV_CFG_NS),
+ .data = &(SMSC9220_ETH_DEV_DATA_NS),
+};
diff --git a/examples/vad_an552/ns_side/platform_eth_dev.h b/examples/vad_an552/ns_side/platform_eth_dev.h
new file mode 100644
index 0000000..fb5a1bf
--- /dev/null
+++ b/examples/vad_an552/ns_side/platform_eth_dev.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __PLATFORM_ETH_DEV_H__
+#define __PLATFORM_ETH_DEV_H__
+
+#include "smsc9220_eth_drv.h"
+
+#define ETH_DEV SMSC9220_ETH_DEV_NS
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct smsc9220_eth_dev_t SMSC9220_ETH_DEV_NS;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PLATFORM_ETH_DEV_H__ */
diff --git a/examples/vad_an552/ns_side/print_log.c b/examples/vad_an552/ns_side/print_log.c
new file mode 100644
index 0000000..1a9b344
--- /dev/null
+++ b/examples/vad_an552/ns_side/print_log.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2018-2021 Arm Limited. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "FreeRTOS.h"
+#include "semphr.h"
+#include "print_log.h"
+
+SemaphoreHandle_t xUARTMutex;
+
+static SemaphoreHandle_t prvCreateUARTMutex( void )
+{
+SemaphoreHandle_t xMutexHandle;
+ xMutexHandle = xSemaphoreCreateMutex();
+ configASSERT( xMutexHandle );
+ return xMutexHandle;
+}
+
+void vUARTLockInit( void )
+{
+ xUARTMutex = prvCreateUARTMutex();
+}
+
+static BaseType_t xUARTLockAcquire()
+{
+ return xSemaphoreTake( xUARTMutex, portMAX_DELAY );
+}
+
+static BaseType_t xUARTLockRelease( void )
+{
+ return xSemaphoreGive( xUARTMutex );
+}
+
+void vLoggingPrintf(const char *format, ...)
+{
+ va_list args;
+ BaseType_t schedulerState = xTaskGetSchedulerState();
+ /* A UART lock is used here to ensure that there is
+ * at most one task accessing UART at a time.
+ */
+ if (schedulerState != taskSCHEDULER_NOT_STARTED) {
+ xUARTLockAcquire();
+ }
+ va_start( args, format );
+ vprintf( format, args );
+ va_end ( args );
+ printf("\r\n");
+ if (schedulerState != taskSCHEDULER_NOT_STARTED) {
+ xUARTLockRelease();
+ }
+}
+
+void vLoggingPrint(const char * message)
+{
+ BaseType_t schedulerState = xTaskGetSchedulerState();
+ /* A UART lock is used here to ensure that there is
+ * at most one task accessing UART at a time.
+ */
+ if (schedulerState != taskSCHEDULER_NOT_STARTED) {
+ xUARTLockAcquire();
+ }
+ puts(message);
+ printf("\r\n");
+ if (schedulerState != taskSCHEDULER_NOT_STARTED) {
+ xUARTLockRelease();
+ }
+}
diff --git a/examples/vad_an552/ns_side/print_log.h b/examples/vad_an552/ns_side/print_log.h
new file mode 100644
index 0000000..7ae28aa
--- /dev/null
+++ b/examples/vad_an552/ns_side/print_log.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018-2021 Arm Limited. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __PRINT_LOG_H__
+#define __PRINT_LOG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Initialize the mutex of UART.
+ */
+void vUARTLockInit(void);
+
+/*
+ * @brief Send printf formatted message to the serial line.
+ */
+void vLoggingPrintf(const char *format, ...);
+
+/*
+ * @brief Send message to the serial line.
+ */
+void vLoggingPrint(const char * message);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PRINT_LOG_H__ */
diff --git a/examples/vad_an552/ns_side/smsc9220_eth_drv.c b/examples/vad_an552/ns_side/smsc9220_eth_drv.c
new file mode 100644
index 0000000..2cb6774
--- /dev/null
+++ b/examples/vad_an552/ns_side/smsc9220_eth_drv.c
@@ -0,0 +1,1079 @@
+/*
+ * Copyright (c) 2016-2021 Arm Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "cmsis.h"
+#include "smsc9220_eth_drv.h"
+
+/** Setter bit manipulation macro */
+#define SET_BIT(WORD, BIT_INDEX) ((WORD) |= (1U << (BIT_INDEX)))
+/** Clearing bit manipulation macro */
+#define CLR_BIT(WORD, BIT_INDEX) ((WORD) &= ~(1U << (BIT_INDEX)))
+/** Getter bit manipulation macro */
+#define GET_BIT(WORD, BIT_INDEX) (bool)(((WORD) & (1U << (BIT_INDEX))))
+
+/** Setter bit-field manipulation macro */
+#define SET_BIT_FIELD(WORD, BIT_MASK, BIT_OFFSET, VALUE) \
+ (WORD |= ((VALUE & BIT_MASK) << BIT_OFFSET))
+
+/** Clearing bit-field manipulation macro */
+#define CLR_BIT_FIELD(WORD, BIT_MASK, BIT_OFFSET, VALUE) \
+ (WORD &= ~((VALUE & BIT_MASK) << BIT_OFFSET))
+
+/** Getter bit-field manipulation macro */
+#define GET_BIT_FIELD(WORD, BIT_MASK, BIT_OFFSET) \
+ ((WORD >> BIT_OFFSET) & BIT_MASK)
+
+/** Millisec timeout macros */
+#define RESET_TIME_OUT_MS 10U
+#define REG_WRITE_TIME_OUT_MS 50U
+#define PHY_RESET_TIME_OUT_MS 100U
+#define INIT_FINISH_DELAY 2000U
+
+struct smsc9220_eth_reg_map_t {
+__I uint32_t rx_data_port; /**< Receive FIFO Ports (offset 0x0) */
+ uint32_t reserved1[0x7];
+__O uint32_t tx_data_port; /**< Transmit FIFO Ports (offset 0x20) */
+ uint32_t reserved2[0x7];
+
+__I uint32_t rx_status_port; /**< Receive FIFO status port (offset 0x40) */
+__I uint32_t rx_status_peek; /**< Receive FIFO status peek (offset 0x44) */
+__I uint32_t tx_status_port; /**< Transmit FIFO status port (offset 0x48) */
+__I uint32_t tx_status_peek; /**< Transmit FIFO status peek (offset 0x4C) */
+
+__I uint32_t id_revision; /**< Chip ID and Revision (offset 0x50) */
+__IO uint32_t irq_cfg; /**< Main Interrupt Config (offset 0x54) */
+__IO uint32_t irq_status; /**< Interrupt Status (offset 0x58) */
+__IO uint32_t irq_enable; /**< Interrupt Enable Register (offset 0x5C) */
+ uint32_t reserved3; /**< Reserved for future use (offset 0x60) */
+__I uint32_t byte_test; /**< Byte order test 87654321h (offset 0x64) */
+__IO uint32_t fifo_level_irq; /**< FIFO Level Interrupts (offset 0x68) */
+__IO uint32_t rx_cfg; /**< Receive Configuration (offset 0x6C) */
+__IO uint32_t tx_cfg; /**< Transmit Configuration (offset 0x70) */
+__IO uint32_t hw_cfg; /**< Hardware Configuration (offset 0x74) */
+__IO uint32_t rx_datapath_ctrl; /**< RX Datapath Control (offset 0x78) */
+__I uint32_t rx_fifo_inf; /**< Receive FIFO Information (offset 0x7C) */
+__I uint32_t tx_fifo_inf; /**< Transmit FIFO Information (offset 0x80) */
+__IO uint32_t pmt_ctrl; /**< Power Management Control (offset 0x84) */
+__IO uint32_t gpio_cfg; /**< GPIO Configuration (offset 0x88) */
+__IO uint32_t gptimer_cfg; /**< GP Timer Configuration (offset 0x8C) */
+__I uint32_t gptimer_count; /**< GP Timer Count (offset 0x90) */
+ uint32_t reserved4; /**< Reserved for future use (offset 0x94) */
+__IO uint32_t word_swap; /**< WORD SWAP Register (offset 0x98) */
+__I uint32_t free_run_counter; /**< Free Run Counter (offset 0x9C) */
+__I uint32_t rx_dropped_frames;/**< RX Dropped Frames Counter (offset 0xA0) */
+__IO uint32_t mac_csr_cmd; /**< MAC CSR Synchronizer Cmd (offset 0xA4) */
+__IO uint32_t mac_csr_data; /**< MAC CSR Synchronizer Data (offset 0xA8) */
+__IO uint32_t afc_cfg; /**< AutomaticFlow Ctrl Config (offset 0xAC) */
+__IO uint32_t eeprom_cmd; /**< EEPROM Command (offset 0xB0) */
+__IO uint32_t eeprom_data; /**< EEPROM Data (offset 0xB4) */
+};
+
+/**
+ * \brief TX FIFO Size definitions
+ *
+ */
+#define TX_STATUS_FIFO_SIZE_BYTES 512U /*< fixed allocation in bytes */
+#define TX_DATA_FIFO_SIZE_KBYTES_POS 16U
+#define TX_DATA_FIFO_SIZE_KBYTES_MASK 0x0FU
+#define KBYTES_TO_BYTES_MULTIPLIER 1024U
+
+/**
+ * \brief FIFO Info definitions
+ *
+ */
+#define DATA_FIFO_USED_SPACE_MASK 0xFFFFU
+#define DATA_FIFO_USED_SPACE_POS 0U
+#define STATUS_FIFO_USED_SPACE_MASK 0xFFU
+#define STATUS_FIFO_USED_SPACE_POS 16U
+
+/**
+ * \brief MAC CSR Synchronizer Command bit definitions
+ *
+ */
+enum mac_csr_cmd_bits_t{
+ MAC_CSR_CMD_RW_INDEX = 30U,
+ MAC_CSR_CMD_BUSY_INDEX = 31U,
+};
+
+#define MAC_CSR_CMD_ADDRESS_MASK 0x0FU
+
+/**
+ * \brief MAC Control register bit definitions
+ *
+ */
+enum mac_reg_cr_bits_t{
+ MAC_REG_CR_RXEN_INDEX = 2U,
+ MAC_REG_CR_TXEN_INDEX = 3U
+};
+
+/**
+ * \brief MII Access register bit definitions
+ *
+ */
+enum mac_reg_mii_acc_bits_t{
+ MAC_REG_MII_ACC_BUSY_INDEX = 0U,
+ MAC_REG_MII_ACC_WRITE_INDEX = 1U,
+ MAC_REG_MII_ACC_PHYADDR_INDEX = 11U
+};
+#define MAC_REG_MII_ACC_MII_REG_MASK 0x1FU
+#define MAC_REG_MII_ACC_MII_REG_OFFSET 6U
+
+/**
+ * \brief Hardware config register bit definitions
+ *
+ */
+enum hw_cfg_reg_bits_t{
+ HW_CFG_REG_SRST_INDEX = 0U,
+ HW_CFG_REG_SRST_TIMEOUT_INDEX = 1U,
+ HW_CFG_REG_MUST_BE_ONE_INDEX = 20U,
+};
+#define HW_CFG_REG_TX_FIFO_SIZE_POS 16U
+#define HW_CFG_REG_TX_FIFO_SIZE_MIN 2U /*< Min Tx fifo size in KB */
+#define HW_CFG_REG_TX_FIFO_SIZE_MAX 14U /*< Max Tx fifo size in KB */
+#define HW_CFG_REG_TX_FIFO_SIZE 5U /*< Tx fifo size in KB */
+
+/**
+ * \brief EEPROM command register bit definitions
+ *
+ */
+enum eeprom_cmd_reg_bits_t{
+ EEPROM_CMD_REG_BUSY_INDEX = 31U,
+};
+
+/**
+ * \brief PHY Basic Control register bit definitions
+ *
+ */
+enum phy_reg_bctrl_reg_bits_t{
+ PHY_REG_BCTRL_RST_AUTO_NEG_INDEX = 9U,
+ PHY_REG_BCTRL_AUTO_NEG_EN_INDEX = 12U,
+ PHY_REG_BCTRL_RESET_INDEX = 15U
+};
+
+/**
+ * \brief TX Command A bit definitions
+ *
+ */
+#define TX_CMD_DATA_START_OFFSET_BYTES_POS 16U
+#define TX_CMD_DATA_START_OFFSET_BYTES_MASK 0x1FU
+
+
+enum tx_command_a_bits_t{
+ TX_COMMAND_A_LAST_SEGMENT_INDEX = 12U,
+ TX_COMMAND_A_FIRST_SEGMENT_INDEX = 13U
+};
+
+#define TX_CMD_PKT_LEN_BYTES_MASK 0x7FFU
+#define TX_CMD_PKT_TAG_MASK 0xFFFFU
+#define TX_CMD_PKT_TAG_POS 16U
+
+
+/**
+ * \brief RX Fifo Status bit definitions
+ *
+ */
+enum rx_fifo_status_bits_t{
+ RX_FIFO_STATUS_CRC_ERROR_INDEX = 1U,
+ RX_FIFO_STATUS_DRIBBLING_BIT_INDEX = 2U,
+ RX_FIFO_STATUS_MII_ERROR_INDEX = 3U,
+ RX_FIFO_STATUS_REC_WD_TIMEOUT_INDEX = 4U,
+ RX_FIFO_STATUS_FRAME_TYPE_INDEX = 5U,
+ RX_FIFO_STATUS_COLLISION_SEEN_INDEX = 6U,
+ RX_FIFO_STATUS_FRAME_TOO_LONG_INDEX = 7U,
+ RX_FIFO_STATUS_MULTICAST_INDEX = 10U,
+ RX_FIFO_STATUS_RUNT_FRAME_INDEX = 11U,
+ RX_FIFO_STATUS_LENGTH_ERROR_INDEX = 12U,
+ RX_FIFO_STATUS_BROADCAST_FRAME_INDEX = 13U,
+ RX_FIFO_STATUS_ERROR_INDEX = 15U,
+ RX_FIFO_STATUS_FILTERING_FAIL_INDEX = 30U,
+};
+#define RX_FIFO_STATUS_PKT_LENGTH_POS 16U
+#define RX_FIFO_STATUS_PKT_LENGTH_MASK 0x3FFFU
+
+/**
+ * \brief Interrupt Configuration register bit definitions
+ *
+ */
+enum irq_cfg_bits_t{
+ IRQ_CFG_IRQ_EN_INDEX = 8U
+};
+
+#define IRQ_CFG_INT_DEAS_MASK 0xFFU
+#define IRQ_CFG_INT_DEAS_POS 24U
+#define IRQ_CFG_INT_DEAS_10US 0x22U
+
+/**
+ * \brief Automatic Flow Control register bit definitions
+ *
+ */
+enum afc_bits_t{
+ AFC_ANY_INDEX = 0U,
+ AFC_ADDR_INDEX = 1U,
+ AFC_BROADCAST_INDEX = 2U,
+ AFC_MULTICAST_INDEX = 3U
+};
+
+/**
+ * \brief Union for easier uint32_t and uint8_t[] conversion
+ *
+ */
+union data_word{
+ uint32_t w;
+ uint8_t b[4];
+};
+
+#define AFC_BACK_DUR_MASK 0x0FU
+#define AFC_BACK_DUR_POS 4U
+#define AFC_BACK_DUR 4U /**< equal to 50us */
+
+#define AFC_LOW_LEVEL_MASK 0xFFU
+#define AFC_LOW_LEVEL_POS 8U
+#define AFC_LOW_LEVEL 55U /**< specifies in multiple of 64 bytes */
+
+#define AFC_HIGH_LEVEL_MASK 0xFFU
+#define AFC_HIGH_LEVEL_POS 16U
+#define AFC_HIGH_LEVEL 110U /**< specifies in multiple of 64 bytes */
+
+/**
+ * \brief Auto-Negotiation Advertisement register bit definitions
+ *
+ */
+enum aneg_bits_t{
+ ANEG_10_BASE_T_INDEX = 5U, /**< 10Mbps able */
+ ANEG_10_BASE_T_FULL_DUPL_INDEX = 6U, /**< 10Mbps with full duplex */
+ ANEG_100_BASE_TX_INDEX = 7U, /**< 100Mbps Tx able */
+ ANEG_100_BASE_TX_FULL_DUPL_INDEX = 8U, /**< 100Mbps with full duplex */
+ ANEG_SYMM_PAUSE_INDEX = 10U, /**< Symmetric Pause */
+ ANEG_ASYMM_PAUSE_INDEX = 11U /**< Asymmetric Pause */
+};
+
+/**
+ * \brief Transmit Configuration register bit definitions
+ *
+ */
+enum tx_cfg_bits_t{
+ TX_CFG_STOP_INDEX = 0U, /*< stop */
+ TX_CFG_ON_INDEX = 1U, /*< on */
+ TX_CFG_AO_INDEX = 2U, /*< allow overrun */
+ TX_CFG_TXD_DUMP_INDEX = 14U, /*< Data FIFO dump */
+ TX_CFG_TXS_DUMP_INDEX = 15U /*< Status FIFO dump */
+};
+
+/**
+ * \brief Chip ID definitions
+ *
+ */
+#define CHIP_ID 0x9220U
+#define CHIP_ID_MASK 0xFFFFU
+#define CHIP_ID_POS 16U
+
+/**
+ * \brief GPIO Configuration register bit definitions
+ *
+ */
+enum gpio_cfg_bits_t{
+ GPIO_CFG_GPIO0_PUSHPULL_INDEX = 16U, /*< GPIO0 push/pull or open-drain */
+ GPIO_CFG_GPIO1_PUSHPULL_INDEX = 17U, /*< GPIO1 push/pull or open-drain */
+ GPIO_CFG_GPIO2_PUSHPULL_INDEX = 18U, /*< GPIO2 push/pull or open-drain */
+ GPIO_CFG_GPIO0_LED_INDEX = 28U, /*< GPIO0 set to LED1 */
+ GPIO_CFG_GPIO1_LED_INDEX = 29U, /*< GPIO1 set to LED2 */
+ GPIO_CFG_GPIO2_LED_INDEX = 30U /*< GPIO2 set to LED3 */
+};
+
+
+static void fill_tx_fifo(const struct smsc9220_eth_dev_t* dev,
+ uint8_t *data, uint32_t size_bytes)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ union data_word d;
+
+ /*If the data length is not a multiple of 4, then the beginning of the first
+ * DWORD of the TX DATA FIFO gets filled up with zeros and a byte offset is
+ * set accordingly to guarantee proper transmission.*/
+ uint32_t remainder_bytes = (size_bytes % 4);
+ uint32_t filler_bytes = (4 - remainder_bytes);
+ for(uint32_t i = 0; i < 4; i++){
+ if(i < filler_bytes){
+ d.b[i] = 0;
+ } else {
+ d.b[i] = data[i-filler_bytes];
+ }
+ }
+ register_map->tx_data_port = d.w;
+ size_bytes -= remainder_bytes;
+ data += remainder_bytes;
+
+ while (size_bytes > 0) {
+ /* Keep the same endianness in data as in the temp variable */
+ for(uint32_t i = 0; i < sizeof(d.w); i++) {
+ d.b[i] = data[i];
+ }
+
+ register_map->tx_data_port = d.w;
+ data += sizeof(d.w);
+ size_bytes -= sizeof(d.w);
+ }
+}
+
+static void empty_rx_fifo(const struct smsc9220_eth_dev_t* dev,
+ uint8_t *data, uint32_t size_bytes)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+ uint32_t dummy;
+ union data_word d;
+ uint32_t remainder_bytes = (size_bytes % 4);
+ size_bytes -= remainder_bytes;
+
+ while (size_bytes > 0) {
+ /* Keep the same endianness in data as in the temp variable */
+ d.w = register_map->rx_data_port;
+ for(uint32_t i = 0; i < sizeof(d.w); i++) {
+ data[i] = d.b[i];
+ }
+ data += sizeof(d.w);
+ size_bytes -= sizeof(d.w);
+ }
+
+ if ( remainder_bytes > 0 ) {
+ d.w = register_map->rx_data_port;
+ for(uint32_t i = 0; i < remainder_bytes; i++) {
+ data[i] = d.b[i];
+ }
+ }
+
+ /* Read the status fifo to flush the latest status */
+ dummy = register_map->rx_status_port;
+}
+
+
+enum smsc9220_error_t smsc9220_mac_regread(
+ const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_mac_reg_offsets_t regoffset,
+ uint32_t *data)
+{
+ volatile uint32_t val;
+ uint32_t maccmd = GET_BIT_FIELD(regoffset,
+ MAC_CSR_CMD_ADDRESS_MASK, 0);
+ uint32_t time_out = REG_WRITE_TIME_OUT_MS;
+
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ /* Make sure there's no pending operation */
+ if(!(GET_BIT(register_map->mac_csr_cmd, MAC_CSR_CMD_BUSY_INDEX))) {
+ SET_BIT(maccmd, MAC_CSR_CMD_RW_INDEX);
+ SET_BIT(maccmd, MAC_CSR_CMD_BUSY_INDEX);
+ register_map->mac_csr_cmd = maccmd; /* Start operation */
+
+ do {
+ val = register_map->byte_test; /* A no-op read. */
+ (void)val;
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(1);
+ }
+ time_out--;
+ } while(time_out &&
+ GET_BIT(register_map->mac_csr_cmd,MAC_CSR_CMD_BUSY_INDEX));
+
+ if(!time_out) {
+ return SMSC9220_ERROR_TIMEOUT;
+ }
+ else {
+ *data = register_map->mac_csr_data;
+ }
+ } else {
+ return SMSC9220_ERROR_BUSY;
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+enum smsc9220_error_t smsc9220_mac_regwrite(
+ const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_mac_reg_offsets_t regoffset,
+ uint32_t data)
+{
+ volatile uint32_t read = 0;
+ uint32_t maccmd = GET_BIT_FIELD(regoffset,
+ MAC_CSR_CMD_ADDRESS_MASK, 0);
+ uint32_t time_out = REG_WRITE_TIME_OUT_MS;
+
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ /* Make sure there's no pending operation */
+ if(!GET_BIT(register_map->mac_csr_cmd, MAC_CSR_CMD_BUSY_INDEX)) {
+ register_map->mac_csr_data = data; /* Store data. */
+ CLR_BIT(maccmd, MAC_CSR_CMD_RW_INDEX);
+ SET_BIT(maccmd, MAC_CSR_CMD_BUSY_INDEX);
+ register_map->mac_csr_cmd = maccmd;
+
+ do {
+ read = register_map->byte_test; /* A no-op read. */
+ (void)read;
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(1);
+ }
+ time_out--;
+ } while(time_out &&
+ (register_map->mac_csr_cmd &
+ GET_BIT(register_map->mac_csr_cmd, MAC_CSR_CMD_BUSY_INDEX)));
+
+ if(!time_out) {
+ return SMSC9220_ERROR_TIMEOUT;
+ }
+ } else {
+ return SMSC9220_ERROR_BUSY;
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+enum smsc9220_error_t smsc9220_phy_regread(
+ const struct smsc9220_eth_dev_t* dev,
+ enum phy_reg_offsets_t regoffset,
+ uint32_t *data)
+{
+ uint32_t val = 0;
+ uint32_t phycmd = 0;
+ uint32_t time_out = REG_WRITE_TIME_OUT_MS;
+
+ if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_MII_ACC, &val)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+
+ if(!GET_BIT(val, MAC_REG_MII_ACC_BUSY_INDEX)) {
+ phycmd = 0;
+ SET_BIT(phycmd, MAC_REG_MII_ACC_PHYADDR_INDEX);
+ SET_BIT_FIELD(phycmd, MAC_REG_MII_ACC_MII_REG_MASK,
+ MAC_REG_MII_ACC_MII_REG_OFFSET, regoffset);
+ CLR_BIT(phycmd, MAC_REG_MII_ACC_WRITE_INDEX);
+ SET_BIT(phycmd, MAC_REG_MII_ACC_BUSY_INDEX);
+
+ if (smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_MII_ACC,
+ phycmd)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+
+ val = 0;
+ do {
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(1);
+ }
+ time_out--;
+ if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_MII_ACC,
+ &val)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ } while(time_out && (GET_BIT(val, MAC_REG_MII_ACC_BUSY_INDEX)));
+
+ if (!time_out) {
+ return SMSC9220_ERROR_TIMEOUT;
+ } else if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_MII_DATA,
+ data)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ } else {
+ return SMSC9220_ERROR_BUSY;
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+enum smsc9220_error_t smsc9220_phy_regwrite(
+ const struct smsc9220_eth_dev_t* dev,
+ enum phy_reg_offsets_t regoffset,
+ uint32_t data)
+{
+ uint32_t val = 0;
+ uint32_t phycmd = 0;
+ uint32_t time_out = REG_WRITE_TIME_OUT_MS;
+
+ if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_MII_ACC, &val)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+
+ if(!GET_BIT(val, MAC_REG_MII_ACC_BUSY_INDEX)) {
+ /* Load the data */
+ if (smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_MII_DATA,
+ (data & 0xFFFF))) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ phycmd = 0;
+ SET_BIT(phycmd, MAC_REG_MII_ACC_PHYADDR_INDEX);
+ SET_BIT_FIELD(phycmd, MAC_REG_MII_ACC_MII_REG_MASK,
+ MAC_REG_MII_ACC_MII_REG_OFFSET, regoffset);
+ SET_BIT(phycmd, MAC_REG_MII_ACC_WRITE_INDEX);
+ SET_BIT(phycmd, MAC_REG_MII_ACC_BUSY_INDEX);
+ /* Start operation */
+ if (smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_MII_ACC,
+ phycmd)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+
+ phycmd = 0;
+
+ do {
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(1);
+ }
+ time_out--;
+ if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_MII_ACC,
+ &phycmd)){
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ } while(time_out && GET_BIT(phycmd, 0));
+
+ if (!time_out) {
+ return SMSC9220_ERROR_TIMEOUT;
+ }
+
+ } else {
+ return SMSC9220_ERROR_BUSY;
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+uint32_t smsc9220_read_id(const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ return register_map->id_revision;
+}
+
+enum smsc9220_error_t smsc9220_soft_reset(
+ const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t time_out = RESET_TIME_OUT_MS;
+
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ /* Soft reset */
+ SET_BIT(register_map->hw_cfg, HW_CFG_REG_SRST_INDEX);
+
+ do {
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(1);
+ }
+ time_out--;
+ } while(time_out &&
+ GET_BIT(register_map->hw_cfg, HW_CFG_REG_SRST_TIMEOUT_INDEX));
+
+ if (!time_out) {
+ return SMSC9220_ERROR_TIMEOUT;
+ }
+
+ return SMSC9220_ERROR_NONE;
+}
+
+void smsc9220_set_txfifo(const struct smsc9220_eth_dev_t* dev,
+ uint32_t val)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ if(val >= HW_CFG_REG_TX_FIFO_SIZE_MIN &&
+ val <= HW_CFG_REG_TX_FIFO_SIZE_MAX) {
+ register_map->hw_cfg = val << HW_CFG_REG_TX_FIFO_SIZE_POS;
+ }
+}
+
+enum smsc9220_error_t smsc9220_set_fifo_level_irq(
+ const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_fifo_level_irq_pos_t irq_level_pos,
+ uint32_t level)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ if (level > SMSC9220_FIFO_LEVEL_IRQ_LEVEL_MAX) {
+ return SMSC9220_ERROR_PARAM;
+ }
+
+ CLR_BIT_FIELD(register_map->fifo_level_irq, SMSC9220_FIFO_LEVEL_IRQ_MASK,
+ irq_level_pos, SMSC9220_FIFO_LEVEL_IRQ_MASK);
+ SET_BIT_FIELD(register_map->fifo_level_irq, SMSC9220_FIFO_LEVEL_IRQ_MASK,
+ irq_level_pos, level);
+ return SMSC9220_ERROR_NONE;
+}
+
+enum smsc9220_error_t smsc9220_wait_eeprom(
+ const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t time_out = REG_WRITE_TIME_OUT_MS;
+
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ do {
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(1);
+ }
+ time_out--;
+ } while(time_out &&
+ GET_BIT(register_map->eeprom_cmd, EEPROM_CMD_REG_BUSY_INDEX));
+
+ if (!time_out) {
+ return SMSC9220_ERROR_TIMEOUT;
+ }
+
+ return SMSC9220_ERROR_NONE;
+}
+
+void smsc9220_init_irqs(const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ smsc9220_disable_all_interrupts(dev);
+ smsc9220_clear_all_interrupts(dev);
+
+ /* Set IRQ deassertion interval */
+ SET_BIT_FIELD(register_map->irq_cfg, IRQ_CFG_INT_DEAS_MASK,
+ IRQ_CFG_INT_DEAS_POS, IRQ_CFG_INT_DEAS_10US);
+
+ /* enable interrupts */
+ SET_BIT(register_map->irq_cfg, IRQ_CFG_IRQ_EN_INDEX);
+}
+
+enum smsc9220_error_t smsc9220_check_phy(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t phyid1 = 0;
+ uint32_t phyid2 = 0;
+
+ if (smsc9220_phy_regread(dev, SMSC9220_PHY_REG_OFFSET_ID1,&phyid1)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ if (smsc9220_phy_regread(dev, SMSC9220_PHY_REG_OFFSET_ID2,&phyid2)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ if ((phyid1 == 0xFFFF && phyid2 == 0xFFFF) ||
+ (phyid1 == 0x0 && phyid2 == 0x0)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+enum smsc9220_error_t smsc9220_reset_phy(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t read = 0;
+
+ if(smsc9220_phy_regread(dev, SMSC9220_PHY_REG_OFFSET_BCTRL, &read)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+
+ SET_BIT(read, PHY_REG_BCTRL_RESET_INDEX);
+ if(smsc9220_phy_regwrite(dev, SMSC9220_PHY_REG_OFFSET_BCTRL, read)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+void smsc9220_advertise_cap(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t aneg_adv = 0;
+ smsc9220_phy_regread(dev, SMSC9220_PHY_REG_OFFSET_ANEG_ADV, &aneg_adv);
+
+ SET_BIT(aneg_adv, ANEG_10_BASE_T_INDEX);
+ SET_BIT(aneg_adv, ANEG_10_BASE_T_FULL_DUPL_INDEX);
+ SET_BIT(aneg_adv, ANEG_100_BASE_TX_INDEX);
+ SET_BIT(aneg_adv, ANEG_100_BASE_TX_FULL_DUPL_INDEX);
+ SET_BIT(aneg_adv, ANEG_SYMM_PAUSE_INDEX);
+ SET_BIT(aneg_adv, ANEG_ASYMM_PAUSE_INDEX);
+
+ smsc9220_phy_regwrite(dev, SMSC9220_PHY_REG_OFFSET_ANEG_ADV, aneg_adv);
+}
+
+void smsc9220_enable_xmit(const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ SET_BIT(register_map->tx_cfg, TX_CFG_ON_INDEX);
+}
+
+void smsc9220_disable_xmit(const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ CLR_BIT(register_map->tx_cfg, TX_CFG_ON_INDEX);
+}
+
+void smsc9220_enable_mac_xmit(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t mac_cr = 0;
+ smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_CR, &mac_cr);
+
+ SET_BIT(mac_cr, MAC_REG_CR_TXEN_INDEX);
+
+ smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_CR, mac_cr);
+}
+
+void smsc9220_disable_mac_xmit(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t mac_cr = 0;
+ smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_CR, &mac_cr);
+
+ CLR_BIT(mac_cr, MAC_REG_CR_TXEN_INDEX);
+
+ smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_CR, mac_cr);
+}
+
+void smsc9220_enable_mac_recv(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t mac_cr = 0;
+ smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_CR, &mac_cr);
+
+ SET_BIT(mac_cr, MAC_REG_CR_RXEN_INDEX);
+
+ smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_CR, mac_cr);
+}
+
+void smsc9220_disable_mac_recv(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t mac_cr = 0;
+ smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_CR, &mac_cr);
+
+ CLR_BIT(mac_cr, MAC_REG_CR_RXEN_INDEX);
+
+ smsc9220_mac_regwrite(dev, SMSC9220_MAC_REG_OFFSET_CR, mac_cr);
+}
+
+int smsc9220_check_id(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t id = smsc9220_read_id(dev);
+
+ return ((GET_BIT_FIELD(id, CHIP_ID_MASK, CHIP_ID_POS) == CHIP_ID) ? 0 : 1);
+}
+
+void smsc9220_enable_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ SET_BIT(register_map->irq_enable, source);
+}
+
+void smsc9220_disable_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ CLR_BIT(register_map->irq_enable, source);
+}
+
+void smsc9220_disable_all_interrupts(const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ register_map->irq_enable = 0;
+}
+
+void smsc9220_clear_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ SET_BIT(register_map->irq_status, source);
+}
+
+void smsc9220_clear_all_interrupts(const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ register_map->irq_status = UINT32_MAX;
+}
+
+int smsc9220_get_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ return GET_BIT(register_map->irq_status, source);
+}
+
+void smsc9220_establish_link(const struct smsc9220_eth_dev_t* dev)
+{
+ uint32_t bcr = 0;
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ smsc9220_phy_regread(dev, SMSC9220_PHY_REG_OFFSET_BCTRL, &bcr);
+ SET_BIT(bcr, PHY_REG_BCTRL_AUTO_NEG_EN_INDEX);
+ SET_BIT(bcr, PHY_REG_BCTRL_RST_AUTO_NEG_INDEX);
+ smsc9220_phy_regwrite(dev, SMSC9220_PHY_REG_OFFSET_BCTRL, bcr);
+
+ SET_BIT(register_map->hw_cfg, HW_CFG_REG_MUST_BE_ONE_INDEX);
+}
+
+enum smsc9220_error_t smsc9220_read_mac_address(
+ const struct smsc9220_eth_dev_t* dev, char *mac)
+{
+ uint32_t mac_low = 0;
+ uint32_t mac_high = 0;
+
+ if(!mac) {
+ return SMSC9220_ERROR_PARAM;
+ }
+
+ if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_ADDRH, &mac_high)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ if (smsc9220_mac_regread(dev, SMSC9220_MAC_REG_OFFSET_ADDRL, &mac_low)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+ mac[0] = mac_low & 0xFF;
+ mac[1] = (mac_low >> 8) & 0xFF;
+ mac[2] = (mac_low >> 16) & 0xFF;
+ mac[3] = (mac_low >> 24) & 0xFF;
+ mac[4] = mac_high & 0xFF;
+ mac[5] = (mac_high >> 8) & 0xFF;
+
+ return SMSC9220_ERROR_NONE;
+}
+
+uint32_t smsc9220_get_tx_data_fifo_size(
+ const struct smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ uint32_t tx_fifo_size =
+ GET_BIT_FIELD(register_map->hw_cfg,
+ TX_DATA_FIFO_SIZE_KBYTES_MASK,
+ TX_DATA_FIFO_SIZE_KBYTES_POS) * KBYTES_TO_BYTES_MULTIPLIER;
+
+ return (tx_fifo_size - TX_STATUS_FIFO_SIZE_BYTES);
+}
+
+enum smsc9220_error_t smsc9220_init(
+ const struct smsc9220_eth_dev_t* dev,
+ void(* wait_ms_function)(int))
+{
+ uint32_t phyreset = 0;
+ enum smsc9220_error_t error = SMSC9220_ERROR_NONE;
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ if (!wait_ms_function) {
+ return SMSC9220_ERROR_PARAM;
+ }
+ dev->data->wait_ms = wait_ms_function;
+
+ error = smsc9220_check_id(dev);
+ if(error != SMSC9220_ERROR_NONE) {
+ return error;
+ }
+
+ error = smsc9220_soft_reset(dev);
+ if(error != SMSC9220_ERROR_NONE) {
+ return error;
+ }
+
+ smsc9220_set_txfifo(dev, HW_CFG_REG_TX_FIFO_SIZE);
+
+ SET_BIT_FIELD(register_map->afc_cfg, AFC_BACK_DUR_MASK,
+ AFC_BACK_DUR_POS, AFC_BACK_DUR);
+ SET_BIT_FIELD(register_map->afc_cfg, AFC_LOW_LEVEL_MASK,
+ AFC_LOW_LEVEL_POS, AFC_LOW_LEVEL);
+ SET_BIT_FIELD(register_map->afc_cfg, AFC_HIGH_LEVEL_MASK,
+ AFC_HIGH_LEVEL_POS, AFC_HIGH_LEVEL);
+
+ error = smsc9220_wait_eeprom(dev);
+ if(error != SMSC9220_ERROR_NONE) {
+ return error;
+ }
+
+ /* Configure GPIOs as LED outputs. */
+ register_map->gpio_cfg = 0;
+ SET_BIT(register_map->gpio_cfg, GPIO_CFG_GPIO0_PUSHPULL_INDEX);
+ SET_BIT(register_map->gpio_cfg, GPIO_CFG_GPIO1_PUSHPULL_INDEX);
+ SET_BIT(register_map->gpio_cfg, GPIO_CFG_GPIO2_PUSHPULL_INDEX);
+ SET_BIT(register_map->gpio_cfg, GPIO_CFG_GPIO0_LED_INDEX);
+ SET_BIT(register_map->gpio_cfg, GPIO_CFG_GPIO1_LED_INDEX);
+ SET_BIT(register_map->gpio_cfg, GPIO_CFG_GPIO2_LED_INDEX);
+
+ smsc9220_init_irqs(dev);
+
+ /* Configure MAC addresses here if needed. */
+
+ error = smsc9220_check_phy(dev);
+ if(error != SMSC9220_ERROR_NONE) {
+ return error;
+ }
+
+ error = smsc9220_reset_phy(dev);
+ if(error != SMSC9220_ERROR_NONE) {
+ return error;
+ }
+
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(PHY_RESET_TIME_OUT_MS);
+ }
+ /* Checking whether phy reset completed successfully.*/
+ error = smsc9220_phy_regread(dev, SMSC9220_PHY_REG_OFFSET_BCTRL,
+ &phyreset);
+ if(error != SMSC9220_ERROR_NONE) {
+ return error;
+ }
+
+ if(GET_BIT(phyreset, PHY_REG_BCTRL_RESET_INDEX)) {
+ return SMSC9220_ERROR_INTERNAL;
+ }
+
+ smsc9220_advertise_cap(dev);
+ smsc9220_establish_link(dev);
+
+ smsc9220_enable_mac_xmit(dev);
+ smsc9220_enable_xmit(dev);
+ smsc9220_enable_mac_recv(dev);
+
+ /* This sleep is compulsory otherwise txmit/receive will fail. */
+ if (dev->data->wait_ms) {
+ dev->data->wait_ms(INIT_FINISH_DELAY);
+ }
+ dev->data->state = 1;
+
+ return SMSC9220_ERROR_NONE;
+}
+
+enum smsc9220_error_t smsc9220_send_by_chunks(
+ const struct smsc9220_eth_dev_t* dev,
+ uint32_t total_payload_length,
+ bool is_new_packet,
+ const char *data, uint32_t current_size)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+ bool is_first_segment = false;
+ bool is_last_segment = false;
+ uint32_t txcmd_a, txcmd_b = 0;
+ uint32_t tx_buffer_free_space = 0;
+ volatile uint32_t xmit_stat = 0;
+
+ if (!data) {
+ return SMSC9220_ERROR_PARAM;
+ }
+
+ if (is_new_packet) {
+ is_first_segment = true;
+ dev->data->ongoing_packet_length = total_payload_length;
+ dev->data->ongoing_packet_length_sent = 0;
+ } else if (dev->data->ongoing_packet_length != total_payload_length ||
+ dev->data->ongoing_packet_length_sent >= total_payload_length) {
+ return SMSC9220_ERROR_PARAM;
+ }
+
+ /* Would next chunk fit into buffer? */
+ tx_buffer_free_space = GET_BIT_FIELD(register_map->tx_fifo_inf,
+ DATA_FIFO_USED_SPACE_MASK,
+ DATA_FIFO_USED_SPACE_POS);
+ if (current_size > tx_buffer_free_space) {
+ return SMSC9220_ERROR_INTERNAL; /* Not enough space in FIFO */
+ }
+ if ((dev->data->ongoing_packet_length_sent + current_size) ==
+ total_payload_length) {
+ is_last_segment = true;
+ }
+
+ txcmd_a = 0;
+ txcmd_b = 0;
+
+ if (is_last_segment) {
+ SET_BIT(txcmd_a, TX_COMMAND_A_LAST_SEGMENT_INDEX);
+ }
+ if (is_first_segment) {
+ SET_BIT(txcmd_a, TX_COMMAND_A_FIRST_SEGMENT_INDEX);
+ }
+
+ uint32_t data_start_offset_bytes = (4 - (current_size % 4));
+
+ SET_BIT_FIELD(txcmd_a, TX_CMD_PKT_LEN_BYTES_MASK, 0, current_size);
+ SET_BIT_FIELD(txcmd_a, TX_CMD_DATA_START_OFFSET_BYTES_MASK,
+ TX_CMD_DATA_START_OFFSET_BYTES_POS,
+ data_start_offset_bytes);
+
+ SET_BIT_FIELD(txcmd_b, TX_CMD_PKT_LEN_BYTES_MASK, 0, current_size);
+ SET_BIT_FIELD(txcmd_b, TX_CMD_PKT_TAG_MASK, TX_CMD_PKT_TAG_POS,
+ current_size);
+
+ register_map->tx_data_port = txcmd_a;
+ register_map->tx_data_port = txcmd_b;
+
+ fill_tx_fifo(dev, (uint8_t *)data, current_size);
+
+ if (is_last_segment) {
+ /* Pop status port for error check */
+ xmit_stat = register_map->tx_status_port;
+ (void)xmit_stat;
+ }
+ dev->data->ongoing_packet_length_sent += current_size;
+ return SMSC9220_ERROR_NONE;
+}
+
+uint32_t smsc9220_get_received_packet_count(const struct
+ smsc9220_eth_dev_t* dev)
+{
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ return GET_BIT_FIELD(register_map->rx_fifo_inf, STATUS_FIFO_USED_SPACE_MASK,
+ STATUS_FIFO_USED_SPACE_POS);
+}
+
+enum smsc9220_error_t smsc9220_get_received_packet(const struct smsc9220_eth_dev_t* dev,
+ char *data, uint32_t dlen)
+{
+ uint32_t packet_length_byte = 0;
+
+ if (!data) {
+ return SMSC9220_ERROR_PARAM; /* Invalid input parameter, cannot read */
+ }
+
+ packet_length_byte = smsc9220_peek_next_packet_size(dev);
+
+ if (dlen != packet_length_byte) {
+ return SMSC9220_ERROR_PARAM;
+ } else {
+ empty_rx_fifo(dev, (uint8_t *)data, packet_length_byte);
+ }
+ return SMSC9220_ERROR_NONE;
+}
+
+uint32_t smsc9220_peek_next_packet_size(const struct
+ smsc9220_eth_dev_t* dev)
+{
+ uint32_t packet_size = 0;
+ struct smsc9220_eth_reg_map_t* register_map =
+ (struct smsc9220_eth_reg_map_t*)dev->cfg->base;
+
+ /* Check if there is a queued packet before checking its size. */
+ if(smsc9220_get_received_packet_count(dev)) {
+ packet_size = GET_BIT_FIELD(register_map->rx_status_peek,
+ RX_FIFO_STATUS_PKT_LENGTH_MASK,
+ RX_FIFO_STATUS_PKT_LENGTH_POS);
+ }
+ return packet_size;
+}
diff --git a/examples/vad_an552/ns_side/smsc9220_eth_drv.h b/examples/vad_an552/ns_side/smsc9220_eth_drv.h
new file mode 100644
index 0000000..8c6cd05
--- /dev/null
+++ b/examples/vad_an552/ns_side/smsc9220_eth_drv.h
@@ -0,0 +1,549 @@
+/*
+ * Copyright (c) 2016-2021 Arm Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * \file smsc9220_drv.h
+ * \brief Generic driver for SMSC9220 Ethernet controller
+ */
+
+#ifndef __SMSC9220_ETH_H__
+#define __SMSC9220_ETH_H__
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** SMSC9220 device configuration structure */
+struct smsc9220_eth_dev_cfg_t {
+ const uint32_t base; /*!< SMSC9220 base address */
+};
+
+/** SMSC9220 device data structure */
+struct smsc9220_eth_dev_data_t {
+ uint32_t state; /*!< Indicates if the SMSC9220 driver
+ is initialized and enabled */
+ void (*wait_ms) (int);/*!< function pointer to system's millisec delay
+ function, will be used for delays */
+ uint32_t ongoing_packet_length;/*!< size in bytes of the packet
+ is being sent */
+ uint32_t ongoing_packet_length_sent; /*!< size in bytes of the packet
+ has been sent */
+};
+
+/** SMSC9220 device structure */
+struct smsc9220_eth_dev_t {
+ const struct smsc9220_eth_dev_cfg_t* const cfg; /*!< configuration */
+ struct smsc9220_eth_dev_data_t* const data; /*!< data */
+};
+
+/**
+ * \brief Error code definitions
+ *
+ */
+enum smsc9220_error_t{
+ SMSC9220_ERROR_NONE = 0U, /*!< no error */
+ SMSC9220_ERROR_TIMEOUT = 1U, /*!< timeout */
+ SMSC9220_ERROR_BUSY = 2U, /*!< no error */
+ SMSC9220_ERROR_PARAM = 3U, /*!< invalid parameter */
+ SMSC9220_ERROR_INTERNAL = 4U /*!< internal error */
+};
+
+/**
+ * \brief Interrupt source definitions
+ *
+ */
+enum smsc9220_interrupt_source {
+ SMSC9220_INTERRUPT_GPIO0 = 0U,
+ SMSC9220_INTERRUPT_GPIO1 = 1U,
+ SMSC9220_INTERRUPT_GPIO2 = 2U,
+ SMSC9220_INTERRUPT_RX_STATUS_FIFO_LEVEL = 3U,
+ SMSC9220_INTERRUPT_RX_STATUS_FIFO_FULL = 4U,
+ /* 5 Reserved according to Datasheet */
+ SMSC9220_INTERRUPT_RX_DROPPED_FRAME = 6U,
+ SMSC9220_INTERRUPT_TX_STATUS_FIFO_LEVEL = 7U,
+ SMSC9220_INTERRUPT_TX_STATUS_FIFO_FULL = 8U,
+ SMSC9220_INTERRUPT_TX_DATA_FIFO_AVAILABLE = 9U,
+ SMSC9220_INTERRUPT_TX_DATA_FIFO_OVERRUN = 10U,
+ /* 11, 12 Reserved according to Datasheet */
+ SMSC9220_INTERRUPT_TX_ERROR = 13U,
+ SMSC9220_INTERRUPT_RX_ERROR = 14U,
+ SMSC9220_INTERRUPT_RX_WATCHDOG_TIMEOUT = 15U,
+ SMSC9220_INTERRUPT_TX_STATUS_OVERFLOW = 16U,
+ SMSC9220_INTERRUPT_TX_POWER_MANAGEMENT = 17U,
+ SMSC9220_INTERRUPT_PHY = 18U,
+ SMSC9220_INTERRUPT_GP_TIMER = 19U,
+ SMSC9220_INTERRUPT_RX_DMA = 20U,
+ SMSC9220_INTERRUPT_TX_IOC = 21U,
+ /* 22 Reserved according to Datasheet*/
+ SMSC9220_INTERRUPT_RX_DROPPED_FRAME_HALF = 23U,
+ SMSC9220_INTERRUPT_RX_STOPPED = 24U,
+ SMSC9220_INTERRUPT_TX_STOPPED = 25U,
+ /* 26 - 30 Reserved according to Datasheet*/
+ SMSC9220_INTERRUPT_SW = 31U
+};
+
+/**
+ * \brief MAC register offset definitions
+ *
+ */
+enum smsc9220_mac_reg_offsets_t{
+ SMSC9220_MAC_REG_OFFSET_CR = 0x1U,
+ SMSC9220_MAC_REG_OFFSET_ADDRH = 0x2U,
+ SMSC9220_MAC_REG_OFFSET_ADDRL = 0x3U,
+ SMSC9220_MAC_REG_OFFSET_HASHH = 0x4U,
+ SMSC9220_MAC_REG_OFFSET_HASHL = 0x5U,
+ SMSC9220_MAC_REG_OFFSET_MII_ACC = 0x6U,
+ SMSC9220_MAC_REG_OFFSET_MII_DATA = 0x7U,
+ SMSC9220_MAC_REG_OFFSET_FLOW = 0x8U,
+ SMSC9220_MAC_REG_OFFSET_VLAN1 = 0x9U,
+ SMSC9220_MAC_REG_OFFSET_VLAN2 = 0xAU,
+ SMSC9220_MAC_REG_OFFSET_WUFF = 0xBU,
+ SMSC9220_MAC_REG_OFFSET_WUCSR = 0xCU,
+ SMSC9220_MAC_REG_OFFSET_COE_CR = 0xDU
+};
+
+/**
+ * \brief PHY register offset definitions
+ *
+ */
+enum phy_reg_offsets_t{
+ SMSC9220_PHY_REG_OFFSET_BCTRL = 0U,
+ SMSC9220_PHY_REG_OFFSET_BSTATUS = 1U,
+ SMSC9220_PHY_REG_OFFSET_ID1 = 2U,
+ SMSC9220_PHY_REG_OFFSET_ID2 = 3U,
+ SMSC9220_PHY_REG_OFFSET_ANEG_ADV = 4U,
+ SMSC9220_PHY_REG_OFFSET_ANEG_LPA = 5U,
+ SMSC9220_PHY_REG_OFFSET_ANEG_EXP = 6U,
+ SMSC9220_PHY_REG_OFFSET_MCONTROL = 17U,
+ SMSC9220_PHY_REG_OFFSET_MSTATUS = 18U,
+ SMSC9220_PHY_REG_OFFSET_CSINDICATE = 27U,
+ SMSC9220_PHY_REG_OFFSET_INTSRC = 29U,
+ SMSC9220_PHY_REG_OFFSET_INTMASK = 30U,
+ SMSC9220_PHY_REG_OFFSET_CS = 31U
+};
+
+/* Bit definitions for PHY Basic Status Register */
+#define PHY_REG_BSTATUS_EXTENDED_CAPABILITIES_INDEX 0U
+#define PHY_REG_BSTATUS_JABBER_DETECT_INDEX 1U
+#define PHY_REG_BSTATUS_LINK_STATUS_INDEX 2U
+#define PHY_REG_BSTATUS_AUTO_NEG_ABILITY_INDEX 3U
+#define PHY_REG_BSTATUS_REMOTE_FAULT_INDEX 4U
+#define PHY_REG_BSTATUS_AUTO_NEG_COMPLETE_INDEX 5U
+#define PHY_REG_BSTATUS_10BASE_T_HALF_DUPLEX_INDEX 11U
+#define PHY_REG_BSTATUS_10BASE_T_FULL_DUPLEX_INDEX 12U
+#define PHY_REG_BSTATUS_100BASE_TX_HALF_DUPLEX_INDEX 13U
+#define PHY_REG_BSTATUS_100BASE_TX_FULL_DUPLEX_INDEX 14U
+#define PHY_REG_BSTATUS_100BASE_T4_INDEX 15U
+
+/**
+ * \brief FIFO Level Interrupt bit definitions
+ *
+ */
+enum smsc9220_fifo_level_irq_pos_t{
+ SMSC9220_FIFO_LEVEL_IRQ_RX_STATUS_POS = 0U,
+ SMSC9220_FIFO_LEVEL_IRQ_TX_STATUS_POS = 16U,
+ SMSC9220_FIFO_LEVEL_IRQ_TX_DATA_POS = 24U
+};
+
+/**
+ * \brief FIFO Level Interrupt limits
+ *
+ */
+#define SMSC9220_FIFO_LEVEL_IRQ_MASK 0xFFU
+#define SMSC9220_FIFO_LEVEL_IRQ_LEVEL_MIN 0U
+#define SMSC9220_FIFO_LEVEL_IRQ_LEVEL_MAX SMSC9220_FIFO_LEVEL_IRQ_MASK
+
+/**
+ * \brief Initializes SMSC9220 Ethernet controller to a known default state:
+ * - device ID is checked
+ * - global interrupt is enabled, but all irq sources are disabled
+ * - all capabilities are advertised
+ * - 10Mbps able
+ * - 10Mbps with full duplex
+ * - 100Mbps Tx able
+ * - 100Mbps with full duplex
+ * - Symmetric Pause
+ * - Asymmetric Pause
+ * - Establish link enabled
+ * - Rx enabled
+ * - Tx enabled
+ * Init should be called prior to any other process and
+ * it's the caller's responsibility to follow proper call order.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] wait_ms_function function pointer to a millisec delay function
+ * for proper timing of some processes
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_init(const struct smsc9220_eth_dev_t* dev,
+ void(* wait_ms_function)(int));
+
+/**
+ * \brief Reads the MAC register.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] regoffset Register offset
+ * \param[in, out] data Pointer to register will be read
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_mac_regread(
+ const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_mac_reg_offsets_t regoffset,
+ uint32_t *data);
+
+/**
+ * \brief Writes the MAC register.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] regoffset Register offset
+ * \param[in] data Register value to write
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_mac_regwrite(
+ const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_mac_reg_offsets_t regoffset,
+ uint32_t data);
+
+/**
+ * \brief Reads the PHY register.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] regoffset Register offset
+ * \param[out] data Register value is read
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_phy_regread(
+ const struct smsc9220_eth_dev_t* dev,
+ enum phy_reg_offsets_t,
+ uint32_t *data);
+
+/**
+ * \brief Writes the PHY register.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] regoffset Register offset
+ * \param[in] data Register value to write
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_phy_regwrite(
+ const struct smsc9220_eth_dev_t* dev,
+ enum phy_reg_offsets_t,
+ uint32_t data);
+
+/**
+ * \brief Reads the Ethernet Controller's ID.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return ID number
+ */
+uint32_t smsc9220_read_id(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Initiates a soft reset, returns failure or success.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_soft_reset(
+ const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Sets the Maximum Transmission Unit by Tx fifo size.
+ * Note: The MTU will be smaller by 512 bytes,
+ * whis is used by the status.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] val Size of the fifo in kbytes
+ * \ref HW_CFG_REG_TX_FIFO_SIZE_MIN
+ * \ref HW_CFG_REG_TX_FIFO_SIZE_MAX
+ */
+void smsc9220_set_txfifo(const struct smsc9220_eth_dev_t* dev,
+ uint32_t val);
+
+/**
+ * \brief Sets the FIFO level interrupt for a given source.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] irq_level_pos Bit position of the FIFO to set
+ * \ref smsc9220_fifo_level_irq_pos_t
+ * \param[in] level Level of the FIFO, when the FIFO used space is greater
+ * than this value, corresponding interrupt will be generated.
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_set_fifo_level_irq(
+ const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_fifo_level_irq_pos_t irq_level_pos,
+ uint32_t level);
+
+/**
+ * \brief Waits for EEPROM to be ready to use.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_wait_eeprom(
+ const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Initializes irqs by clearing and disabling all interrupt sources
+ * and enable interrupts. Since all interrupt sources are disabled,
+ * interrupt won't be triggered, until interrupt sources won't be
+ * enabled by \ref smsc9220_enable_interrupt
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_init_irqs(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Checks PHY ID registers.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_check_phy(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Resets PHY.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_reset_phy(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Advertises all speeds and pauses capabilities.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_advertise_cap(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Enables transmission.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_enable_xmit(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Disables transmission.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_disable_xmit(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Enables MAC Transmitter.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_enable_mac_xmit(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Disables MAC Transmitter.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_disable_mac_xmit(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Enables receiving.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_enable_mac_recv(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Disables receiving.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_disable_mac_recv(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Enables the given interrupt source.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] source Enum of the interrupt source.
+ */
+void smsc9220_enable_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source);
+
+/**
+ * \brief Disables the given interrupt source.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] source Enum of the interrupt source.
+ */
+void smsc9220_disable_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source);
+
+/**
+ * \brief Disables all interrupt sources.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_disable_all_interrupts(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Clears the given interrupt source.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] source Enum of the interrupt source.
+ */
+void smsc9220_clear_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source);
+
+/**
+ * \brief Clears all interrupt sources.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_clear_all_interrupts(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Gets the status of the given interrupt source.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] source Enum of the interrupt source.
+ *
+ * \return non-zero if the given interrupt source is triggered, zero otherwise
+ */
+int smsc9220_get_interrupt(const struct smsc9220_eth_dev_t* dev,
+ enum smsc9220_interrupt_source source);
+
+/**
+ * \brief Establishes link
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ */
+void smsc9220_establish_link(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Reads the Ethernet Controller's MAC address from its EEPROM.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in,out] mac array will include the read MAC address in
+ * 6 bytes hexadecimal format.
+ * It should be allocated by the caller to 6 bytes.
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_read_mac_address(
+ const struct smsc9220_eth_dev_t* dev, char *mac);
+
+/**
+ * \brief Check device ID.
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+int smsc9220_check_id(const struct smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Gets the data size of the Tx buffer, aka Maximum Trasmission Unit
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return Fifo data size in bytes
+ */
+uint32_t smsc9220_get_tx_data_fifo_size(const struct
+ smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Sends data from the given buffer as an Ethernet packet.
+ * The full packet length must be specified at the beginning
+ * of a new packet transmission.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in] total_payload_length Length of the ethernet payload.
+ * Should be equal to the sum of passed buffers within a packet.
+ * \param[in] is_new_packet Should be set to true if the input buffer has to
+ * be sent as the start of a new packet or as a full packet.
+ * \param[in] data Pointer to the data buffer to be sent.
+ * \param[in] current_size Size of the data in bytes.
+ *
+ * \return error code /ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_send_by_chunks(
+ const struct smsc9220_eth_dev_t* dev,
+ uint32_t total_payload_length,
+ bool is_new_packet,
+ const char *data, uint32_t current_size);
+
+/**
+ * \brief Reads an incoming Ethernet packet into the given buffer.
+ * Stops reading at packet border.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ * \param[in,out] data Pointer to a pre-allocated input buffer.
+ * Allocating sufficient memory space is the caller's
+ * responsibility, which is typically done by calling
+ * \ref smsc9220_peek_next_packet_size.
+ * \param[in] dlen Length of the allocated data in bytes, which equals to
+ * the length of the packet that can be read by calling
+ * \ref smsc9220_peek_next_packet_size.
+ *
+ * \return error code \ref smsc9220_error_t
+ */
+enum smsc9220_error_t smsc9220_get_received_packet(
+ const struct smsc9220_eth_dev_t* dev,
+ char *data, uint32_t dlen);
+
+/**
+ * \brief Get the number of packets that haven't been read out yet.
+ * Note: The function indicates the amount of queued rx status in
+ * the rx status fifo. The number of queued rx status is equal
+ * to the queued rx packets in the data fifo.
+ *
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return Count of the incoming packets that can be read out.
+ */
+uint32_t smsc9220_get_received_packet_count(const struct
+ smsc9220_eth_dev_t* dev);
+
+/**
+ * \brief Gets the size of next unread packet in Rx buffer, using the peak
+ * register, which is not destructive so can be read asynchronously.
+ * Warning: In case of heavy receiving loads, this register may not
+ * be in perfect sync.
+ *
+ * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t
+ *
+ * \return Size of the next packet in bytes, read from the Rx Peek register.
+ */
+uint32_t smsc9220_peek_next_packet_size(const struct
+ smsc9220_eth_dev_t* dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SMSC9220_ETH_H__ */
diff --git a/examples/vad_an552/readme.rst b/examples/vad_an552/readme.rst
new file mode 100644
index 0000000..0decd26
--- /dev/null
+++ b/examples/vad_an552/readme.rst
@@ -0,0 +1,269 @@
+#########################################
+Voice Activity Detection demo application
+#########################################
+
+A demo application for the AN552 FPGA showcasing:
+
+* secure partition using MVE to speed up algorithms
+* secure peripheral usage from secure partition with interrupt handling
+* AWS cloud connectivity with OTA on the non-secure side
+
+---------------
+Brief Operation
+---------------
+
+After boot-up the application first checks whether Over-the-Air update (OTA)
+was initiated from AWS cloud. If yes, the OTA process is executed, otherwise
+the voice activity detection algorithm is started on the secure side. While the
+algorithm is running the non-secure side keep polling it for results. After a
+minute the algorithm is stopped, and the operation restarted with the OTA check
+again.
+
+If the algorithm detects voice, a short audio sample (~100 ms) is recorded, and
+the highest energy frequency component is calculated. This frequency is written
+onto the serial line and it is sent to AWS cloud. Then the algorithm is
+restarted or the OTA check is started if the timeout is up.
+
+By default the solution requires ethernet connectivity, it will not start the
+main operation until the network is up. This can be overwritten if the
+``-DVAD_AN552_NO_CONNECTIVITY=ON`` cmake flag is defined. The effect is:
+
+* No need for Ethernet connection.
+* No need for IoT thing creation in AWS cloud and source update with
+ its credentials.
+* OTA check and AWS cloud communication is not executed.
+
+---------------
+HW requirements
+---------------
+
+* AN552 Version 2.0 FPGA image on MPS3 board.
+* Ethernet connection with access to the internet. (Not needed if
+ ``-DVAD_AN552_NO_CONNECTIVITY=ON`` is added for cmake.)
+* 2 or 3 pole microphone connected into the audio connector. In case of a
+ stereo microphone only the right channel is used.
+
+------------------
+Build instructions
+------------------
+
+*********************************************************
+AWS thing creation and source update with the credentials
+*********************************************************
+
+By default it is required to create an IoT thing in AWS to run the application,
+but this can be skipped if ``-DVAD_AN552_NO_CONNECTIVITY=ON`` is added for
+cmake.
+
+###################################
+Create an IoT thing for your device
+###################################
+
+#. Login to your account and browse to the `AWS IoT console <https://console.aws.amazon.com/iotv2/>`__.
+#. In the left navigation pane, choose ``All devices``, and then choose ``Things``.
+#. Click on ``Create things``.
+#. Choose ``Create single thing``.
+#. At the ``Specify thing properties`` page add the name of your thing at
+ ``Thing name``. You will need to add the name later to your C code. Click
+ ``Next``.
+#. At the ``Configure device certificate`` page choose ``Auto-generate a new
+ certificate``, and click ``Next``.
+#. The thing can be created by clicking on ``Create thing`` at the
+ ``Attach policies to certificate`` page. The policy will be created at the
+ next section.
+#. Download the key files and the certificate, and make a note of the name of
+ the certificate.
+#. Activate your certificate if it is not active by default.
+
+###############
+Create a policy
+###############
+
+For the sake of simplicity in this example a very permissive Policy is created,
+for production usage a more restrictive one is recommended.
+
+#. In the navigation pane of the AWS IoT console, choose ``Security``, and then
+ choose ``Policies``.
+#. At the ``Policies`` page, choose ``Create policy``.
+#. At the ``Create a policy`` page, enter a name for the policy.
+#. At the Policy document click on JSON, and paste the following snippet into the
+ Policy document textbox, then click on ``Create``. (``Region`` and
+ ``Account ID`` must be updated.)
+
+.. code-block:: JSON
+
+ {
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Effect": "Allow",
+ "Action": [
+ "iot:Connect",
+ "iot:Publish",
+ "iot:Subscribe",
+ "iot:Receive"
+ ],
+ "Resource": "arn:aws:iot:<Region>:<Account ID without dashes>:*"
+ }
+ ]
+ }
+
+#######################################
+Attach the created policy to your thing
+#######################################
+
+#. In the left navigation pane of the AWS IoT console, choose ``Secure``, and
+ then choose ``Certificates``. You should see the certificate that you have
+ created earlier.
+#. Click on the three dots next to the certificate and choose
+ ``Attach policy``.
+#. In the ``Attach policies to certificate(s)`` window choose the created
+ policy and click ``Attach``.
+
+####################################
+Update source with thing credentials
+####################################
+
+Edit `examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential.h` file and
+set the value of the following macros:
+
+* `clientcredentialMQTT_BROKER_ENDPOINT`, set this to the endpoint name of your
+ amazon account. To find this go to the AWS IoT console page and in the left
+ navigation pane click on ``Settings``. The Endpoint can be found under
+ ``Device data endpoint``.
+
+* `clientcredentialIOT_THING_NAME`, set this to the name of the created thing.
+
+Recreate or update examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential_keys.h`
+with the downloaded certificate and keys.
+
+Recreate with the html tool from Amazon-FreeRTOS:
+
+#. Clone `Amazon-FreeRTOS <https://github.com/aws/amazon-freertos>`__.
+#. Open ``Amazon-FreeRTOS/tools/certificate_configuration/CertificateConfigurator.html``
+ in your browser.
+#. Upload the downloaded certificate and the private key.
+#. Click on ``Generate and save aws_clientcredential_keys.h``
+#. Download the file and update `examples/vad_an552/ns_side/amazon-freertos/aws_clientcredential_keys.h`
+ with it.
+
+Alternatively, the file can be updated by hand by setting the values of the
+following macros:
+
+* ``keyCLIENT_CERTIFICATE_PEM``, content of ``<your-thing-certificate-unique-string>-certificate.pem.crt``.
+* ``keyCLIENT_PRIVATE_KEY_PEM``, content of ``<your-thing-certificate-unique-string>-private.pem.key``.
+* ``keyCLIENT_PUBLIC_KEY_PEM``, content of ``<your-thing-certificate-unique-string>-public.pem.key``.
+
+##################
+Running TF-M build
+##################
+
+For building TF-M's build system is used with the following mandatory CMAKE
+flags::
+
+ -DTFM_PLATFORM=arm/mps3/an552
+ -DNS_EVALUATION_APP_PATH=<path-to-tf-m-extras-repo>/examples/vad_an552/ns_side
+ -DTFM_EXTRA_PARTITION_PATHS=<path-to-tf-m-extras-repo>/partitions/vad_an552_sp/
+ -DTFM_EXTRA_MANIFEST_LIST_FILES=<path-to-tf-m-extras-repo>/partitions/vad_an552_sp/extra_manifest_list.yaml
+ -DCRYPTO_ENGINE_BUF_SIZE=0x8000 -DITS_MAX_ASSET_SIZE=1300
+ -DTFM_PARTITION_FIRMWARE_UPDATE=ON -DMCUBOOT_DATA_SHARING=ON
+ -DMCUBOOT_UPGRADE_STRATEGY=SWAP_USING_SCRATCH
+ -DMCUBOOT_IMAGE_NUMBER=1 -DMCUBOOT_SIGNATURE_KEY_LEN=2048
+ -DCONFIG_TFM_ENABLE_MVE=ON
+
+The application also can be run without MVE support, in that case the
+``-DCONFIG_TFM_ENABLE_MVE=ON`` flags should be omitted, and the
+``configENABLE_MVE`` can be set to ``0`` in the
+``ns_side/amazon-freertos/FreeRTOSConfig.h`` file.
+Our measurements showed that MVE speeds up the frequency calculation by 10
+times with release GCC build.
+
+You can check TF-M's build instructions
+`here <https://tf-m-user-guide.trustedfirmware.org/docs/technical_references/instructions/tfm_build_instruction.html>`__.
+
+-----------------------
+Running the application
+-----------------------
+
+It is covered by the generic TF-M run instructions for AN552
+`here <https://tf-m-user-guide.trustedfirmware.org/platform/ext/target/arm/mps3/an552/README.html>`__.
+
+---------------------------
+Testing the voice algorithm
+---------------------------
+
+Start up the board, wait until ``==== Start listening ====`` is written on the
+serial console and start talking, or make some noise. You can check that the
+``Voice detected with most energy at X Hz`` message is written onto the serial
+console, and the same message is sent to AWS cloud.
+
+For checking the AWS messages:
+
+#. In the left navigation pane of the AWS IoT console, choose ``Test``.
+#. Define ``<Name of your thing>/vad_an552`` as the topic filter.
+#. Click on ``Subscribe``.
+#. Once a message is sent to AWS cloud you should see it on this page.
+
+.. note::
+
+ For this test it is recommended to find a quiet environment, because any
+ noise can trigger the voice activity algorithm.
+
+For testing the frequency calculation pure sine signals should be used,
+the accuracy is about +/- 100 Hz.
+
+----------------------
+Testing Amazon AWS OTA
+----------------------
+
+To run an OTA update a new image must be created with higher version number.
+This can be easily done by rebuilding the solution with the following cmake
+flag: -DMCUBOOT_IMAGE_VERSION_S=2.1.0. (The version itself can be anything, but
+must be higher than the version of the currently running image.)
+
+The image signature must be extracted from the final binary, can be done by
+openssl running the following commands in the build directory:
+
+#. ``openssl dgst -sha256 -binary -out update-digest.bin tfm_s_ns_signed.bin``
+#. ``openssl pkeyutl -sign -pkeyopt digest:sha256 -pkeyopt rsa_padding_mode:pss -pkeyopt rsa_mgf1_md:sha256 -inkey <path to tfm source>/bl2/ext/mcuboot/root-RSA-2048.pem -in update-digest.bin -out update-signature.bin``
+#. ``openssl base64 -A -in update-signature.bin -out update-signature.txt``
+
+Once the signature extracted into ``update-signature.txt`` file, the OTA job
+can be created:
+
+#. `Create an Amazon S3 bucket to store your update <https://docs.aws.amazon.com/freertos/latest/userguide/dg-ota-bucket.html>`__.
+#. `Create an OTA Update service role <https://docs.aws.amazon.com/freertos/latest/userguide/create-service-role.html>`__.
+#. `Create an OTA user policy <https://docs.aws.amazon.com/freertos/latest/userguide/create-ota-user-policy.html>`__.
+#. Go to AWS IoT web interface and choose ``Manage`` and then ``Jobs``.
+#. Click the create job button and select ``Create FreeRTOS OTA update job``.
+#. Give it a name and click next.
+#. Select the device to update (the Thing you created in earlier steps).
+#. Select ``MQTT`` transport only.
+#. Select ``Use my custom signed file``.
+#. Paste the signature string from the ``update-signature.txt`` file. Make sure
+ that it is pasted as it is without any whitespace characters.
+#. Select ``SHA-256`` and ``RSA`` algorithms.
+#. For ``Path name of code signing certificate on device`` put in ``0``
+ (the path is not used).
+#. Select upload new file and select the signed update binary
+ ``tfm_s_ns_signed.bin``.
+#. Select the S3 bucket you created to upload the binary to.
+#. For ``Path name of file on device`` put in ``full image``.
+#. As the role, select the OTA role you created.
+#. Click next.
+#. Click next, your update job is ready and running. If your board is running
+ (or the next time it will be turned on) the update will be performed.
+
+After the update happened the system resets, and the image version is written
+onto the serial console. That way the update can be verified.
+
+.. note::
+
+ The OTA process only updates the image stored in RAM, so if the MPS3 board
+ is power cycled the system will boot up with the original image. The FPGA at
+ power-on loads the application image from the SD card to RAM, and the SD
+ card content is not changed during OTA.
+
+-------------
+
+*Copyright (c) 2021-2022, Arm Limited. All rights reserved.*