### STM32CubeMX Installation and Setup Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Projects/STM32N6570-DK/Applications/USBX/Ux_Host_DualClass/readme.html Instructions for downloading, installing, and setting up STM32CubeMX. This includes obtaining the necessary software and dependencies for development. ```plaintext Download STM32CubeMX from the official STMicroelectronics website. Install the software by following the on-screen instructions. Ensure you have a Java Runtime Environment (JRE) installed, as STM32CubeMX requires it. ``` -------------------------------- ### Install vcpkg and Paho MQTT Client Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_linux.md Installs the vcpkg package manager and the Eclipse Paho MQTT C client. This process involves cloning the vcpkg repository, checking out a specific commit, bootstrapping vcpkg, and then installing curl, cmocka, and paho-mqtt using vcpkg. ```bash cd ~ sudo git clone https://github.com/Microsoft/vcpkg.git cd vcpkg # Checkout the vcpkg commit per vcpkg-commit.txt above. sudo ./bootstrap-vcpkg.sh sudo ./vcpkg install --triplet x64-linux curl cmocka paho-mqtt cd .. ``` -------------------------------- ### Key Derivation Driver Setup and Abort Functions (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/Third_Party/mbedtls/docs/proposed/psa-driver-interface.md Demonstrates the mandatory 'key_derivation_setup' and 'key_derivation_abort' entry points. 'key_derivation_setup' is the initial call, providing necessary inputs. 'key_derivation_abort' is the final call to clean up resources. This example assumes a driver with the prefix 'acme'. ```c typedef ... acme_key_derivation_operation_t; psa_status_t acme_key_derivation_abort(acme_key_derivation_operation_t *operation); ``` -------------------------------- ### Install Build Tools and Dependencies on Debian/Ubuntu Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_linux.md Installs essential build tools and libraries required for compiling the Azure SDK for Embedded C samples on Debian/Ubuntu-based Linux systems. This includes build-essential, curl, unzip, tar, pkg-config, git, and OpenSSL development packages. ```bash sudo apt-get update sudo apt-get install build-essential curl unzip tar pkg-config git openssl libssl-dev ``` -------------------------------- ### ThreadX Initialization and Thread Creation Example (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Projects/STM32N6570-DK/Applications/USBX/Ux_Device_Video/readme.html This C code snippet outlines the initial setup within ThreadX for the USB Device Video application. It shows the `tx_application_define()` function where USBX resources are initialized, the video class driver is registered, and the application's main thread (`app_ux_device_thread_entry`) is created. ```c // Inside tx_application_define() { // Initialize USBX resources // Register video class driver // Create the application thread tx_thread_create(&app_ux_device_thread_entry, "USB Device Video Thread", app_ux_device_thread_entry_function, 0, (void *)app_ux_device_thread_stack, STACK_SIZE, 10, 10, TX_AUTO_START); } ``` -------------------------------- ### Install CMake on Ubuntu 16.04 Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_linux.md Installs CMake version 3.18.3 on Ubuntu 16.04 systems by downloading the binary distribution, making it executable, and installing it to the /usr/local directory. This is an alternative to using apt-get for older Ubuntu versions. ```bash wget https://cmake.org/files/v3.18/cmake-3.18.3-Linux-x86_64.sh sudo chmod 777 cmake-3.18.3-Linux-x86_64.sh sudo ./cmake-3.18.3-Linux-x86_64.sh --prefix=/usr # When prompted to include the default subdirectory, enter 'n'. ``` -------------------------------- ### Example XML Parameter Configuration Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Utilities/PC_Software/ROT_AppliConfig/README.md Provides an example of a fully configured parameter entry in an XML file for the AppliCfg tool. This specific example configures 'Header Size' with various attributes. ```xml Header Size Data -H 1 1 0x400 ``` -------------------------------- ### Post-build Command for IAR Project (Single Image) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Utilities/PC_Software/ROT_AppliConfig/README.md Example of a post-build command configuration for an IAR project when using a single-image setup. This specific configuration invokes the STM32TrustedPackageCreator_CLI.exe tool with an XML file for package building. ```XML BUILDACTION 1 "STM32TrustedPackageCreator_CLI.exe" -pb "OEMiRoT_S_Code_Image.xml" ``` -------------------------------- ### Install AppliCfg Tool Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Utilities/PC_Software/ROT_AppliConfig/README.md Installs the AppliCfg tool and its Python module dependencies. Requires Python 3.11.2 or newer. Executes the setup.py script to manage installations. ```bash python setup.py install ``` -------------------------------- ### Build CMSIS-DSP Examples with cbuild Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/dsppp_building.html Commands to build CMSIS-DSP examples. The first-time build includes updating the RTE, while subsequent builds omit this step. Requires the cbuild toolchain and a specified toolchain/configuration. ```shell cbuild -O cprj test.csolution.yml --toolchain AC6 -c example.Release+VHT-Corstone-300 -p -r --update-rte cbuild -O cprj test.csolution.yml --toolchain AC6 -c example.Release+VHT-Corstone-300 ``` -------------------------------- ### Install Executables and Programs Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/Third_Party/mbedtls/programs/psa/CMakeLists.txt Defines installation rules for the project. It installs the defined executables to the 'bin' directory with specific permissions and installs shell scripts to the 'bin' directory as well. ```cmake install(TARGETS ${executables} DESTINATION "bin" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) install(PROGRAMS key_ladder_demo.sh DESTINATION "bin") ``` -------------------------------- ### Run CMSIS-DSP Example on FVP Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/dsppp_building.html Command to run a compiled CMSIS-DSP example on the FVP_Corstone_SSE-300_Ethos-U55 simulator. This command specifies the FVP executable, configuration file, and the path to the compiled application's executable. ```shell FVP_Corstone_SSE-300_Ethos-U55.exe -f fvp_configs/VHT-Corstone-300.txt -a cpu0=cprj\out\example\VHT-Corstone-300\Release\example.axf ``` -------------------------------- ### Start Sequence for Peripheral Power Management (SPI Example) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Driver/theoryOperation.html This example shows how to initialize and start a peripheral (SPI1) using its driver. It involves calling Initialize, then PowerControl with ARM_POWER_FULL to enable the peripheral for operation, followed by similar steps for another peripheral (USART1). ```c SPI1drv->Initialize(...); SPI1drv->PowerControl(ARM_POWER_FULL); USART1drv->Initialize(...); USART1drv->PowerControl(ARM_POWER_FULL); ``` -------------------------------- ### CMakeLists.txt: Basic Project Setup and Source File Definition Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/test/cmake/netxduo/samples/CMakeLists.txt This snippet sets up the basic CMake project, defines the source directory for samples, and lists the core NetX Duo demo files. It uses `cmake_minimum_required` and `project` commands, and `set` to define variables for source directories and files. The `SOURCE_DIR` variable points to the common sample directory, while `sample_files` enumerates various network protocol demos. ```cmake cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) cmake_policy(SET CMP0057 NEW) project(samples LANGUAGES C) set(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../samples) set(sample_files ${SOURCE_DIR}/demo_netxduo_dns.c ${SOURCE_DIR}/demo_netxduo_ftp.c ${SOURCE_DIR}/demo_netxduo_http.c ${SOURCE_DIR}/demo_netxduo_snmp.c ${SOURCE_DIR}/demo_netxduo_sntp_client.c ${SOURCE_DIR}/demo_netxduo_telnet.c ${SOURCE_DIR}/demo_netxduo_tftp.c ${SOURCE_DIR}/demo_netx_duo_tcp.c ${SOURCE_DIR}/demo_netx_duo_udp.c) ``` -------------------------------- ### Set vcpkg Environment Variables Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_linux.md Sets the necessary environment variables for vcpkg to function correctly. VCPKG_DEFAULT_TRIPLET is set to 'x64-linux' and VCPKG_ROOT points to the vcpkg installation directory. These variables must be reset every time a new terminal session is started. ```bash export VCPKG_DEFAULT_TRIPLET=x64-linux export VCPKG_ROOT=~/vcpkg ``` -------------------------------- ### Get Stride (C++) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/group__Matrix.html Returns the stride of the matrix. The stride indicates the number of elements between the start of one row and the start of the next. This is a const inline function. ```cpp uint32_t stride( ) const inline ``` -------------------------------- ### SystemInit Function Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core/startup_c_pg.html Initializes the system, including necessary configurations for TrustZone and stack sealing. ```APIDOC ## SystemInit Function ### Description Initializes the system, which may include setting up clock trees, memory, and other core system functionalities. This function is crucial for the proper operation of the microcontroller. ### Method N/A (This is a function call, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c // This function is typically called automatically by the startup code. // You usually don't call it directly unless for specific testing purposes. SystemInit(); ``` ### Response #### Success Response N/A (This is a void function) #### Response Example N/A ### Notes - Stack Sealing requires the application project to use a scatter file or a linker script, as explained in the [Stack Sealing](using_TrustZone_pg.html#RTOS_TrustZone_stacksealing) section. ``` -------------------------------- ### Get Stride - C++ Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/group__Matrix.html The `stride()` function returns the number of elements between the start of one row and the start of the next. It's declared as `constexpr` and `inline` for compile-time evaluation and performance. ```cpp /** * @brief Number of stride. * @return Number of stride */ constexpr uint32_t stride() const inline constexpr; ``` -------------------------------- ### Example: Get Host IP Address Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Driver/group__wifi__socket__gr.html An example demonstrating how to use ARM_WIFI_SocketGetHostByName to resolve a host name to an IPv4 address. It initializes the WiFi driver and calls the function with necessary parameters. ```c extern ARM_DRIVER_WIFI Driver_WiFi0; static ARM_DRIVER_WIFI *wifi; void ping_arm_com (void) { uint8_t ip[4]; uint32_t ip_len; int32_t res; wifi = &Driver_WiFi0; ip_len = sizeof(ip); res = wifi->GetHostByName("example.com", ARM_SOCKET_AF_INET, ip, &ip_len); // ... handle result ... } ``` -------------------------------- ### Build Demonstration Application using GNU Make Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/threadx/ports/linux/gnu/readme_threadx.txt Builds the ThreadX demonstration application ('sample_threadx.c') and links it with the pre-compiled ThreadX library ('tx.a') to create an executable binary named 'DEMO'. This command should be executed from the 'example_build' directory. ```makefile make sample_threadx ``` -------------------------------- ### Start Azure IoT ADU Agent (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/docs/azure_rtos_iot_adu_agent.md Initializes and starts the Azure IoT ADU agent. It requires pointers to the agent, IoT hub client, device properties (manufacturer, model), installed criteria, and callback functions for update notifications and driver operations. The agent can internally check installed criteria or delegate this to a provided driver. ```c UINT nx_azure_iot_adu_agent_start(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, NX_AZURE_IOT_HUB_CLIENT *iothub_client_ptr, const UCHAR *manufacturer, UINT manufacturer_length, const UCHAR *model, UINT model_length, const UCHAR *installed_criteria, UINT installed_criteria_length, VOID (*adu_agent_update_notify)(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, UCHAR *provider, UINT provider_length, UCHAR *name, UINT name_length, UCHAR *version, UINT version_length), VOID (*adu_agent_driver)(NX_AZURE_IOT_ADU_AGENT_DRIVER *)); ``` -------------------------------- ### Install vcpkg and MQTT Client (Windows) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/README.md Clones the vcpkg repository, checks out a specific commit, bootstraps it, and then installs the curl, cmocka, and paho-mqtt libraries for Windows x64-static. This is crucial for managing C/C++ dependencies on Windows. ```powershell git clone https://github.com/Microsoft/vcpkg.git cd vcpkg git checkout # Checkout the vcpkg commit per vcpkg-commit.txt above. .\bootstrap-vcpkg.bat .\vcpkg.exe install --triplet x64-windows-static curl[winssl] cmocka paho-mqtt # Update triplet per your system. ``` -------------------------------- ### Build ThreadX Demonstration System with IAR Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/threadx/ports/cortex_m0/iar/readme_threadx.txt Steps to build the ThreadX demonstration application (sample_threadx.out) for the IAR Cortex-M0 simulator. This requires making the sample_threadx.ewp project active and building it. ```text 1. Make the sample_threadx.ewp project the "active project" in the IAR Embedded Workbench. 2. Select the "Make" button to compile sample_threadx.c and link with tx.a. 3. The output is sample_threadx.out, a binary file executable on the IAR Cortex-M0 simulator. ``` -------------------------------- ### Start or Restart a Timer using osTimerStart (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/RTOS2/group__CMSIS__RTOS__TimerMgmt.html This example shows how to start or restart a timer with a specified delay using the osTimerStart function. It includes creating a periodic timer, setting the delay in ticks, and checking the status of the start operation. The osTimerStart function cannot be called from interrupt service routines. ```c #include "cmsis_os2.h" void Timer_Callback (void *arg) { // timer callback function // arg contains &exec // called every second after osTimerStart } uint32_t exec; // argument for the timer call back function void TimerStart_example (void) { osTimerId_t id; // timer id uint32_t timerDelay; // timer value osStatus_t status; // function return status // Create periodic timer exec = 1U; id = osTimerNew(Timer_Callback, osTimerPeriodic, &exec, NULL); if (id != NULL) { timerDelay = 1000U; status = osTimerStart(id, timerDelay); // start timer if (status != osOK) { // Timer could not be started } } ; } ``` -------------------------------- ### Construct Package URL Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/eng/docs/api/assets/header.html Generates the full URL for a specific language, package, and version of the documentation. This URL points to the 'index.html' file within the specified documentation path. ```javascript function getPackageUrl(language, package, version) { return ( "https://azuresdkdocs.blob.core.windows.net/$web/" + language + "/" + package + "/" + version + "/index.html" ); } ``` -------------------------------- ### Install Build Tools (Linux) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/README.md Installs essential build tools for Linux systems, including a compiler, curl, zip, unzip, tar, and pkg-config. These are fundamental for compiling C/C++ projects. ```bash sudo apt-get update sudo apt-get install build-essential curl zip unzip tar pkg-config ``` -------------------------------- ### Build ThreadX Demonstration System with GNU Tools (Batch) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/threadx/ports/cortex_m0/gnu/readme_threadx.txt This batch script compiles the ThreadX demonstration application 'sample_threadx.c' and links it with the pre-built ThreadX runtime library 'tx.a'. It's designed to run from the 'example_build' directory. The output is an executable binary 'sample_threadx.out' suitable for simulators or hardware. ```batch call build_threadx_sample.bat ``` -------------------------------- ### WiFi Module Initialization and Power Control Example Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Driver/group__wifi__control__gr.html This C code example demonstrates the initialization and power control of a WiFi module using the ARM_DRIVER_WIFI interface. It shows how to get a driver instance, initialize the module, set it to full power, and then retrieve module information. ```c extern \tARM_DRIVER_WIFI\tDriver_WiFi0; static \tARM_DRIVER_WIFI\t*wifi; void initialize_wifi (void) { \tchar info[32]; \twifi = &Driver_WiFi0; \t// Initialize and Power-on WiFi Module \twifi->Initialize(NULL); \twifi->PowerControl(ARM_POWER_FULL); \t// Retrieve module information \twifi->GetModuleInfo(info, 32); } ``` -------------------------------- ### CMSIS-DSP Convolution Example (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/arm_convolution_example_f32_8c-example.html Demonstrates floating-point convolution using the CMSIS-DSP library. It includes setup for input buffers, test data, and defines related to block size and precision. This example is suitable for Cortex-M4/Cortex-M3 processors and requires the 'arm_math.h' and 'math_helper.h' headers. ```c #include "arm_math.h" #include "math_helper.h" #if defined(SEMIHOSTING) #include #endif /* Defines each of the tests performed */ #define MAX_BLOCKSIZE 128 #define DELTA (0.000001f) #define SNR_THRESHOLD 90 /* Declare I/O buffers */ float32_t Ak[MAX_BLOCKSIZE]; /* Input A */ float32_t Bk[MAX_BLOCKSIZE]; /* Input B */ float32_t AxB[MAX_BLOCKSIZE * 2]; /* Output */ /* Test input data for Floating point Convolution example for 32-blockSize */ /* Generated by the MATLAB randn() function */ float32_t testInputA_f32[64] = { -0.808920, 1.357369, 1.180861, -0.504544, 1.762637, -0.703285, 1.696966, 0.620571, -0.151093, -0.100235, -0.872382, -0.403579, -0.860749, -0.382648, -1.052338, 0.128113, -0.646269, 1.093377, -2.209198, 0.471706, 0.408901, 1.266242, 0.598252, 1.176827, -0.203421, 0.213596, -0.851964, -0.466958, 0.021841, -0.698938, -0.604107, 0.461778, -0.318219, 0.942520, 0.577585, 0.417619, ``` -------------------------------- ### Install vcpkg and MQTT Client (Linux) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/README.md Clones the vcpkg repository, checks out a specific commit, bootstraps it, and then installs the curl, cmocka, and paho-mqtt libraries for Linux x64. This is crucial for managing C/C++ dependencies. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg git checkout # Checkout the vcpkg commit per vcpkg-commit.txt above. ./bootstrap-vcpkg.sh ./vcpkg install --triplet x64-linux curl cmocka paho-mqtt ``` -------------------------------- ### TLS Session Start Tests Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/test/cmake/nx_secure/regression/CMakeLists.txt Tests for initiating and establishing new TLS sessions, covering the handshake process and initial secure communication setup. ```c #include "nx_secure_tls_session_start_test.c" ``` -------------------------------- ### Context Object Memory Movement Example Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/Third_Party/mbedtls/docs/architecture/alternative-implementations.md Demonstrates the necessity of context objects being movable in memory, illustrating a typical sequence of initialization, setup, assignment, zeroing, and usage. This ensures compatibility with stack-based contexts and garbage collection. ```c mbedtls_xxx_context ctx1, ctx2; mbedtls_xxx_init(&ctx1); mbedtls_xxx_setup(&ctx1, …); ctx2 = ctx1; memset(&ctx1, 0, sizeof(ctx1)); mbedtls_xxx_do_stuff(&ctx2, …); mbedtls_xxx_free(&ctx2); ``` -------------------------------- ### Example Usage of the iofile Tool Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Utilities/PC_Software/ROT_AppliConfig/README.md Demonstrates a practical example of using the 'iofile' tool with specific arguments for processing secure data images. This includes input file paths, macro symbols, and XML configuration. ```bash iofile --layout image_macros_preprocessed_bl2.c -mi RE_APP_IMAGE_NUMBER -me RE_ENCRYPTION --xml OEMiRoT_NonSecure_Code.xml -in "Firmware binary input file" -i ../../ROT_Appli_TrustZone/Binary/rot_app.bin -on "Image output file" -en "Encryption key" -b ns_code_image ob_flash_programming.bat ``` -------------------------------- ### Set RTC Time and Date Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Projects/NUCLEO-N657X0-Q/Examples/RTC/RTC_TimeStamp/README.md Sets the initial time and date for the Real-Time Clock. These functions are used to synchronize the RTC to a specific starting point. They take RTC time and date structures as arguments. ```c HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN); HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN); ``` -------------------------------- ### ThreadX Application Definition and Thread Creation (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Projects/STM32N6570-DK/Applications/USBX/Ux_Host_Audio_2.0/readme.html Defines the main entry point for the ThreadX application and sets up USBX resources. It creates two essential threads: one for USB OTG HAL HCD driver initialization and Host startup, and another for audio playback after device enumeration. ```c UINT tx_application_define(void *first_unused_memory) { /* Initialize USBX */ UINT status = ux_system_initialize(first_unused_memory); if (status != UX_SUCCESS) { return status; } /* Register AUDIO Class driver */ status = ux_host_class_audio_init(); if (status != UX_SUCCESS) { return status; } /* Create USBX application thread */ tx_thread_create(&usbx_app_thread, "USBX App Thread", usbx_app_thread_entry, 0, NULL, 0, TX_AUTO_START, TX_THREAD_ID_USB_APP, TX_NO_TIME_SLICE, TX_NO_PREEMPTION); /* Create Audio playback thread */ tx_thread_create(&audio_playback_thread, "Audio Playback Thread", audio_playback_thread_entry, 0, NULL, 0, TX_AUTO_START, TX_THREAD_ID_AUDIO_PLAYBACK, TX_NO_TIME_SLICE, TX_NO_PREEMPTION); return TX_SUCCESS; } ``` -------------------------------- ### Navigation Tree and Resizable Panel Setup (JavaScript) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core_A/globals_defs_g.html Initializes the navigation tree and sets up a resizable panel for the documentation interface. This function is called when the document is ready and the DOM has loaded. ```javascript $(document).ready(function(){initNavTree('globals_defs_g.html',''); initResizable(); }); ``` -------------------------------- ### CMSIS-DSP Least Square Fit Example (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/arm_matrix_example_f32_8c-example.html Demonstrates how to perform a least square fit to data using matrix functions from the CMSIS-DSP library. This example is intended for Cortex-M4/M3 processors and utilizes float32_t data types for calculations. It includes setup for input data (B_f32) and matrix coefficients (A_f32), along with temporary buffers for intermediate results like the transpose (AT_f32) and the product of the transpose with itself (ATMA_f32). ```c #include "arm_math.h" #include "math_helper.h" #if defined(SEMIHOSTING) #include #endif #define SNR_THRESHOLD 77 const float32_t B_f32[4] = { 782.0, 7577.0, 470.0, 4505.0 }; const float32_t A_f32[16] = { /* Const, numTaps, blockSize, numTaps*blockSize */ 1.0, 32.0, 4.0, 128.0, 1.0, 32.0, 64.0, 2048.0, 1.0, 16.0, 4.0, 64.0, 1.0, 16.0, 64.0, 1024.0, }; float32_t AT_f32[16]; float32_t ATMA_f32[16]; ``` -------------------------------- ### Project Setup and Options (CMake) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/CMakeLists.txt Initializes the CMake project for NetX Duo, setting the minimum version and project name. It defines build options like enabling FileX server support and Azure IoT integration, along with essential checks for ThreadX architecture and toolchain definitions. ```cmake cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) # Set up the project project(netxduo LANGUAGES C ASM ) option(NXD_ENABLE_FILE_SERVERS "Includes a dependency on FileX to support 'server' protocol handlers" ON) option(NXD_ENABLE_AZURE_IOT "Enable Azure IoT" OFF) if(NOT DEFINED THREADX_ARCH) message(FATAL_ERROR "Error: THREADX_ARCH not defined") endif() if(NOT DEFINED THREADX_TOOLCHAIN) message(FATAL_ERROR "Error: THREADX_TOOLCHAIN not defined") endif() ``` -------------------------------- ### Get RTOS Kernel Tick Count (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/RTOS2/group__CMSIS__RTOS__KernelCtrl.html This code example shows how to retrieve the current RTOS kernel tick count using osKernelGetTickCount. It's used to schedule periodic tasks, for instance, delaying a thread by 1000 ticks. The function can be called from interrupt service routines. It also includes an example of implementing a 64-bit tick counter to handle potential overflows of the 32-bit tick count. ```c #include "cmsis_os2.h" void Thread_1 (void *arg) { // Thread function uint32_t tick; tick = osKernelGetTickCount(); // retrieve the number of system ticks for (;;) { tick += 1000; // delay 1000 ticks periodically osDelayUntil(tick); // ... } } uint64_t GetTick(void) { static uint32_t tick_h = 0U; static uint32_t tick_l = 0U; uint32_t tick; tick = osKernelGetTickCount(); if (tick < tick_l) { tick_h++; } tick_l = tick; return (((uint64_t)tick_h << 32) | tick_l); } ``` -------------------------------- ### Get Network Options (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Driver/group__wifi__management__gr.html This example shows how to retrieve network configuration details such as IP address, subnet mask, and gateway address for the WiFi station interface using the GetOption function. It utilizes specific ARM_WIFI option defines to query each parameter. ```c uint8_t ip[4]; // IP address uint8_t mask[4]; // Subnet mask uint8_t gateway[4]; // Gateway address // Get IP address, Subnet mask and Gateway address of the Station wifi->GetOption (0U, ARM_WIFI_IP, &ip, sizeof(ip)); wifi->GetOption (0U, ARM_WIFI_IP_SUBNET_MASK, &mask, sizeof(mask)); wifi->GetOption (0U, ARM_WIFI_IP_GATEWAY, &gateway, sizeof(gateway)); ``` -------------------------------- ### Install vcpkg and Dependencies with PowerShell Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_windows.md Installs the vcpkg package manager and the Eclipse Paho MQTT C client using PowerShell. This process can take a significant amount of time. Ensure you checkout the correct vcpkg commit as specified. ```powershell PS C:\> git clone https://github.com/Microsoft/vcpkg.git PS C:\> cd vcpkg PS C:\vcpkg> git checkout # Checkout the vcpkg commit per vcpkg-commit.txt above. PS C:\vcpkg> .\bootstrap-vcpkg.bat PS C:\vcpkg> .\vcpkg.exe install --triplet x64-windows-static curl[winssl] cmocka paho-mqtt # Update triplet per your system. PS C:\vcpkg> cd .. ``` -------------------------------- ### Initialize Navigation Tree and Resizable Window Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/DSP/Documentation/html/group__groupExamples.html Initializes the navigation tree for the documentation and enables window resizing. This script is typically run when the document is ready. ```javascript $(document).ready(function(){initNavTree('group__groupExamples.html',''); initResizable(); }); ``` -------------------------------- ### Get Interrupt Vector with __STATIC_INLINE Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core/group__compiler__conntrol__gr.html This example demonstrates retrieving an interrupt vector using NVIC_GetVector, defined with __STATIC_INLINE. The compiler can choose to inline this function, optimizing code size and potentially execution speed by substituting the function call with its body. ```c __STATIC_INLINE uint32_t NVIC_GetVector(IRQn_Type IRQn) { uint32_t *vectors = (uint32_t *) ((uintptr_t) SCB->VTOR); return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; } ``` -------------------------------- ### Compile and Run Azure IoT Sample (Bash) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_linux.md After configuring the build with CMake, this command compiles the Azure SDK for Embedded C and its samples. Subsequently, it shows how to execute a sample application, specifically 'paho_iot_hub_telemetry_sample', from within the 'build' directory. Users can replace this with any other available sample executable. ```bash ~/azure-sdk-for-c/build$ cmake --build . ~/azure-sdk-for-c/build$ ./sdk/samples/iot/paho_iot_hub_telemetry_sample # Use the executable of your choice. ``` -------------------------------- ### ThreadX Nested FIQ Handler Example (Assembly) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/threadx/ports/cortex_a7/iar/readme_threadx.txt This assembly code illustrates how to implement nested FIQ interrupt handling in ThreadX when TX_ENABLE_FIQ_NESTING is defined. It shows the calls to start and end FIQ nesting around the application FIQ dispatch, enabling FIQ interrupts temporarily. ```assembly RSEG .text:CODE:NOROOT(2) PUBLIC __tx_fiq_handler RSEG .text:CODE:NOROOT(2) PUBLIC __tx_fiq_processing_return __tx_fiq_handler ; ; /* Jump to fiq context save to save system context. */ B _tx_thread_fiq_context_save __tx_fiq_processing_return: ; ; /* At this point execution is still in the FIQ mode. The CPSR, point of ; interrupt, and all C scratch registers are available for use. */ ; ; /* Enable nested FIQ interrupts. NOTE: Since this service returns ; with FIQ interrupts enabled, all FIQ interrupt sources must be ; cleared prior to calling this service. */ BL _tx_thread_fiq_nesting_start ; ; /* Application FIQ dispatch call goes here! */ ; ; /* Disable nested FIQ interrupts. The mode is switched back to ; FIQ mode and FIQ interrupts are disable upon return. */ BL _tx_thread_fiq_nesting_end ; ; /* Jump to fiq context restore to restore system context. */ B _tx_thread_fiq_context_restore ``` -------------------------------- ### Run VxWorks Samples Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_vxworks.md Executes sample applications in the VxWorks command shell. Ensure the target has internet access before running. These commands navigate to the romfs directory and then execute the provisioning and client samples. ```shell -> cmd [vxWorks *]# cd /romfs [vxWorks *]# ./azureProvisioningClientSample [vxWorks *]# ./azureClientSample ``` -------------------------------- ### Get Active FIQ ID using IRQ_GetActiveFIQ Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core_A/group__irq__ctrl__gr.html Retrieves the interrupt ID number of the current Fast Interrupt Request (FIQ) source and acknowledges the interrupt. The provided example implementation returns an invalid ID (-1) as FIQ is not supported in this context. ```c IRQn_ID_t IRQ_GetActiveFIQ(void) { /* FIQ is not supported, return invalid ID */ return ((IRQn_ID_t)-1); } ``` -------------------------------- ### Get Interrupt Vector with __STATIC_FORCEINLINE Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core/group__compiler__conntrol__gr.html This example shows how to retrieve an interrupt vector using the NVIC_GetVector function, defined as __STATIC_FORCEINLINE. This ensures the function call is replaced with its body at compile time, potentially improving performance by reducing function call overhead. ```c __STATIC_FORCEINLINE uint32_t NVIC_GetVector(IRQn_Type IRQn) { uint32_t *vectors = (uint32_t *) ((uintptr_t) SCB->VTOR); return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; } ``` -------------------------------- ### Get RTOS Kernel State (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/RTOS2/group__CMSIS__RTOS__KernelCtrl.html The osKernelGetState function retrieves the current state of the RTOS kernel. It can be called before kernel initialization or start, returning osKernelError on failure or the actual kernel state. This function can be safely invoked from Interrupt Service Routines. ```c int main (void) { // System Initialization SystemCoreClockUpdate(); // ... if([osKernelGetState](group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba "Get the current RTOS Kernel state.")() == [osKernelInactive](group__CMSIS__RTOS__KernelCtrl.html#gga08326469274b668140ca934b168a5ad4a2ad3e5912db47b497529d036c89e7995 "Inactive.")) { // Is the kernel initialized? [osKernelInitialize](group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659 "Initialize the RTOS Kernel.")(); // Initialize CMSIS-RTOS kernel } ; } ``` -------------------------------- ### ThreadX Initialization and Resource Creation (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Projects/NUCLEO-N657X0-Q/Applications/USBX/Ux_Device_HID/README.md This C code demonstrates the initialization of USBX resources and the creation of application threads within the `tx_application_define()` function. It sets up two threads: one for USB OTG HAL PCD driver initialization and device start-up, and another for sending HID reports to control the PC cursor. ```c UINT tx_application_define(void *first_unused_memory) { // Initialize the USBX device stack ux_device_stack_initialize(device_framework_reals, /* Device Framework */ (ULONG)sizeof(device_framework_reals), /* Device Framework Length */ NULL, /* No Host Framework */ 0, /* No Host Framework Length */ NULL, /* No Manufacturer String */ 0, /* No Manufacturer String Length */ NULL, /* No Product String */ 0, /* No Product String Length */ NULL, /* No Serial Number String */ 0, /* No Serial Number String Length */ UX_NULL); /* Init hardware */ MX_USB_OTG_FS_PCD_Init(); /* Register the HID class */ ux_device_stack_class_register(UX_DEVICE_CLASS_HID, ux_device_class_hid_entry); /* Create the application threads */ tx_thread_create(&app_ux_device_thread, "App UX Device Thread", app_ux_device_thread_entry, 0, stack_ptr++, 1024, 10, 10, TX_AUTO_START); tx_thread_create(&usbx_hid_thread, "USbx HID Thread", usbx_hid_thread_entry, 0, stack_ptr++, 1024, 20, 20, TX_AUTO_START); return TX_SUCCESS; } ``` -------------------------------- ### Configure SAU Address Regions (C) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core/partition_h_pg.html Defines the maximum number of SAU (Security Attribution Unit) regions and initializes individual regions with their start address, end address, and non-secure callable (NSC) attribute. These macros are typically generated by CMSIS-Zone. ```c #define SAU_REGIONS_MAX 8 /* Max. number of SAU regions */ #define SAU_INIT_REGION0 1 #define SAU_INIT_START0 0x00000000 /* start address of SAU region 0 */ #define SAU_INIT_END0 0x001FFFE0 /* end address of SAU region 0 */ #define SAU_INIT_NSC0 1 #define SAU_INIT_REGION1 1 #define SAU_INIT_START1 0x00200000 /* start address of SAU region 1 */ #define SAU_INIT_END1 0x003FFFE0 /* end address of SAU region 1 */ #define SAU_INIT_NSC1 0 #define SAU_INIT_REGION2 1 #define SAU_INIT_START2 0x20200000 /* start address of SAU region 2 */ #define SAU_INIT_END2 0x203FFFE0 /* end address of SAU region 2 */ #define SAU_INIT_NSC2 0 #define SAU_INIT_REGION3 1 #define SAU_INIT_START3 0x40000000 /* start address of SAU region 3 */ #define SAU_INIT_END3 0x40040000 /* end address of SAU region 3 */ #define SAU_INIT_NSC3 0 #define SAU_INIT_REGION4 0 #define SAU_INIT_START4 0x00000000 /* start address of SAU region 4 */ #define SAU_INIT_END4 0x00000000 /* end address of SAU region 4 */ #define SAU_INIT_NSC4 0 #define SAU_INIT_REGION5 0 #define SAU_INIT_START5 0x00000000 /* start address of SAU region 5 */ #define SAU_INIT_END5 0x00000000 /* end address of SAU region 5 */ #define SAU_INIT_NSC5 0 #define SAU_INIT_REGION6 0 #define SAU_INIT_START6 0x00000000 /* start address of SAU region 6 */ #define SAU_INIT_END6 0x00000000 /* end address of SAU region 6 */ #define SAU_INIT_NSC6 0 #define SAU_INIT_REGION7 0 #define SAU_INIT_START7 0x00000000 /* start address of SAU region 7 */ #define SAU_INIT_END7 0x00000000 /* end address of SAU region 7 */ #define SAU_INIT_NSC7 0 ``` -------------------------------- ### CSS for Icon Components Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Projects/NUCLEO-N657X0-Q/Examples/TIM/TIM_ExtTriggerSynchro/readme.html Styles for custom icon elements using `span` tags with class names starting with 'icon-'. Icons are implemented using background images via data URIs, supporting color inversion and alignment. An example for an 'alert' icon is provided. ```css span[class^='icon-'] { display: inline-block; height: 1em; width: 1em; vertical-align: -0.125em; background-size: contain; margin: 0 calc(var(--universal-margin) / 4); } span[class^='icon-'].secondary { -webkit-filter: invert(25%); filter: invert(25%); } span[class^='icon-'].inverse { -webkit-filter: invert(100%); filter: invert(100%); } span.icon-alert { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2303234b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3 Cline x1='12' y1='16' x2='12' y2='16'%3E%3C/line%3E%3C/svg%3E"); } span.icon-bookmark { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewB"); } ``` -------------------------------- ### Install CMake (Older Ubuntu/Manual) Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/README.md Provides instructions to download and install a specific version of CMake on older Ubuntu versions or as a manual alternative. This ensures a compatible CMake version for project builds. ```bash wget https://cmake.org/files/v3.18/cmake-3.18.3-Linux-x86_64.sh # Use latest version. sudo ./cmake-3.18.3-Linux-x86_64.sh --prefix=/usr ``` -------------------------------- ### Get Active Interrupt (Non-Secure) - C Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Drivers/CMSIS/Documentation/html/Core/group__nvic__trustzone__functions.html Retrieves the active status of a non-secure external interrupt when in secure state. This function takes the interrupt number as input and returns a uint32_t value indicating the active status. It is useful for monitoring interrupt states in a TrustZone setup. ```c uint32_t TZ_NVIC_GetActive_NS(IRQn_Type IRQn) { // Implementation details for getting active IRQ status in non-secure state return 0; } ``` -------------------------------- ### Clone Azure SDK for Embedded C IoT Repository Source: https://github.com/stmicroelectronics/stm32cuben6/blob/main/Middlewares/ST/netxduo/addons/azure_iot/azure-sdk-for-c/sdk/samples/iot/docs/how_to_iot_hub_samples_linux.md Clones the official Azure SDK for Embedded C IoT repository from GitHub. This command downloads all the necessary source code and sample files to the local machine for further configuration and building. ```bash git clone https://github.com/Azure/azure-sdk-for-c.git ```