### Convolution Example Setup (C)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm_convolution_example_f32_8c-example.html
This snippet shows the setup for the convolution example, including buffer declarations and test input data. Ensure MAX_BLOCKSIZE is defined appropriately for your application.
```c
#include "arm_math.h"
#include "math_helper.h"
#define MAX_BLOCKSIZE 128
#define DELTA (0.000001f)
#define SNR_THRESHOLD 90
float32_t Ak[MAX_BLOCKSIZE];
float32_t Bk[MAX_BLOCKSIZE];
float32_t AxB[MAX_BLOCKSIZE * 2];
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,
```
--------------------------------
### Initialize WiFi Bypass Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__wifi__bypass__gr.html
Example demonstrating the initialization of WiFi bypass mode, including retrieving driver capabilities. This setup is part of the necessary steps before utilizing bypass functionalities.
```c
extern ARM_DRIVER_WIFI Driver_WiFi0;
static ARM_DRIVER_WIFI *wifi;
static ARM_ETH_MAC_ADDR own_mac_address;
static void wifi_notify (uint32_t event, ,void *arg) {
switch (event) {
:
}
}
void initialize_wifi_bypass (void) {
ARM_WIFI_CAPABILITIES capabilities;
wifi = &Driver_WiFi0;
capabilities = wifi->GetCapabilities ();
```
--------------------------------
### Flash Driver Setup and Operation Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__flash__interface__gr.html
Demonstrates the typical setup sequence for the Flash driver, including initialization with a callback, power control, reading data, and graceful shutdown. It utilizes CMSIS-RTOS2 for thread management and event signaling.
```c
#include "Driver_Flash.h"
#include "cmsis_os2.h" // ARM::CMSIS:RTOS2:Keil RTX5
/* Flash driver instance */
extern ARM_DRIVER_FLASH Driver_Flash0;
static ARM_DRIVER_FLASH *flashDev = &Driver_Flash0;
/* CMSIS-RTOS2 Thread Id */
osThreadId_t Flash_Thread_Id;
/* Flash signal event */
void Flash_Callback(uint32_t event)
{
if (event & ARM_FLASH_EVENT_READY) {
/* The read/program/erase operation is completed */
osThreadFlagsSet(Flash_Thread_Id, 1U);
}
if (event & ARM_FLASH_EVENT_ERROR) {
/* The read/program/erase operation is completed with errors */
/* Call debugger or replace with custom error handling */
__breakpoint(0);
}
}
/* CMSIS-RTOS2 Thread */
void Flash_Thread (void *argument)
{
/* Query drivers capabilities */
const ARM_FLASH_CAPABILITIES capabilities = flashDev->GetCapabilities();
/* Initialize Flash device */
if (capabilities.event_ready) {
flashDev->Initialize (&Flash_Callback);
} else {
flashDev->Initialize (NULL);
}
/* Power-on Flash device */
flashDev->PowerControl (ARM_POWER_FULL);
/* Read data taking data_width into account */
uint8_t buf[256U];
flashDev->ReadData (0x1000U, buf, sizeof(buf)>>capabilities.data_width);
/* Wait operation to be completed */
if (capabilities.event_ready) {
osThreadFlagsWait (1U, osFlagsWaitAny, 100U);
} else {
osDelay(100U);
}
/* Switch off gracefully */
flashDev->PowerControl (ARM_POWER_OFF);
flashDev->Uninitialize ();
}
```
--------------------------------
### MPU Region Configuration Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__mpu__functions.html
Example demonstrating how to configure MPU Region 0 with specific attributes and enable the MPU. This snippet shows a typical setup for memory protection.
```c
void main()
{
// Set Region 0
[ARM_MPU_SetRegionEx](group__mpu__functions.html#ga042ba1a6a1a58795231459ac0410b809)(0UL, 0x08000000UL, MPU_RASR(0UL, ARM_MPU_AP_FULL, 0UL, 0UL, 1UL, 1UL, 0x00UL, ARM_MPU_REGION_SIZE_1MB));
[ARM_MPU_Enable](group__mpu__functions.html#ga31406efd492ec9a091a70ffa2d8a42fb)(0);
// Execute application code that is access protected by the MPU
```
--------------------------------
### Main Function Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm__class__marks__example__f32_8c.html
The entry point of the example program. It orchestrates the setup, processing, and output of the class marks statistics.
```c
int32_t main(void)
{
// Initialization
numStudents = NUMSTUDENTS;
numSubjects = NUMSUBJECTS;
// Statistical calculations using CMSIS-DSP functions
// ... (calls to arm_max_f32, arm_min_f32, arm_mean_f32, arm_std_f32, arm_var_f32)
// Example usage of student_num
student_num = 0;
// Output results (e.g., printing to console or storing)
// ...
return 0;
}
```
--------------------------------
### FIR Filter Example Setup (C)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm_fir_example_f32_8c-example.html
This C code sets up the necessary includes, defines constants for test length, SNR threshold, block size, and number of taps. It also declares external input and reference output arrays, and a static buffer for test output.
```c
#include "arm_math.h"
#include "math_helper.h"
#define TEST_LENGTH_SAMPLES 320
#define SNR_THRESHOLD_F32 140.0f
#define BLOCK_SIZE 32
#define NUM_TAPS 29
extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES];
extern float32_t refOutput[TEST_LENGTH_SAMPLES];
static float32_t testOutput[TEST_LENGTH_SAMPLES];
/* -------------------------------------------------------------------
* Declare State buffer of size (numTaps + blockSize - 1)
*/
```
--------------------------------
### Graphic Equalizer Example Setup (C)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm_graphic_equalizer_example_q31_8c-example.html
This C code sets up constants for an audio graphic equalizer example using Q31 data types. It defines test lengths, block sizes, and the number of filter stages required.
```c
#include "arm_math.h"
#include "math_helper.h"
/* Length of the overall data in the test */
#define TESTLENGTH 320
/* Block size for the underlying processing */
#define BLOCKSIZE 32
/* Total number of blocks to run */
#define NUMBLOCKS (TESTLENGTH/BLOCKSIZE)
/* Number of 2nd order Biquad stages per filter */
#define NUMSTAGES 2
#define SNR_THRESHOLD_F32 98
```
--------------------------------
### Adaptive Filter Convergence Example Setup
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm_signal_converge_example_f32_8c-example.html
This C code sets up the necessary state buffers and instances for an adaptive FIR filter and an LMSNorm filter. It defines parameters like test length, number of taps, block size, and convergence factors.
```c
#include "arm_math.h"
#include "math_helper.h"
/* ----------------------------------------------------------------------
* Global defines for the simulation
* ------------------------------------------------------------------- */
#define TEST_LENGTH_SAMPLES 1536
#define NUMTAPS 32
#define BLOCKSIZE 32
#define DELTA_ERROR 0.000001f
#define DELTA_COEFF 0.0001f
#define MU 0.5f
#define NUMFRAMES (TEST_LENGTH_SAMPLES / BLOCKSIZE)
/* ----------------------------------------------------------------------
* Declare FIR state buffers and structure
* ------------------------------------------------------------------- */
float32_t firStateF32[NUMTAPS + BLOCKSIZE];
arm_fir_instance_f32 LPF_instance;
/* ----------------------------------------------------------------------
* Declare LMSNorm state buffers and structure
* ------------------------------------------------------------------- */
float32_t lmsStateF32[NUMTAPS + BLOCKSIZE];
```
--------------------------------
### CMSIS-RTOS Thread and Kernel Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS/html/usingOS.html
Defines multiple threads with different priorities and delays, initializes the RTOS kernel, creates the threads, and starts the kernel execution. Ensure `cmsis_os.h` is included and peripherals are set up before starting the kernel.
```c
#include "cmsis_os.h" // CMSIS-RTOS header file
void job1 (void const *argument) { // thread function 'job1'
while (1) {
: // execute some code
osDelay (10); // delay execution for 10 milliseconds
}
}
osThreadDef(job1, osPriorityAboveNormal, 1, 0); // define job1 as thread function
void job2 (void const *argument) { // thread function 'job2'
osThreadCreate (osThread(job1),NULL); // create job1 thread
while (1) {
: // execute some code
}
}
osThreadDef(job2, osPriorityNormal, 1, 0); // define job2 as thread function
void job3 (void const *argument) { // thread function 'job3'
while (1) {
: // execute some code
osDelay (20); // delay execution for 20 milliseconds
}
}
osThreadDef(job3, osPriorityNormal, 1, 0); // define job3 as thread function
int main (void) { // program execution starts here
osKernelInitialize (); // initialize RTOS kernel
: // setup and initialize peripherals
osThreadCreate (osThread(job2));
osThreadCreate (osThread(job3));
osKernelStart (); // start kernel with job2 execution
}
```
--------------------------------
### Initialize and Start RTOS Kernel
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS/html/group__CMSIS__RTOS__KernelCtrl.html
This code demonstrates the basic structure of the main function for a CMSIS-RTOS application. It shows the initialization of the kernel, peripheral setup, thread creation (commented out), and finally starting the kernel to begin thread execution.
```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
}
```
--------------------------------
### main
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm__signal__converge__example__f32_8c.html
The main function serves as the entry point of the program. It orchestrates the execution of the signal convergence example by calling the test_signal_converge_example function and handling its return status. This function is typically responsible for initializing the system and starting the main processing loop.
```APIDOC
## main
### Description
The main function serves as the entry point of the program. It orchestrates the execution of the signal convergence example by calling the test_signal_converge_example function and handling its return status. This function is typically responsible for initializing the system and starting the main processing loop.
### Function Signature
int32_t main(void)
### Parameters
None
### Returns
- int32_t: The exit status of the program. Typically 0 for success.
```
--------------------------------
### Device Feature: QFP Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/pdsc_family_pg.html
Example of defining the number of leads for a QFP package.
```xml
```
--------------------------------
### Device Feature: QFN Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/pdsc_family_pg.html
Example of defining the number of leads for a QFN package.
```xml
```
--------------------------------
### MPU Enable Example 2
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__mpu__functions.html
Example demonstrating how to enable the MPU with all region definitions, background regions for privileged access, and MPU protection for exceptions.
```c
MPU_Enable (MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_HFNMIENA_Msk);
```
--------------------------------
### Install required packages in virtual environment
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/DSP/PythonWrapper/README.md
Install NumPy, SciPy, and Matplotlib within the activated virtual environment. These packages are needed to run the CMSIS-DSP wrapper examples.
```bash
> pip install numpy
> pip install scipy
> pip install matplotlib
```
--------------------------------
### MPU Enable Example 1
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__mpu__functions.html
Example demonstrating how to enable the MPU with all region definitions, but without MPU protection for exceptions.
```c
MPU_Enable (0);
```
--------------------------------
### Basic CMSIS Example for Cortex-A
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core_A/html/using_CMSIS.html
This example demonstrates a typical setup for using the CMSIS layer on an unspecific Cortex-A9 device. It includes timer initialization for millisecond ticks, interrupt handling, and a delay function.
```c
#include // File name depends on device used
static const uint32_t TICK_RATE_HZ = 1000U;
uint32_t volatile msTicks; // Counter for millisecond Interval
static void SysTick_Handler( void )
{
msTicks++; // Increment Counter
}
// We use the Private Tiemer (PTIM) of the Cortex-A9 FVP Model here.
// In general the available Timers are highly vendor specific for Cortex-A processors.
void private_timer_init(void) {
PTIM_SetLoadValue ( (SystemCoreClock/TICK_RATE_HZ) - 1U);
PTIM_SetControl ( PTIM_GetControl() | 7U);
/* Install SysTick_Handler as the interrupt function for PTIM */
IRQ_SetHandler (PrivTimer_IRQn, SysTick_Handler);
/* Determine number of implemented priority bits */
IRQ_SetPriority (PrivTimer_IRQn, IRQ_PRIORITY_Msk);
/* Set lowest priority -1 */
IRQ_SetPriority (PrivTimer_IRQn, GIC_GetPriority((IRQn_ID_t)PrivTimer_IRQn)-1);
/* Enable IRQ */
IRQ_Enable ((IRQn_ID_t)PrivTimer_IRQn);
}
/* Delay execution for given amount of ticks */
void Delay(uint32_t ticks) {
uint32_t tgtTicks = msTicks + ticks; // target tick count to delay execution to
while (msTicks == tgtTicks) {
__WFE (); // Power-Down until next Event/Interrupt
}
}
/* main function */
int main(void)
{
/* Initialize device HAL here */
private_timer_init();
static uint8_t ledState = 0;
/* Infinite loop */
while (1)
{
/* Add application code here */
ledState = !ledState;
Delay(500);
}
}
```
--------------------------------
### System Initialization and Clock Update Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__system__init__gr.html
Example demonstrating the usage of SystemCoreClock, SystemInit, and SystemCoreClockUpdate functions.
```APIDOC
## Code Example
```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) {
/* Error Handling */
}
while(1);
}
```
```
--------------------------------
### Echo Server Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__wifi__socket__gr.html
An example demonstrating how to set up an echo server using WiFi socket functions. It creates a socket, binds it, listens for connections, accepts them, and echoes received data back to the client.
```c
extern ARM_DRIVER_WIFI Driver_WiFi0;
static ARM_DRIVER_WIFI *wifi;
void Echo_Server_Thread (void *arg) {
uint8_t ip[4] = { 0U, 0U, 0U, 0U };
int32_t sock, sd, res;
char dbuf[120];
while (1) {
wifi = &Driver_WiFi0;
sock = wifi->SocketCreate(ARM_SOCKET_AF_INET, ARM_SOCKET_SOCK_STREAM, ARM_SOCKET_IPPROTO_TCP);
wifi->SocketBind (sock, (uint8_t *)ip, sizeof(ip), 7U);
wifi->SocketListen(sock, 1);
sd = wifi->SocketAccept (sock, NULL, NULL, NULL);
wifi->SocketClose (sock);
sock = sd;
while (1) {
res = wifi->SocketRecv(sock, dbuf, sizeof(dbuf));
if (res < 0) {
break; // Error occurred
}
if (res > 0) {
wifi->SocketSend (sock, dbuf, res); // Echo the data
}
}
wifi->SocketClose (sock);
}
}
```
--------------------------------
### test_signal_converge_example Function
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm__signal__converge__example__f32_8c.html
Executes the signal convergence example. This function orchestrates the setup and execution of the convergence test.
```c
arm_status test_signal_converge_example(
void
)
```
--------------------------------
### SAU Address Region Configuration Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/partition_h_pg.html
Example configuration of SAU address regions, defining the maximum number of regions and the properties for each region including initialization, start address, end address, and security attribute.
```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 */
```
--------------------------------
### Example: Configure Ethernet Media Interface
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__eth__phy__interface__gr.html
Example demonstrating how to set the Ethernet media interface using MAC capabilities. It initializes the MAC and PHY drivers, retrieves MAC capabilities, and then sets the interface on the PHY.
```c
static [ARM_ETH_MAC_CAPABILITIES](group__eth__mac__interface__gr.html#structARM__ETH__MAC__CAPABILITIES) capabilities;
static [ARM_DRIVER_ETH_MAC](group__eth__mac__interface__gr.html#structARM__DRIVER__ETH__MAC) *mac;
static [ARM_DRIVER_ETH_PHY](group__eth__phy__interface__gr.html#structARM__DRIVER__ETH__PHY) *phy;
mac = &Driver_ETH_MAC0;
phy = &Driver_ETH_PHY0;
// Initialize Media Access Controller
capabilities = mac->[GetCapabilities](group__eth__mac__interface__gr.html#a9fd725bb058c584a9ced9c579561cdf1) ();
...
status = phy->[SetInterface](group__eth__phy__interface__gr.html#a7dfc7cf346c80e7fdb2fe4cea2c61161) (capabilities.[media_interface](group__eth__mac__interface__gr.html#a3c5cb74e086417a01d0079f847a3fc8d));
```
--------------------------------
### Linear Interpolation Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm__linear__interp__example__f32_8c.html
This example demonstrates the usage of linear interpolation functions within the CMSIS-DSP library. It includes setup for input data, reference output, and the actual interpolated output. Ensure TEST_LENGTH_SAMPLES is defined appropriately.
```c
#define SNR_THRESHOLD
#define TEST_LENGTH_SAMPLES
#define XSPACING
int32_t main(void)
{
/* Call the linear interpolation example function */
linear_interp_example_f32();
/* Return to application space */
return 0;
}
float arm_linear_interep_table[188495];
float32_t snr1;
float32_t snr2;
float32_t testInputSin_f32[TEST_LENGTH_SAMPLES];
float32_t testLinIntOutput[TEST_LENGTH_SAMPLES];
```
--------------------------------
### Example Project Files Section
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/cpdsc_pg.html
Illustrates how to define files and groups within a project's files section. Use predefined values for file categories.
```xml
```
--------------------------------
### Device Configuration Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/sdf_pg.html
Example of configuring a CoreSight device with its base address and access port index.
```xml
3.5
true
0xE0041000
0
```
--------------------------------
### CAN Driver Initialization and Configuration Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__can__interface__gr.html
This example demonstrates the initialization, power control, mode setting, and bitrate configuration of the CAN driver. It includes error handling and retrieval of driver capabilities. Ensure the CAN controller is correctly defined and the driver is available.
```c
#include
#include
#include "cmsis_os.h"
#include "Driver_CAN.h"
// CAN Driver Controller selector
#define CAN_CONTROLLER 1 // CAN Controller number
#define _CAN_Driver_(n) Driver_CAN##n
#define CAN_Driver_(n) _CAN_Driver_(n)
extern ARM_DRIVER_CAN CAN_Driver_(CAN_CONTROLLER);
#define ptrCAN (&CAN_Driver_(CAN_CONTROLLER))
uint32_t rx_obj_idx = 0xFFFFFFFFU;
uint8_t rx_data[8];
ARM_CAN_MSG_INFO rx_msg_info;
uint32_t tx_obj_idx = 0xFFFFFFFFU;
uint8_t tx_data[8];
ARM_CAN_MSG_INFO tx_msg_info;
static void Error_Handler (void) { while (1); }
void CAN_SignalUnitEvent (uint32_t event) {}
void CAN_SignalObjectEvent (uint32_t obj_idx, uint32_t event) {
if (obj_idx == rx_obj_idx) { // If receive object event
if (event == ARM_CAN_EVENT_RECEIVE) { // If message was received successfully
if (ptrCAN->MessageRead(rx_obj_idx, &rx_msg_info, rx_data, 8U) > 0U) {
// Read received message
// process received message ...
}
}
}
if (obj_idx == tx_obj_idx) { // If transmit object event
if (event == ARM_CAN_EVENT_SEND_COMPLETE) { // If message was sent successfully
// acknowledge sent message ...
}
}
}
int main (void) {
ARM_CAN_CAPABILITIES can_cap;
ARM_CAN_OBJ_CAPABILITIES can_obj_cap;
int32_t status;
uint32_t i, num_objects;
can_cap = ptrCAN->GetCapabilities (); // Get CAN driver capabilities
num_objects = can_cap.num_objects; // Number of receive/transmit objects
status = ptrCAN->Initialize (CAN_SignalUnitEvent, CAN_SignalObjectEvent); // Initialize CAN driver
if (status != ARM_DRIVER_OK) { Error_Handler(); }
status = ptrCAN->PowerControl (ARM_POWER_FULL); // Power-up CAN controller
if (status != ARM_DRIVER_OK) { Error_Handler(); }
status = ptrCAN->SetMode (ARM_CAN_MODE_INITIALIZATION); // Activate initialization mode
if (status != ARM_DRIVER_OK) { Error_Handler(); }
status = ptrCAN->SetBitrate (ARM_CAN_BITRATE_NOMINAL, // Set nominal bitrate
100000U, // Set bitrate to 100 kbit/s
(ARM_CAN_BIT_PROP_SEG(5U) | // Set propagation segment to 5 time quanta
ARM_CAN_BIT_PHASE_SEG1(1U)) | // Set phase segment 1 to 1 time quantum (sample point at 87.5% of bit time)
// ARM_CAN_BIT_PHASE_SEG2(2U) | // Set phase segment 2 to 2 time quanta
// ARM_CAN_BIT_SJW(1U) // Set synchronization jump width to 1 time quantum
);
if (status != ARM_DRIVER_OK) { Error_Handler(); }
// ... rest of the configuration and usage ...
return 0;
}
```
--------------------------------
### Get CMSIS RTOS Kernel State
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS2/html/group__CMSIS__RTOS__KernelCtrl.html
Returns the current state of the RTOS kernel. This function can be safely called before the RTOS is initialized or started.
```c
int main (void) {
// System Initialization
SystemCoreClockUpdate();
// ...
```
--------------------------------
### SystemInit
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/globals_func_s.html
Initializes the system. This function is called from the startup code before entering main.
```APIDOC
## SystemInit
### Description
Initializes the system. This function is called from the startup code before entering main.
### Function Signature
`void SystemInit(void);`
### Related Files
`Ref_SystemAndClock.txt`
```
--------------------------------
### Example: Working with Memory Pools (C)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS/html/group__CMSIS__RTOS__PoolMgmt.html
Demonstrates the typical workflow for using memory pools: defining a structure, declaring a pool, creating the pool, and allocating a block.
```c
typedef struct {
uint32_t length;
uint32_t width;
uint32_t height;
uint32_t weight;
} properties_t;
osPoolDef(object_pool, 10, properties_t); // Declare memory pool
osPoolId (object_pool_id); // Memory pool ID
object_pool_id = osPoolCreate(osPool(object_pool));
properties_t *object_data;
object_data = (properties_t *) osPoolAlloc(object_pool_id);
```
--------------------------------
### Get Driver Version Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__storage__interface__gr.html
Retrieves the driver version information. This function can be called anytime, even before initialization, and always returns the same information synchronously.
```c
extern ARM_DRIVER_STORAGE *drv_info;
void read_version (void) {
ARM_DRIVER_VERSION version;
version = drv_info->GetVersion ();
if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
// error handling
return;
}
}
```
--------------------------------
### NVIC Priority Configuration Example (C)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__NVIC__gr.html
Demonstrates setting and getting interrupt priority grouping and encoding priorities using CMSIS NVIC functions.
```c
#include "LPC17xx.h"
uint32_t priorityGroup;
/* Variables to store priority group and priority */
uint32_t priority;
uint32_t preemptPriority;
uint32_t subPriority;
int main (void) {
NVIC_SetPriorityGrouping(5); /* Set priority group to 5:
Bit[7..6] preempt priority Bits,
Bit[5..3] subpriority Bits
(valid for five priority bits) */
priorityGroup = NVIC_GetPriorityGrouping(); /* Get used priority grouping */
priority = NVIC_EncodePriority(priorityGroup, 1, 6); /* Encode priority with 6 for subpriority and 1 for preempt priority
Note: priority depends on the used priority grouping */
```
--------------------------------
### Configure SysTick Timer
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__SysTick__gr.html
Initializes and starts the SysTick Timer to generate interrupts at a specified interval. This example configures the SysTick to generate an interrupt every millisecond.
```c
#include "LPC17xx.h"
volatile uint32_t msTicks = 0; /* Variable to store millisecond ticks */
void SysTick_Handler(void) { /* SysTick interrupt Handler. */
msTicks++; /* See startup file startup_LPC17xx.s for SysTick vector */
}
int main (void) {
uint32_t returnCode;
returnCode = SysTick_Config(SystemCoreClock / 1000); /* Configure SysTick to generate an interrupt every millisecond */
if (returnCode != 0) { /* Check return code for errors */
// Error Handling
}
while(1);
}
```
--------------------------------
### SystemInit
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core_A/html/globals_s.html
Initializes the system to a default state, including clock configuration and other essential system settings.
```APIDOC
## SystemInit()
### Description
Initializes the microcontroller system. This function is called automatically at the beginning of the program execution and should be used to configure the system clock, memory, and peripherals to a default state.
### Function Signature
```c
void SystemInit(void);
```
```
--------------------------------
### FMAC IIR Filter Configuration and Start Example
Source: https://context7.com/stmicroelectronics/stm32cubeg4/llms.txt
This example demonstrates how to configure the FMAC peripheral for an IIR Direct Form 1 filter. It shows loading coefficients, setting buffer sizes, and initiating the filtering process. Input data is fed via interrupt, and output is retrieved via polling.
```APIDOC
## HAL_FMAC_FilterConfig() / HAL_FMAC_FilterStart() / HAL_FMAC_AppendFilterData_IT()
### Description
Configures and starts the Filter Math Accelerator (FMAC) for IIR filtering. This example uses interrupt-driven input data appending and polling for output retrieval.
### Method
`HAL_FMAC_FilterConfig(FMAC_HandleTypeDef *hfmac, FMAC_FilterConfigTypeDef *sFmacConfig)`
`HAL_FMAC_FilterStart(FMAC_HandleTypeDef *hfmac, int16_t *pOutputData, uint16_t *pOutputSize)`
`HAL_FMAC_AppendFilterData_IT(FMAC_HandleTypeDef *hfmac, int16_t *pInputData, uint32_t InputSize)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```c
#include "stm32g4xx_hal.h"
FMAC_HandleTypeDef hfmac;
FMAC_FilterConfigTypeDef sFmacConfig;
static int16_t aFilterCoeffA[6] = { 19448, -29793, 9645, -4884, 671, -81 };
static int16_t aFilterCoeffB[7] = { 590, 3540, 8851, 11801, 8851, 3540, 590 };
#define INPUT_SIZE 128
#define OUTPUT_SIZE 128
static int16_t aInputData[INPUT_SIZE];
static int16_t aOutputData[OUTPUT_SIZE];
void FMAC_IIR_Example(void)
{
hfmac.Instance = FMAC;
if (HAL_FMAC_Init(&hfmac) != HAL_OK)
Error_Handler();
/* Configure IIR filter: load A and B coefficients into FMAC local memory */
sFmacConfig.InputBaseAddress = 0;
sFmacConfig.InputBufferSize = INPUT_SIZE + 6; /* +order for state */
sFmacConfig.InputThreshold = FMAC_THRESHOLD_1;
sFmacConfig.CoeffBaseAddress = sFmacConfig.InputBaseAddress + sFmacConfig.InputBufferSize;
sFmacConfig.CoeffBufferSize = 6 + 7; /* |A| + |B| */
sFmacConfig.OutputBaseAddress = sFmacConfig.CoeffBaseAddress + sFmacConfig.CoeffBufferSize;
sFmacConfig.OutputBufferSize = OUTPUT_SIZE;
sFmacConfig.OutputThreshold = FMAC_THRESHOLD_1;
sFmacConfig.pCoeffA = aFilterCoeffA;
sFmacConfig.CoeffASize = 6;
sFmacConfig.pCoeffB = aFilterCoeffB;
sFmacConfig.CoeffBSize = 7;
sFmacConfig.Filter = FMAC_FUNC_IIR_DIRECT_FORM_1;
sFmacConfig.InputAccess = FMAC_BUFFER_ACCESS_IT;
sFmacConfig.OutputAccess = FMAC_BUFFER_ACCESS_POLLING;
sFmacConfig.Clip = FMAC_CLIP_ENABLED;
if (HAL_FMAC_FilterConfig(&hfmac, &sFmacConfig) != HAL_OK)
Error_Handler();
/* Start the filter; output buffer filled by FMAC autonomously */
if (HAL_FMAC_FilterStart(&hfmac, aOutputData, (uint16_t *)&OUTPUT_SIZE) != HAL_OK)
Error_Handler();
/* Feed input samples via interrupt */
if (HAL_FMAC_AppendFilterData_IT(&hfmac, aInputData, INPUT_SIZE) != HAL_OK)
Error_Handler();
/* aOutputData is now updated with filtered IIR output values */
}
```
### Response
#### Success Response (HAL_OK)
Indicates that the FMAC filter configuration, start, or data appending was successful.
#### Response Example
None explicitly provided, success indicated by `HAL_OK` return value.
```
--------------------------------
### FatFs SD Card File Operations Example
Source: https://context7.com/stmicroelectronics/stm32cubeg4/llms.txt
Shows how to initialize an SD card, mount the FatFs file system, and perform file read/write operations. Requires the Adafruit 802 SD card BSP driver and `app_fatfs` module.
```c
#include "app_fatfs.h"
#include "ff.h"
FATFS SDFatFs; /* FatFs object for SD logical drive */
FIL MyFile; /* File object */
char SDPath[4]; /* SD logical drive path: "0:/" */
void FatFs_SD_Example(void)
{
FRESULT res;
uint32_t bytesWritten, bytesRead;
uint8_t wText[] = "STM32CubeG4 FatFs SD Card Test\r\n";
uint8_t rText[64] = {0};
/* Initialize SD card hardware */
ADAFRUIT_802_SD_Init(0);
/* Link FatFs SD driver and mount file system */
if (FATFS_LinkDriver(&SD_Driver, SDPath) != 0)
Error_Handler();
res = f_mount(&SDFatFs, SDPath, 1); /* 1 = force mount */
if (res != FR_OK)
Error_Handler();
/* Create and write a file */
res = f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
if (res != FR_OK)
Error_Handler();
res = f_write(&MyFile, wText, sizeof(wText) - 1, (UINT *)&bytesWritten);
if ((res != FR_OK) || (bytesWritten < sizeof(wText) - 1))
Error_Handler();
f_close(&MyFile);
/* Read back the file */
res = f_open(&MyFile, "STM32.TXT", FA_READ);
if (res != FR_OK)
Error_Handler();
res = f_read(&MyFile, rText, sizeof(rText) - 1, (UINT *)&bytesRead);
if (res != FR_OK)
Error_Handler();
f_close(&MyFile);
/* Unmount and unlink driver */
f_mount(NULL, SDPath, 1);
FATFS_UnLinkDriver(SDPath);
/* rText now contains "STM32CubeG4 FatFs SD Card Test\r\n" */
}
```
--------------------------------
### ARM_WIFI_IP_DHCP_POOL_BEGIN
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/group__WiFi__option.html
Sets or gets the start IP address for the DHCP server's IP address pool (Access Point mode). The data should be a pointer to a 4-byte uint8_t array.
```APIDOC
## ARM_WIFI_IP_DHCP_POOL_BEGIN
### Description
AP Set/Get IPv4 DHCP pool begin address.
### Parameters
- `data`: Pointer to a `uint8_t[4]` array containing the start IP address of the DHCP pool.
- `len`: Must be 4.
### Usage
This option is used with `ARM_WIFI_SetOption` or `ARM_WIFI_GetOption` to define the starting IP address for DHCP leases in AP mode.
```
--------------------------------
### FFT Bin Example Configuration
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm_fft_bin_example_f32_8c-example.html
This snippet shows the configuration of global variables for the FFT bin example, including FFT size, inverse FFT flag, bit-reversal flag, and reference/test indices.
```c
#include "arm_math.h"
#include "arm_const_structs.h"
#define TEST_LENGTH_SAMPLES 2048
extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES];
static float32_t testOutput[TEST_LENGTH_SAMPLES/2];
uint32_t fftSize = 1024;
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;
/* Reference index at which max energy of bin ocuurs */
uint32_t refIndex = 213, testIndex = 0;
```
--------------------------------
### Create and Delete Timer Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS2/html/group__CMSIS__RTOS__TimerMgmt.html
Demonstrates the creation of a periodic timer, starting it, and subsequently deleting it. Ensure the timer ID is valid before attempting deletion. This function cannot be called from an interrupt service routine.
```c
#include "cmsis_os2.h"
void Timer_Callback (void *arg);
uint32_t exec;
void TimerDelete_example (void) {
osTimerId_t id;
osStatus_t status;
exec = 1U;
id = osTimerNew(Timer_Callback, osTimerPeriodic, &exec, NULL);
osTimerStart(id, 1000U);
status = osTimerDelete(id);
if (status != osOK) {
}
}
```
--------------------------------
### Middleware Initialization with SPI Driver
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Driver/html/theoryOperation.html
Demonstrates how to pass a specific SPI driver instance to middleware for communication setup.
```c
void init_middleware (ARM_DRIVER_SPI *Drv_spi) ...
init_middleware (&Driver_SPI1);
init_middleware (&Driver_SPI2);
```
--------------------------------
### Variance Calculation Example (32-bit Float)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/DSP/html/arm_variance_example_f32_8c-example.html
This snippet shows the setup and usage of the variance calculation function for a 32-bit floating-point input sequence. It includes buffer declarations and test input data.
```c
#include
#include "arm_math.h"
#define MAX_BLOCKSIZE 32
#define DELTA (0.000001f)
float32_t wire1[MAX_BLOCKSIZE];
float32_t wire2[MAX_BLOCKSIZE];
float32_t wire3[MAX_BLOCKSIZE];
float32_t testInput_f32[32] =
{
-0.432564811528221, -1.665584378238097, 0.125332306474831, 0.287676420358549,
-1.146471350681464, 1.190915465642999, 1.189164201652103, -0.037633276593318,
0.327292361408654, 0.174639142820925, -0.186708577681439, 0.725790548293303,
```
--------------------------------
### FreeRTOS Thread and Mutex Example (CMSIS-RTOS v1)
Source: https://context7.com/stmicroelectronics/stm32cubeg4/llms.txt
Demonstrates creating threads with different priorities and protecting shared resources using a mutex. Ensure HAL_Init, SystemClock_Config, and FreeRTOS kernel start are called.
```c
#include "main.h"
#include "cmsis_os.h"
/* Thread handles */
osThreadId HighTaskHandle;
osThreadId LowTaskHandle;
osMutexId sharedMutex;
/* Shared counter protected by mutex */
volatile uint32_t sharedCounter = 0;
void HighPriorityTask(void const *arg)
{
while (1)
{
osMutexWait(sharedMutex, osWaitForever);
sharedCounter++;
osMutexRelease(sharedMutex);
osDelay(20); /* yield for 20 ms */
}
}
void LowPriorityTask(void const *arg)
{
while (1)
{
osMutexWait(sharedMutex, osWaitForever);
sharedCounter += 10;
osMutexRelease(sharedMutex);
osDelay(100);
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
/* Create mutex */
osMutexDef(sharedMutex);
sharedMutex = osMutexCreate(osMutex(sharedMutex));
/* Create tasks: BelowNormal and Idle priorities */
osThreadDef(HighTask, HighPriorityTask, osPriorityBelowNormal, 0, 128);
HighTaskHandle = osThreadCreate(osThread(HighTask), NULL);
osThreadDef(LowTask, LowPriorityTask, osPriorityIdle, 0, 128);
LowTaskHandle = osThreadCreate(osThread(LowTask), NULL);
/* Hand control to FreeRTOS scheduler – never returns */
osKernelStart();
while (1) { }
}
```
--------------------------------
### Message Queue Initialization Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS2/html/group__CMSIS__RTOS__Message.html
Example demonstrating the creation of a message queue object using osMessageQueueNew. Handles potential creation failures.
```c
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Message Queue creation & usage
*--------------------------------------------------------------------------*/
#define MSGQUEUE_OBJECTS 16 // number of Message Queue Objects
typedef struct { // object data type
uint8_t Buf[32];
uint8_t Idx;
} MSGQUEUE_OBJ_t;
osMessageQueueId_t mid_MsgQueue; // message queue id
osThreadId_t tid_Thread_MsgQueue1; // thread id 1
osThreadId_t tid_Thread_MsgQueue2; // thread id 2
void Thread_MsgQueue1 (void *argument); // thread function 1
void Thread_MsgQueue2 (void *argument); // thread function 2
int Init_MsgQueue (void) {
mid_MsgQueue = osMessageQueueNew(MSGQUEUE_OBJECTS, sizeof(MSGQUEUE_OBJ_t), NULL);
if (mid_MsgQueue == NULL) {
; // Message Queue object not created, handle failure
}
```
--------------------------------
### Interrupt Number Definition Example (IRQn_Type)
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/device_h_pg.html
Defines interrupt numbers (IRQn) for processor core exceptions and device-specific interrupts. Negative values are for core exceptions, positive for device-specific ones starting from 0.
```c
typedef enum IRQn
{
/***** Cortex-M0 Processor Exceptions Numbers *****/
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
SVCall_IRQn = -5,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
/***** LPC11xx/LPC11Cxx Specific Interrupt Numbers *****/
WAKEUP0_IRQn = 0,
WAKEUP1_IRQn = 1,
WAKEUP2_IRQn = 2,
: :
: :
EINT1_IRQn = 30,
EINT0_IRQn = 31,
} IRQn_Type;
```
--------------------------------
### Environment Configuration Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/pdsc_examples_pg.html
Configures specific tool-chain environments for a project, including the project file to load. The 'load' attribute can include a path relative to the example's folder.
```xml
```
--------------------------------
### OS_Tick_Setup
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS2/html/group__CMSIS__RTOS__TickAPI.html
Setup OS Tick timer to generate periodic RTOS Kernel Ticks. The timer should be configured to generate periodic interrupts at the frequency specified by _freq_. The parameter _handler_ defines the interrupt handler function that is called. The timer should only be initialized and configured but must not be started to create interrupts. The RTOS kernel calls the function OS_Tick_Enable to start the timer interrupts.
```APIDOC
## OS_Tick_Setup
### Description
Setup OS Tick timer to generate periodic RTOS Kernel Ticks.
### Parameters
#### Path Parameters
- **freq** (uint32_t) - in - tick frequency in Hz
- **handler** (IRQHandler_t) - in - tick IRQ handler
### Returns
- **int32_t** - 0 on success, -1 on error.
```
--------------------------------
### Run External Application Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/debug_description.html
Demonstrates how to call an external tool to calculate a hash for an image file using the RunApplication function and character sequences for file paths.
```c
RunApplication("external_tool.exe", "$P:image.bin $P:output.hash");
```
--------------------------------
### Flash Memory Configuration Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/pdsc_family_pg.html
Defines the properties of an internal flash device, including its name, start address, page size, and programming/erasing timeouts. It also specifies memory blocks and gaps within the flash.
```xml
```
--------------------------------
### File URI Example for URL
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/cp_SWComponents.html
This example shows how to specify a local directory as the download URL for a Software Pack using a file URI. This marks the Pack as offline and requires manual updates.
```xml
file:///c:/temp/working
```
--------------------------------
### Example Device with Variants
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Pack/html/pdsc_family_pg.html
Illustrates how to define a device with multiple variants, each having specific features and descriptions.
```xml
...
Use this device as an alternative.
...
```
--------------------------------
### Setup OS Tick Timer - Cortex-M SysTick Implementation
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/RTOS2/html/group__CMSIS__RTOS__TickAPI.html
Configures the OS Tick timer for periodic interrupts. This implementation uses the Cortex-M SysTick timer and defines a default IRQ priority. The timer is initialized but not started; the RTOS kernel will enable interrupts later.
```c
#ifndef SYSTICK_IRQ_PRIORITY
#define SYSTICK_IRQ_PRIORITY 0xFFU
#endif
static uint8_t PendST;
```
--------------------------------
### Load MPU Regions Example
Source: https://github.com/stmicroelectronics/stm32cubeg4/blob/master/Drivers/CMSIS/docs/Core/html/group__mpu8__functions.html
Loads MPU region configurations from a table. This example demonstrates setting up two memory regions with specific attributes for code and data.
```c
const ARM_MPU_Region_t mpuTable[1][4] = {
{
// BASE SH RO NP XN LIMIT ATTR
{ .RBAR = ARM_MPU_RBAR(0x08000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 0UL), .RLAR = ARM_MPU_RLAR(0x080FFFFFUL, 0UL) },
{ .RBAR = ARM_MPU_RBAR(0x20000000UL, ARM_MPU_SH_NON, 0UL, 1UL, 1UL), .RLAR = ARM_MPU_RLAR(0x20007FFFUL, 0UL) },
```