### CMSIS-RTOS v1 to v2 Migration: Application Main Thread Example Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_MigrationGuide.txt This C code snippet demonstrates how to adapt the application's main thread structure when migrating from CMSIS-RTOS v1 to v2 with RTX5. It shows the renaming of the original `main` function to `app_main` and the new `main` function's responsibilities, including system initialization, `SystemCoreClock` update, CMSIS-RTOS kernel initialization, creating the `app_main` thread, and starting the RTOS scheduler. ```C #include "RTE_Components.h" #include CMSIS_device_header /* Renamed main() function */ void app_main (void const *argument) { // contents of old "main" } osThreadDef(app_main, osPriorityNormal, 1, 0); int main (void) { // System Initialization SystemCoreClockUpdate(); // ... osKernelInitialize(); osThreadCreate(osThread(app_main), NULL); osKernelStart(); for (;;); } ``` -------------------------------- ### Initialize and Start CMSIS-RTOS Kernel in main Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This example demonstrates the typical structure of a `main` function when using CMSIS-RTOS. It shows the essential steps: initializing the RTOS kernel, setting up peripherals and creating RTOS objects, and finally starting the kernel to begin thread execution and scheduling. ```C int main (void) { osKernelInitialize (); // initialize CMSIS-RTOS // initialize peripherals here // create 'thread' functions that start executing, // example: tid_name = osThreadCreate (osThread(name), NULL); osKernelStart (); // start thread execution } ``` -------------------------------- ### CMSIS-RTOS Timer Control API (Start and Stop) Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This API documentation details the functions for starting and stopping CMSIS-RTOS timers. It includes parameter descriptions, return status codes, and C code examples demonstrating how to start a periodic timer and how to stop a timer. ```APIDOC osStatus osTimerStart (osTimerId timer_id, uint32_t millisec) - Starts or restarts the specified timer. - Cannot be called from Interrupt Service Routines. - Parameters: - timer_id: The ID of the timer to start or restart. - millisec: The time in milliseconds after which the timer will expire. - Returns (osStatus): - `osOK`: The specified timer has been started or restarted. - `osErrorISR`: `osTimerStart` cannot be called from interrupt service routines. - `osErrorParameter`: `timer_id` is incorrect. - Code Example: #include "cmsis_os.h" void Time_Callback (void const *arg) { // timer callback function // arg contains &exec // called every second after osTimerStart } osTimerDef (Timer, Time_Callback); // define timer uint32_t exec; // argument for the timer call back function void TimerStart_example (void) { osTimerId id; // timer id uint32_t timerDelay; // timer value osStatus status; // function return status // Create periodic timer exec = 1; id = osTimerCreate (osTimer(Timer), osTimerPeriodic, &exec); if (id) { timerDelay = 1000; status = osTimerStart (id, timerDelay); // start timer if (status != osOK) { // Timer could not be started } } } osStatus osTimerStop (osTimerId timer_id) - Stops the specified timer. - Cannot be called from Interrupt Service Routines. - Parameters: - timer_id: The ID of the timer to stop. - Returns (osStatus): - `osOK`: The specified timer has been stopped. - `osErrorISR`: `osTimerStop` cannot be called from interrupt service routines. - `osErrorParameter`: `timer_id` is incorrect. - `osErrorResource`: The timer is not started. - Code Example: #include "cmsis_os.h" void Timer_Callback (void const *arg); // prototype for timer callback function osTimerDef (Timer, Timer_Callback); // define timer void TimerStop_example (void) { ``` -------------------------------- ### Initialize RTOS and Create Main Application Thread Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Tutorial.txt This C code snippet demonstrates the initial setup of a CMSIS-RTOS2 application. It creates the main application launcher thread (`app_main`) and then starts the RTOS kernel, which begins scheduling tasks. ```C osThreadNew(app_main, NULL, NULL); osKernelStart(); ``` -------------------------------- ### Initialize and Start CMSIS-RTOS Kernel in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Kernel.txt Demonstrates the basic initialization and startup sequence of the CMSIS-RTOS kernel, including creating an application main thread. This example shows how `osKernelInitialize` and `osKernelStart` are used in a typical `main` function to prepare and begin RTOS operation. ```C /*---------------------------------------------------------------------------- * Application main thread *---------------------------------------------------------------------------*/ void app_main (void *argument) { // ... for (;;) {} } int main (void) { // System Initialization SystemCoreClockUpdate(); // ... osKernelInitialize(); // Initialize CMSIS-RTOS osThreadNew(app_main, NULL, NULL); // Create application main thread osKernelStart(); // Start thread execution for (;;) {} } ``` -------------------------------- ### Example SAU Region Configuration in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Template.txt Illustrates a practical example of defining Security Attribution Unit (SAU) regions using C preprocessor macros. This snippet sets up multiple SAU regions with specific start and end addresses, and assigns security attributes (Secure/Non-Secure callable or Non-Secure) for each, demonstrating how to initialize and configure memory access permissions. ```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 */ ``` -------------------------------- ### CMSIS-RTOS RTX5 Application and Kernel Initialization in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2.txt Illustrates the basic structure of a CMSIS-RTOS RTX5 application, including the `app_main` thread and the `main` function responsible for system initialization, RTOS kernel initialization, thread creation, and kernel start. This snippet demonstrates the typical entry points and setup sequence for an embedded application using RTX5. ```C void app_main (void *argument) { // ... for (;;) {} } int main (void) { // System Initialization SystemCoreClockUpdate(); // ... osKernelInitialize(); // Initialize CMSIS-RTOS osThreadNew(app_main, NULL, NULL); // Create application main thread osKernelStart(); // Start thread execution for (;;) {} } ``` -------------------------------- ### Start CMSIS-RTOS2 Timer Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Timer.txt This C code example illustrates how to start a previously created CMSIS-RTOS2 timer using the `osTimerStart` function. It demonstrates creating a periodic timer and then initiating its operation with a specified delay, including error checking for the start operation. ```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 } } } ``` -------------------------------- ### Start Existing CMSIS-RTOS Timers Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This snippet demonstrates how to start previously created CMSIS-RTOS timers using their IDs and specified delays. It shows examples for both a one-shot timer and a periodic timer. ```C osTimerStart(one_shot_id, 500); osTimerStart(periodic, 1500); ``` -------------------------------- ### Configure Event Recorder Global Initialization in CMSIS-RTOS Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2.txt Settings for initializing the Event Recorder during kernel initialization and optionally starting event recording. These configurations simplify Event Recorder setup by automating calls to `EventRecorderInitialize` and `EventRecorderStart`. ```APIDOC OS_EVR_INIT: Description: Initialize Event Recorder during osKernelInitialize. Note: If set, an explicit call to EventRecorderInitialize is not required. OS_EVR_START: Description: Start event recording after initialization. Note: If set, an explicit call to EventRecorderStart is not required. EventRecorderStop can be called to stop recording. ``` -------------------------------- ### JavaScript Page Initialization and Search Box Setup Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Build/html/index.html These JavaScript snippets handle the initial setup of the documentation page, including resizing, navigation tree initialization, and the creation and management of a search box for user interaction. ```javascript $(document).ready(initResizable); $(window).load(resizeHeight); $(document).ready(function() { searchBox.OnSelectItem(0); }); var searchBox = new SearchBox("searchBox", "search",false,'Search'); $(document).ready(function(){initNavTree('index.html','');}); ``` -------------------------------- ### Implement MPU Zone Setup Callback in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Thread.txt This C function, `osZoneSetup_Callback`, is invoked by the kernel when the MPU Protected Zone changes. It disables the MPU, loads new MPU settings based on the provided zone, and then re-enables the MPU. This function must be implemented by the user application to handle MPU configuration changes dynamically, ensuring the correct memory protection is applied for the active zone. ```C /* Update MPU settings for newly activating Zone */ void osZoneSetup_Callback (uint32_t zone) { if (zone >= ZONES_NUM) { //Issue an error for incorrect zone value } ARM_MPU_Disable(); ARM_MPU_Load(mpu_table[zone], MPU_REGIONS); ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk); } ``` -------------------------------- ### Example C Configuration for Cortex-M4 Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Template.txt Illustrates a basic C code example for defining core revision and MPU presence for a Cortex-M4 processor, typically found in header files for hardware abstraction. ```C #define __CM4_REV 0x0001U /* Core revision r0p1 */ #define __MPU_PRESENT 1U /* MPU present or not */ ``` -------------------------------- ### Create Simple CMSIS-RTOS Thread with Default Settings Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Thread.txt This example demonstrates how to create a basic thread in CMSIS-RTOS using `osThreadNew` with all default attributes. The thread function `thread1` runs indefinitely in a loop. It initializes the kernel, creates the thread, and then starts the kernel. ```C __NO_RETURN void thread1 (void *argument) { // ... for (;;) {} } int main (void) { osKernelInitialize(); ; osThreadNew(thread1, NULL, NULL); // Create thread with default settings ; osKernelStart(); } ``` -------------------------------- ### Start CMSIS-RTOS2 Timer Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Tutorial.txt This C code snippet shows how to start a previously created CMSIS-RTOS2 timer using its handle and a specified count period in kernel ticks. The timer will begin counting down from the provided value. ```C osTimerStart (timer0_handle,0x100); ``` -------------------------------- ### Get IPv6 Address with vioGetIPv6 Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/VIO.txt This C code example illustrates how to retrieve an IPv6 address from a VIO interface using the `vioGetIPv6` function. It initializes the VIO system and then reads the IPv6 address associated with the interface identified by '0'. ```C #include "cmsis_vio.h" // ::CMSIS Driver:VIO int main (void) { vioAddrIPv6_t addrIPv6; vioInit(); addrIPv6 = vioGetIPv6(0); } ``` -------------------------------- ### Get IPv4 Address with vioGetIPv4 Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/VIO.txt This C code example shows how to retrieve an IPv4 address from a VIO interface using the `vioGetIPv4` function. It initializes the VIO system and then reads the IPv4 address associated with the interface identified by '0'. ```C #include "cmsis_vio.h" // ::CMSIS Driver:VIO int main (void) { vioAddrIPv4_t addrIPv4; vioInit(); addrIPv4 = vioGetIPv4(0); } ``` -------------------------------- ### CMSIS-Pack XML: setup Element Schema Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Zone/src/XML_Format.txt Defines setup information for a peripheral, slot, or peripheral group. It allows specifying register names, an optional index, and a value to be assigned, potentially conditioned on security and privilege settings. ```APIDOC Element: xml_p_setup (/rzone/resources/peripherals/.../setup) Parent Element: peripheral, group, slot Description: Defines the setup information for this peripheral, slot, or peripheral group. When the peripheral is specified for one of the conditions (security/privilege), the value is assigned to the register name (with an optional index). Attributes: name: The name of the register. Type: xs:string Use: required index: An index value for the register. Type: xs:string Use: required value: The value to be assigned to the register. Type: (Inferred from context, likely xs:string or numeric type) Use: (Inferred from context, likely required) ``` -------------------------------- ### WinUSB GUID for CMSIS-DAP v2 Automatic Driver Installation Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/DAP/src/dap_config.txt This snippet provides the specific WinUSB GUID required for automatic installation of CMSIS-DAP v2 enabled debug adapters on Microsoft Windows operating systems (Windows 8 and above). This GUID helps Windows identify and install the correct driver without manual intervention. ```Text {CDB3B5AD-293B-4663-AA36-1AAE46463776} ``` -------------------------------- ### FreeMarker Sorted List Iteration Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Zone/src/GenDataModel.txt Shows how to iterate over a sequence after sorting it by a specific property. This example sorts the 'zone.memory' sequence by the 'start' property before printing the start address and name of each memory region. ```FreeMarker <#list zone.memory?sort_by("start") as mem> ${mem.start} ${mem.name} ``` -------------------------------- ### VIO Interface Initialization Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/VIO.txt The `vioInit` function initializes the VIO interface and any connected hardware used to map VIO signals. It should be called once at the beginning of the application to prepare the VIO environment. ```APIDOC void vioInit (void) - Initializes the VIO interface and any connected hardware. - Parameters: None - Returns: None ``` ```C #include "cmsis_vio.h" // ::CMSIS Driver:VIO int main (void) { // System Initialization SystemCoreClockUpdate(); vioInit(); // ... } ``` -------------------------------- ### Initialize CMSIS RTOS Kernel and Create Threads in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Tutorial.txt This C code demonstrates the essential steps for starting an RTOS application. The `main` function initializes hardware and calls `osKernelInitialize()` to set up the RTOS. The `app_main` function, intended as a launcher thread, then creates other application threads using `osThreadNew()` before the RTOS scheduler is started. ```C void app_main(void *argument) { T_led_ID1 = osThreadNew(led_Thread1, NULL, &ThreadAttr_LED1); T_led_ID2 = osThreadNew(led_Thread2, NULL, &ThreadAttr_LED2); osDelay(osWaitForever); while (1) ; } void main(void) { IODIR1 = 0x00FF0000; // Do any C code you want osKernelInitialize(); // Initialize the kernel ``` -------------------------------- ### Delete CMSIS-RTOS Timer Example Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This C code example illustrates how to create and then delete a CMSIS-RTOS timer. It includes the necessary header, defines a timer callback, creates a periodic timer, starts it, and then demonstrates calling `osTimerDelete` with error checking. ```C #include "cmsis_os.h" void Timer_Callback (void const *arg); // prototype for timer callback function osTimerDef (Timer, Timer_Callback); // define timer void TimerDelete_example (void) { osTimerId id; // timer id osStatus status; // function return status // Create periodic timer exec = 1; id = osTimerCreate (osTimer(Timer2), osTimerPeriodic, NULL); osTimerStart (id, 1000UL); // start timer status = osTimerDelete (id); // stop and delete timer if (status != osOK) { // Timer could not be deleted } } ``` -------------------------------- ### CMSIS-Driver Peripheral Start Sequence Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/General.txt Illustrates the recommended sequence for initializing and powering up a peripheral using CMSIS-Driver functions. This involves allocating I/O resources and setting up peripheral registers, interrupts, and DMA. ```C drv->Initialize (...); // Allocate I/O pins drv->PowerControl (ARM_POWER_FULL); // Power up peripheral, setup IRQ/DMA ``` -------------------------------- ### CMSIS-Driver Shared I/O Pin Usage Example Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/General.txt Demonstrates how two different CMSIS-Drivers can share the same I/O pins by properly managing their start and stop sequences. This example shows sequential usage of an SPI driver and a USART driver on potentially overlapping pins. ```C SPI1drv->Initialize (...); // Start SPI1 SPI1drv->PowerControl (ARM_POWER_FULL); ... // Do operations with SPI1 SPI1drv->PowerControl (ARM_POWER_OFF); // Stop SPI1 SPI1drv->Uninitialize (); ... USART1drv->Initialize (...); // Start USART1 USART1drv->PowerControl (ARM_POWER_FULL); ... // Do operations with USART1 USART1drv->PowerControl (ARM_POWER_OFF); // Stop USART1 USART1drv->Uninitialize (); ``` -------------------------------- ### Get Current CMSIS-RTOS Thread ID Example in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This C code example illustrates how to retrieve the ID of the currently running thread using the `osThreadGetId` function in CMSIS-RTOS. It includes a check to handle cases where the ID cannot be obtained, such as when not called from within a thread context. ```C void ThreadGetId_example (void) { osThreadId id; // id for the currently running thread id = osThreadGetId (); if (id == NULL) { // Failed to get the id; not in a thread } } ``` -------------------------------- ### Example Configuration for Cortex-A9 Processor Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core_A/src/Template.txt Illustrates how to configure an ARM Cortex-A9 processor and its core peripherals using CMSIS preprocessor defines. This example sets the core revision, specifies Cortex-A9, and indicates the presence of FPU and GIC, while disabling the private timer and L2 cache. ```C #define __CA_REV 0x0000U /*!< Core revision r0p0 */ #define __CORTEX_A 9U /*!< Cortex-A9 Core */ #define __FPU_PRESENT 1U /*!< FPU present */ #define __GIC_PRESENT 1U /*!< GIC present */ #define __TIM_PRESENT 0U /*!< TIM not present */ #define __L2C_PRESENT 0U /*!< L2C not present */ : : #include "core_ca.h" /* Cortex-A processor and core peripherals */ ``` -------------------------------- ### CMSIS System Initialization and Program Start Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Ref_CompilerControl.txt This C code snippet illustrates the typical entry point for CMSIS-based embedded systems, showing calls to `SystemInit` for hardware initialization and `__PROGRAM_START` to enter the C library's main entry point (PreMain). ```C SystemInit(); /* CMSIS System Initialization */ __PROGRAM_START(); /* Enter PreMain (C library entry point) */ ``` -------------------------------- ### CMSIS-RTOS RTX Round-Robin Multitasking Example Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This C code example demonstrates the implementation of Round-Robin Multitasking using CMSIS-RTOS RTX. It defines two simple counter threads, `job1` and `job2`, both running at the same priority. The kernel initializes, creates these threads, and then starts, allowing RTX to switch between them based on the configured time slice, illustrating quasi-parallel execution. ```C #include "cmsis_os.h" // CMSIS-RTOS header file int counter1; int counter2; void job1 (void const *arg) { while (1) { // loop forever counter1++; // update the counter } } void job2 (void const *arg) { while (1) { // loop forever counter2++; // update the counter } } osThreadDef (job1, osPriorityAboveNormal, 1, 0); osThreadDef (job2, osPriorityAboveNormal, 1, 0); int main (void) { osKernelInitialize (); // setup kernel osThreadCreate (osThread(job1), NULL); // create threads osThreadCreate (osThread(job2), NULL); osKernelStart (); // start kernel } ``` -------------------------------- ### Complete C-side SVC Function Declaration and Implementation Example Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS/src/cmsis_os.txt This comprehensive C code snippet combines both the declaration and implementation of a user-defined SVC function. It shows the `__svc(1)` attribute for declaration and the `__SVC_1` function for implementation, including the necessary interrupt disable/enable calls to protect the critical section. This example provides a full view of the C-side setup for an SVC. ```C void __svc(1) inc_5bit (U32 *cp); void __SVC_1 (U32 *cp) { // A protected function to increment a 5-bit counter. __disable_irq(); *cp = (*cp + 1) & 0x1F; __enable_irq(); } ``` -------------------------------- ### Delete CMSIS-RTOS Timer Example in C Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Timer.txt This C code snippet demonstrates how to create, start, and then stop and delete a periodic timer using CMSIS-RTOS API functions. It includes error checking for the deletion operation. ```C #include "cmsis_os2.h" void Timer_Callback (void *arg); // prototype for timer callback function uint32_t exec; // argument for the timer call back function void TimerDelete_example (void) { osTimerId_t id; // timer id osStatus_t status; // function return status // Create periodic timer exec = 1U; id = osTimerNew(Timer_Callback, osTimerPeriodic, &exec, NULL); osTimerStart(id, 1000U); // start timer ; status = osTimerDelete(id); // stop and delete timer if (status != osOK) { // Timer could not be deleted } ; } ``` -------------------------------- ### Stop CMSIS-RTOS2 Timer Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Timer.txt This C code example demonstrates how to stop a running CMSIS-RTOS2 timer using the `osTimerStop` function. It shows the typical sequence of creating and starting a timer, followed by stopping it, and includes error handling for the stop operation. ```C #include "cmsis_os2.h" void Timer_Callback (void *arg); // prototype for timer callback function uint32_t exec; // argument for the timer call back function void TimerStop_example (void) { osTimerId_t id; // timer id osStatus_t status; // function return status // Create periodic timer exec = 1U; id = osTimerNew(Timer_Callback, osTimerPeriodic, &exec, NULL); osTimerStart(id, 1000U); // start timer status = osTimerStop(id); // stop timer if (status != osOK) { // Timer could not be stopped } } ``` -------------------------------- ### Example of Loading ARM MPU Regions from a Table Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Ref_MPU.txt Illustrates how to define and load multiple ARM MPU regions from a `ARM_MPU_Region_t` table using the `ARM_MPU_Load` function. This example shows a 3x4 table of MPU configurations, demonstrating how to switch between different sets of MPU settings dynamically. ```C const ARM_MPU_Region_t mpuTable[3][4] = { { { .RBAR = ARM_MPU_RBAR(0UL, 0x08000000UL), .RASR = ARM_MPU_RASR(0UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_1MB) }, { .RBAR = ARM_MPU_RBAR(1UL, 0x20000000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_32KB) }, { .RBAR = ARM_MPU_RBAR(2UL, 0x40020000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 2UL, 0UL, 0UL, 0UL, 0x00UL, ARM_MPU_REGION_SIZE_8KB) }, { .RBAR = ARM_MPU_RBAR(3UL, 0x40022000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 2UL, 0UL, 0UL, 0UL, 0xC0UL, ARM_MPU_REGION_SIZE_4KB) } }, { { .RBAR = ARM_MPU_RBAR(4UL, 0x08000000UL), .RASR = ARM_MPU_RASR(0UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_1MB) }, { .RBAR = ARM_MPU_RBAR(5UL, 0x20000000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_32KB) }, { .RBAR = ARM_MPU_RBAR(6UL, 0x40020000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 2UL, 0UL, 0UL, 0UL, 0x00UL, ARM_MPU_REGION_SIZE_8KB) }, { .RBAR = ARM_MPU_RBAR(7UL, 0x40022000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 2UL, 0UL, 0UL, 0UL, 0xC0UL, ARM_MPU_REGION_SIZE_4KB) } }, { { .RBAR = ARM_MPU_RBAR(4UL, 0x18000000UL), .RASR = ARM_MPU_RASR(0UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_1MB) }, { .RBAR = ARM_MPU_RBAR(5UL, 0x30000000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_32KB) }, { .RBAR = ARM_MPU_RBAR(6UL, 0x50020000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 2UL, 0UL, 0UL, 0UL, 0x00UL, ARM_MPU_REGION_SIZE_8KB) }, { .RBAR = ARM_MPU_RBAR(7UL, 0x50022000UL), .RASR = ARM_MPU_RASR(1UL, ARM_MPU_AP_FULL, 2UL, 0UL, 0UL, 0UL, 0xC0UL, ARM_MPU_REGION_SIZE_4KB) } } }; void UpdateMpu(uint32_t idx) { ARM_MPU_Load(mpuTable[idx], 4); } ``` -------------------------------- ### Cortex-M MPU Configuration Example Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Ref_MPU.txt Demonstrates how to enable the Memory Protection Unit (MPU) and configure a memory region using `ARM_MPU_SetRegionEx` and `ARM_MPU_Enable` functions. It shows a basic setup for a 1MB region at address 0x08000000UL and then disables the MPU. ```C int main() { // Set Region 0 ARM_MPU_SetRegionEx(0UL, 0x08000000UL, ARM_MPU_RASR(0UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_1MB)); ARM_MPU_Enable(0); // Execute application code that is access protected by the MPU ARM_MPU_Disable(); } ``` -------------------------------- ### Basic MCU Initialization and Super-Loop with Interrupts (C) Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Using.txt This snippet illustrates fundamental microcontroller programming patterns, including device initialization, setting up a timer interrupt, and managing a main 'super-loop'. It shows how to disable and enable interrupts for critical sections and use `__WFE()` for power management. ```C __WFE (); // Power-Down until next Event/Interrupt } } void TIM1_UP_IRQHandler (void) { // Timer Interrupt Handler ; // Add user code here } void timer1_init(int frequency) { // Set up Timer (device specific) NVIC_SetPriority (TIM1_UP_IRQn, 1); // Set Timer priority NVIC_EnableIRQ (TIM1_UP_IRQn); // Enable Timer Interrupt } void Device_Initialization (void) { // Configure & Initialize MCU if (SysTick_Config (SystemCoreClock / 1000)) { // SysTick 1mSec : // Handle Error } timer1_init (); // setup device-specific timer } // The processor clock is initialized by CMSIS startup + system file void main (void) { // user application starts here Device_Initialization (); // Configure & Initialize MCU while (1) { // Endless Loop (the Super-Loop) __disable_irq (); // Disable all interrupts Get_InputValues (); // Read Values __enable_irq (); // Enable all interrupts Calculation_Response (); // Calculate Results Output_Response (); // Output Results WaitForTick (); // Synchronize to SysTick Timer } } ``` -------------------------------- ### CMSIS-RTOS Kernel State and Initialization Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Kernel.txt This C code example demonstrates how to check the current state of the CMSIS-RTOS kernel using `osKernelGetState` and initialize it with `osKernelInitialize` if it's inactive. It also shows how to start the kernel with `osKernelStart` once it's ready, initiating thread execution. ```C int main (void) { // System Initialization SystemCoreClockUpdate(); // ... if(osKernelGetState() == osKernelInactive) { // Is the kernel initialized? osKernelInitialize(); // Initialize CMSIS-RTOS kernel } ; } ``` ```C int main (void) { // System Initialization SystemCoreClockUpdate(); // ... if(osKernelGetState() == osKernelInactive) { osKernelInitialize(); } ; // ... Start Threads if (osKernelGetState() == osKernelReady) { // If kernel is ready to run... osKernelStart(); // ... start thread execution } while(1); // only reached in case of error } ``` -------------------------------- ### jQuery Document Ready and Window Load Handlers Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Pack/html/index.html These JavaScript snippets utilize jQuery to execute functions when the DOM is ready or the window has fully loaded. They are responsible for initializing page resizing, selecting an item in a search box, and setting up the navigation tree. ```javascript $(document).ready(initResizable); $(window).load(resizeHeight); $(document).ready(function() { searchBox.OnSelectItem(0); }); $(document).ready(function(){initNavTree('index.html','');}); ``` -------------------------------- ### Hide UI Elements and Initialize Search Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/DSP/html/search/pages_1.html This JavaScript code snippet manages the visibility of UI elements and initializes a search functionality. It hides 'Loading' and 'No Matches' display elements, then creates a new `SearchResults` object and triggers its `Search` method to begin or refresh the search process. ```JavaScript document.getElementById("Loading").style.display="none"; document.getElementById("NoMatches").style.display="none"; var searchResults = new SearchResults("searchResults"); searchResults.Search(); ``` -------------------------------- ### CMSIS-Zone Utility Headless Command Line Interface Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Zone/src/Overview.txt Documents the command-line interface for the CMSIS-Zone utility, allowing users to generate output files in headless mode. It specifies the executable, application plugin, and various parameters for processing .azone files and managing template directories. ```APIDOC eclipsec.exe -noSplash -consoleLog --launcher.suppressErrors -application com.arm.cmsis.zone.ui.headlessgen -azone FILENME.azone -ftl FTL_DIR -ftl_gen FTL_GEN_DIR Parameters: -noSplash: Suppresses Eclipse's splash screen. (Required) -launcher.suppressErrors: Suppresses error dialog. (Optional) -consoleLog: Suppresses diagnostic messages. (Optional) -application com.arm.cmsis.zone.ui.headlessgen: Specifies the plug-in to be called. (Required) -azone FILNAME.azone: Specifies the .azone file to be processed. (Required) -ftl FTL_DIR: Relative or absolute directory with templates to process. (Optional, default: ftl directory under the azone's file path is used) -ftl_gen FTL_GEN_DIR: Relative or absolute output directory to write generated files. (Optional, default: ftl_gen directory under the azone's file path is used) -help: Shows command line parameter information. (Optional) ``` -------------------------------- ### C Example: Using SystemCoreClock, SystemInit, and SystemCoreClockUpdate Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Core/src/Ref_SystemAndClock.txt This C code snippet demonstrates how to use the `SystemCoreClock` variable to store the system frequency and how to update it using `SystemCoreClockUpdate()`. It also implicitly shows the context where `SystemInit()` would be called (though not explicitly in `main`). The example checks for consistency between initial and updated clock values, highlighting the need to call `SystemCoreClockUpdate()` after any clock changes. ```C #include "LPC17xx.h" uint32_t coreClock_1 = 0; /* Variables to store core clock values */ uint32_t coreClock_2 = 0; int main (void) { coreClock_1 = SystemCoreClock; /* Store value of predefined SystemCoreClock */ SystemCoreClockUpdate(); /* Update SystemCoreClock according to register settings */ coreClock_2 = SystemCoreClock; /* Store value of calculated SystemCoreClock */ if (coreClock_2 != coreClock_1) { /* Without changing the clock setting both core clock values should be the same */ // Error Handling } while(1); } ``` -------------------------------- ### Get 3D Value with vioGetXYZ Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/VIO.txt This C code example illustrates how to retrieve a three-dimensional value from the CMSIS VIO interface using the `vioGetXYZ` function. It initializes the VIO system and then fetches a 3D value associated with a specific identifier, such as `vioMotionGyro`. ```C #include "cmsis_vio.h" // ::CMSIS Driver:VIO int main (void) { volatile vioValueXYZ_t xyz; vioInit(); xyz = vioGetXYZ(vioMotionGyro); } ``` -------------------------------- ### Set IPv4 Address with vioSetIPv4 Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/Driver/src/VIO.txt This C code example demonstrates how to configure an IPv4 address for a VIO interface using the `vioSetIPv4` function. It initializes a `vioAddrIPv4_t` structure with a sample IPv4 address and then assigns it to the interface identified by '0'. ```C #include "cmsis_vio.h" // ::CMSIS Driver:VIO int main (void) { vioAddrIPv4_t addrIPv4 = {192U, 168U, 111U, 123U}; vioInit(); vioSetIPv4 (0, addrIPv4); } ``` -------------------------------- ### CMSIS-RTOS Timer Management API Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Migration.txt This section covers the API for managing software timers in CMSIS-RTOS. It details changes to existing timer functions like deletion, starting, and stopping, and introduces new functions for getting timer names and checking their running status. It also highlights the replacement of osTimerCreate with osTimerNew. ```APIDOC osStatus_t osTimerDelete (osTimerId_t timer_id) - Old Signature: osStatus osTimerDelete (osTimerId timer_id) - Description: Deletes a software timer. The return type changed to osStatus_t, and the parameter type changed to osTimerId_t. - Parameters: - timer_id: Identifier of the timer to delete. - Returns: osStatus_t indicating the status of the operation. const char *osTimerGetName (osTimerId_t timer_id) - Description: Retrieves the name of a software timer. This is a new function. - Parameters: - timer_id: Identifier of the timer. - Returns: A pointer to the timer's name string. uint32_t osTimerIsRunning (osTimerId_t timer_id) - Description: Checks if a software timer is currently running. This is a new function. - Parameters: - timer_id: Identifier of the timer. - Returns: Non-zero if the timer is running, 0 otherwise. osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) - Old Signature: osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) - Description: Creates a new software timer. This function replaces osTimerCreate. The return type changed to osTimerId_t, and the parameter list and types have changed significantly. - Parameters: - func: Pointer to the timer callback function. - type: Type of the timer (one-shot or periodic). - argument: Argument passed to the timer callback function. - attr: Optional attributes for the timer. - Returns: Identifier of the new timer, or NULL if creation failed. osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks) - Old Signature: osStatus osTimerStart (osTimerId timer_id, uint32_t timeout) - Description: Starts or restarts a software timer. The return type changed to osStatus_t, and the first parameter type changed to osTimerId_t. - Parameters: - timer_id: Identifier of the timer to start. - ticks: Timeout value in ticks for the timer. - Returns: osStatus_t indicating the status of the operation. osStatus_t osTimerStop (osTimerId_t timer_id) - Old Signature: osStatus osTimerStop (osTimerId timer_id) - Description: Stops a running software timer. The return type changed to osStatus_t, and the parameter type changed to osTimerId_t. - Parameters: - timer_id: Identifier of the timer to stop. - Returns: osStatus_t indicating the status of the operation. ``` -------------------------------- ### Initialize and Execute Search Functionality Source: https://github.com/arm-software/cmsis_5/blob/develop/CMSIS/DoxyGen/DSP/html/search/groups_10.html This JavaScript snippet manages the display of UI elements during a search operation. It hides 'Loading' and 'No Matches' indicators, then initializes a `SearchResults` object and triggers its `Search()` method to begin the search process. ```JavaScript document.getElementById("Loading").style.display="none"; document.getElementById("NoMatches").style.display="none"; var searchResults = new SearchResults("searchResults"); searchResults.Search(); ```