Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

Adding WCM library and using its APIs in ModusToolbox

PRI
Moderator
Moderator First question asked First like given 50 replies posted
Moderator

Adding WCM library and using its APIs in ModusToolbox

Adding WCM library:
wifi-connection-manager(WCM) library can be added to your project using the "Library Manager" in ModusToolbox. The below is the link for the github repository of WCM library.
 
Project's Makefile is a file named "Makefile" present in the project folder created using "New Application" in ModusToolbox. After adding the WCM library to your project, you have to make the changes mentioned below in your project’s Makefile to build your project without any compilation errors.
 
1. Add freertos, lwip, mbedtls to COMPONENTS in your Makefile to include them in the build.
   `COMPONENTS=FREERTOS LWIP MBEDTLS`

2. Add the below line to configure the MBEDTLS_USER_CONFIG_FILE C macro to mbedtls_user_config.h in the Makefile
   `DEFINES+=MBEDTLS_USER_CONFIG_FILE='"mbedtls_user_config.h"'`

3. You have to add the following additional defines in your Makefile
   `DEFINES=$(MBEDTLSFLAGS) CYBSP_WIFI_CAPABLE CY_RTOS_AWARE`
 
Using WCM APIs:
In a bare metal application, using WCM library APIs will result in a fault and the fault handler is an infinite while loop. So, your application will get stuck in that infinite loop. Code Snippet 1 results in this fault.
 
To avoid above condition, you have to call the WCM APIs from a task created using the “xTaskCreate” like in Code Snippet 2. You need to initialize WCM library by calling “cy_wcm_init” before calling any other WCM API.

Snippet 1:
 
#include "cy_wcm.h"
int main(void)
{    
// Your code
cy_rslt_t result;
cy_wcm_config_t config;
config.interface = CY_WCM_INTERFACE_TYPE_AP;
// Initialize Wi-Fi connection manager
result = cy_wcm_init(&config);
// Your code
}

Snippet 2:
 
#include "cy_wcm.h"
TaskHandle_t Task_handle;
#define Task_stack_size                    (2048u)
#define Task_priority                         (3u)

int main(void)
{
// Your code
xTaskCreate(Task_code, ”Task name”, Task_stack_size, NULL, Task_priority, Task_handle);
// Start the FreeRTOS scheduler
vTaskStartScheduler();
// Should never get here
CY_ASSERT(0);
}

void Task_code(void *args)
{
// Your code
cy_rslt_t result;
cy_wcm_config_t config;
config.interface = CY_WCM_INTERFACE_TYPE_AP;
// Initialize Wi-Fi connection manager
result = cy_wcm_init(&config);
// Your code
}
0 Likes
79 Views