1、产品特点
PSOC E84 Edge AI KIT开发板配备双 CPU 内核(400 MHz Arm Cortex‑M55和200 MHz Arm Cortex‑M33),芯片集成图形音频模块、数字信号处理 DSP 单元、安全隔离区、高性能存储扩展等接口;
板载KitProg3编程调试器、SWD调试排针、6轴IMU传感器、3轴磁力计、气压传感器、温湿度传感器、雷达模块以及64MB QSPI Flash、16MB Octal RAM以及具有Wi‑Fi、蓝牙二合一的CYW55513无线模块模组;

主要特性
双核CPU:400MHz Cortex‑M55(高性能) + 200MHz Cortex‑M33(低功耗)
支持1.8V、3.3V工作电压
主要原理图

二、功能效果
通过无线模组的WIFI功能,实现通过网页UI控制板载RGB的灯光效果;

无线WIFI+BLE模块 (LBEE5HY2FY )
Type 2FY是一款基于英飞凌CYW55513组合芯片组的小型高性能模块,支持 Wi-Fi 6 + 蓝牙5.4,Wi-Fi上最高可达143Mbps数据速率,蓝牙数据速率3Mbps;
主要特性
Wi‑Fi:Wi‑Fi 6E(802.11a/b/g/n/ac/ax)三频,支持 2.4 GHz /5 GHz /6 GHz 频段;
蓝牙:Bluetooth 5.4 BR/EDR/LE,BR/EDR 物理速率3 Mbps;


三、代码编写
创建工程模板: Web Server

1、使用Configure Device配置板载RGB对应的引脚为PWM输出模式;


修改PWM时钟频率为1Mhz(Divider:100)

2、在web_server.c中,使用STA模式控制RGB;
uint8_t wifi_ssid[WIFI_SSID_LEN] = "WIFI_SSID"; // WIFI名称
uint8_t wifi_pwd[WIFI_PWD_LEN] = "WIFI_PASS"; // WIFI密码
/*******************************************************************************
* File Name: web_server.c
*
* Description: STA Mode HTTP Server for RGB LED Control
*******************************************************************************/
#include "web_server.h"
#include "cy_http_server.h"
#include "cy_log.h"
#include "cy_secure_sockets.h"
#include "cy_tls.h"
#include "cy_wcm.h"
#include "cy_wcm_error.h"
#include "html_web_page.h"
#include "retarget_io_init.h"
#include <ctype.h>
#include <string.h>
/*****************************************************************************
* Macros
*****************************************************************************/
#define VALUE_TO_BE_FILLED (0U)
#define DATA_LENGTH (1U)
#define APP_SDIO_INTERRUPT_PRIORITY (7U)
#define APP_HOST_WAKE_INTERRUPT_PRIORITY (2U)
#define APP_SDIO_FREQUENCY_HZ (25000000U)
#define SDHC_SDIO_64BYTES_BLOCK (64U)
/*******************************************************************************
* Global Variables
********************************************************************************/
/* Holds the IP address and port number details of the socket for the HTTP
* server. */
cy_socket_sockaddr_t http_server_ip_address;
/* Wi-Fi network interface. */
cy_network_interface_t nw_interface;
/* HTTP server instance. */
cy_http_server_t http_sta_server;
/* Buffer to store SSID and Password (Hardcoded for STA mode) */
uint8_t wifi_ssid[WIFI_SSID_LEN] = "WIFI名称";
uint8_t wifi_pwd[WIFI_PWD_LEN] = "WIFI密码";
static mtb_hal_sdio_t sdio_instance;
static cy_stc_sd_host_context_t sdhc_host_context;
static cy_wcm_config_t wcm_config;
#if (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP)
static cy_stc_syspm_callback_params_t sdcardDSParams = {
.context = &sdhc_host_context, .base = CYBSP_WIFI_SDIO_HW};
static cy_stc_syspm_callback_t sdhcDeepSleepCallbackHandler = {
.callback = Cy_SD_Host_DeepSleepCallback,
.skipMode = SYSPM_SKIP_MODE,
.type = CY_SYSPM_DEEPSLEEP,
.callbackParams = &sdcardDSParams,
.prevItm = NULL,
.nextItm = NULL,
.order = SYSPM_CALLBACK_ORDER};
#endif
int32_t softap_resource_handler(const char *url_path,
const char *url_parameters,
cy_http_response_stream_t *stream, void *arg,
cy_http_message_body_t *http_message_body) {
cy_rslt_t result = CY_RSLT_SUCCESS;
int32_t status = HTTP_REQUEST_HANDLE_SUCCESS;
switch (http_message_body->request_type) {
case CY_HTTP_REQUEST_GET:
// RGB控制网页
result = cy_http_server_response_stream_write_payload(
stream, SOFTAP_DEVICE_DATA, sizeof(SOFTAP_DEVICE_DATA) - 1);
if (CY_RSLT_SUCCESS != result) {
ERR_INFO(("Failed to send the HTTP GET response.\n"));
}
break;
case CY_HTTP_REQUEST_POST: {
int r_val = 0, g_val = 0, b_val = 0, bright_val = 100;
char *ptr;
char safe_data[256] = {0};
uint32_t len = http_message_body->data_length < 255
? http_message_body->data_length
: 255;
memcpy(safe_data, http_message_body->data, len);
// 数据解析
if ((ptr = strstr(safe_data, "R=")) != NULL)
r_val = atoi(ptr + 2);
if ((ptr = strstr(safe_data, "G=")) != NULL)
g_val = atoi(ptr + 2);
if ((ptr = strstr(safe_data, "Bright=")) != NULL) {
bright_val = atoi(ptr + 7);
}
if ((ptr = strstr(safe_data, "&B=")) != NULL) {
b_val = atoi(ptr + 3);
} else if ((ptr = strstr(safe_data, "B=")) != NULL) {
if (strncmp(ptr, "Bright=", 7) != 0) {
b_val = atoi(ptr + 2);
}
}
if (r_val > 255)
r_val = 255;
if (g_val > 255)
g_val = 255;
if (b_val > 255)
b_val = 255;
if (bright_val > 100)
bright_val = 100;
// 调用控制函数
set_rgb_with_brightness((uint8_t)r_val, (uint8_t)g_val, (uint8_t)b_val,
(uint8_t)bright_val);
result = cy_http_server_response_stream_write_payload(
stream, HTTP_HEADER_204, sizeof(HTTP_HEADER_204) - 1);
if (CY_RSLT_SUCCESS != result) {
ERR_INFO(("Failed to send the HTTP POST response.\n"));
}
} break;
default:
ERR_INFO(("Received invalid HTTP request method.\n"));
break;
}
if (CY_RSLT_SUCCESS != result)
status = HTTP_REQUEST_HANDLE_ERROR;
return status;
}
/*******************************************************************************
* Wi-Fi & System Initialization
*******************************************************************************/
cy_rslt_t start_sta_mode() {
cy_rslt_t result;
cy_wcm_connect_params_t connect_param;
cy_wcm_ip_address_t ip_address;
bool wifi_conct_stat = false;
wifi_conct_stat = cy_wcm_is_connected_to_ap();
if (wifi_conct_stat)
cy_wcm_disconnect_ap();
memset(&connect_param, VALUE_TO_BE_FILLED, sizeof(cy_wcm_connect_params_t));
memset(&ip_address, VALUE_TO_BE_FILLED, sizeof(cy_wcm_ip_address_t));
memcpy(connect_param.ap_credentials.SSID, wifi_ssid, sizeof(wifi_ssid));
memcpy(connect_param.ap_credentials.password, wifi_pwd, sizeof(wifi_pwd));
connect_param.ap_credentials.security = CY_WCM_SECURITY_WPA2_AES_PSK;
for (uint32_t conn_retries = 0; conn_retries < 5; conn_retries++) {
result = cy_wcm_connect_ap(&connect_param, &ip_address);
if (result == CY_RSLT_SUCCESS) {
printf("Successfully connected to Wi-Fi network '%s'.\n",
connect_param.ap_credentials.SSID);
break;
}
printf("Connection failed, retrying...\n");
vTaskDelay(pdMS_TO_TICKS(1000));
}
return result;
}
cy_rslt_t start_sta_http_server(void) {
cy_rslt_t result = CY_RSLT_SUCCESS;
cy_wcm_ip_address_t ip_addr;
cy_resource_dynamic_data_t http_get_post_resource;
// 获取路由器分配给板子的 IP
result = cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_STA, &ip_addr);
PRINT_AND_ASSERT(result, "Failed to get STA IP address.\n");
http_server_ip_address.ip_address.ip.v4 = ip_addr.ip.v4;
http_server_ip_address.ip_address.version = CY_SOCKET_IP_VER_V4;
nw_interface.object = (void *)&http_server_ip_address;
nw_interface.type = CY_NW_INF_TYPE_WIFI;
// 初始化并创建服务器
result = cy_http_server_network_init();
result = cy_http_server_create(&nw_interface, HTTP_PORT, MAX_SOCKETS, NULL,
&http_sta_server);
PRINT_AND_ASSERT(result,
"Failed to allocate memory for the STA HTTP server.\n");
PRINT_AND_ASSERT(result, "Failed to register SSE resource.\n");
// 注册主页资源
http_get_post_resource.resource_handler = softap_resource_handler;
http_get_post_resource.arg = NULL;
result = cy_http_server_register_resource(
http_sta_server, (uint8_t *)"/", (uint8_t *)"text/html",
CY_DYNAMIC_URL_CONTENT, &http_get_post_resource);
PRINT_AND_ASSERT(result, "Failed to register root resource.\n");
// 启动服务器
result = cy_http_server_start(http_sta_server);
PRINT_AND_ASSERT(result, "Failed to start the STA HTTP server.\n");
return result;
}
/*******************************************************************************
* Hardware Interrupts & SDIO Init
*******************************************************************************/
static void sdio_interrupt_handler(void) {
mtb_hal_sdio_process_interrupt(&sdio_instance);
}
static void host_wake_interrupt_handler(void) {
mtb_hal_gpio_process_interrupt(&wcm_config.wifi_host_wake_pin);
}
static void app_sdio_init(void) {
cy_rslt_t result;
mtb_hal_sdio_cfg_t sdio_hal_cfg;
cy_stc_sysint_t sdio_intr_cfg = {.intrSrc = CYBSP_WIFI_SDIO_IRQ,
.intrPriority = APP_SDIO_INTERRUPT_PRIORITY};
cy_stc_sysint_t host_wake_intr_cfg = {.intrSrc = CYBSP_WIFI_HOST_WAKE_IRQ,
.intrPriority =
APP_HOST_WAKE_INTERRUPT_PRIORITY};
if (CY_SYSINT_SUCCESS !=
Cy_SysInt_Init(&sdio_intr_cfg, sdio_interrupt_handler))
handle_app_error();
NVIC_EnableIRQ(CYBSP_WIFI_SDIO_IRQ);
result = mtb_hal_sdio_setup(&sdio_instance, &CYBSP_WIFI_SDIO_sdio_hal_config,
NULL, &sdhc_host_context);
if (CY_RSLT_SUCCESS != result)
handle_app_error();
Cy_SD_Host_Enable(CYBSP_WIFI_SDIO_HW);
Cy_SD_Host_Init(CYBSP_WIFI_SDIO_HW,
CYBSP_WIFI_SDIO_sdio_hal_config.host_config,
&sdhc_host_context);
Cy_SD_Host_SetHostBusWidth(CYBSP_WIFI_SDIO_HW, CY_SD_HOST_BUS_WIDTH_4_BIT);
sdio_hal_cfg.frequencyhal_hz = APP_SDIO_FREQUENCY_HZ;
sdio_hal_cfg.block_size = SDHC_SDIO_64BYTES_BLOCK;
mtb_hal_sdio_configure(&sdio_instance, &sdio_hal_cfg);
#if (CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP)
Cy_SysPm_RegisterCallback(&sdhcDeepSleepCallbackHandler);
#endif
mtb_hal_gpio_setup(&wcm_config.wifi_wl_pin, CYBSP_WIFI_WL_REG_ON_PORT_NUM,
CYBSP_WIFI_WL_REG_ON_PIN);
mtb_hal_gpio_setup(&wcm_config.wifi_host_wake_pin,
CYBSP_WIFI_HOST_WAKE_PORT_NUM, CYBSP_WIFI_HOST_WAKE_PIN);
if (CY_SYSINT_SUCCESS !=
Cy_SysInt_Init(&host_wake_intr_cfg, host_wake_interrupt_handler))
handle_app_error();
NVIC_EnableIRQ(CYBSP_WIFI_HOST_WAKE_IRQ);
}
/*******************************************************************************
* Function Name: server_task
********************************************************************************/
void server_task(void *arg) {
cy_rslt_t result = CY_RSLT_SUCCESS;
(void)arg;
app_sdio_init();
wcm_config.interface = CY_WCM_INTERFACE_TYPE_STA;
wcm_config.wifi_interface_instance = &sdio_instance;
result = cy_wcm_init(&wcm_config);
if (CY_RSLT_SUCCESS != result) {
printf("Failed to initialize Wi-Fi Connection Manager.\n");
handle_app_error();
}
printf("\r\nConnecting directly to Wi-Fi '%s'...\r\n", wifi_ssid);
result = start_sta_mode();
if (CY_RSLT_SUCCESS != result) {
printf("Failed to connect to Wi-Fi.\r\n");
handle_app_error();
}
printf("Wi-Fi Connected successfully!\r\n");
printf("Starting HTTP Server...\r\n");
result = start_sta_http_server();
if (CY_RSLT_SUCCESS != result) {
printf("Failed to start server.\r\n");
handle_app_error();
}
// 初始化 RGB 硬件 PWM
initialize_sensors();
// 打印 IP 地址
cy_wcm_ip_address_t ip_address;
cy_wcm_get_ip_addr(CY_WCM_INTERFACE_TYPE_STA, &ip_address);
uint32_t ip_addr = ip_address.ip.v4;
printf("\r\n************************************************\r\n");
printf("Web Server is running!\r\n");
printf("Open browser and go to: http://%u.%u.%u.%u\r\n",
(unsigned char)((ip_addr >> 0) & 0xFF),
(unsigned char)((ip_addr >> 8) & 0xFF),
(unsigned char)((ip_addr >> 16) & 0xFF),
(unsigned char)((ip_addr >> 24) & 0xFF));
printf("************************************************\r\n\r\n");
while (true) {
vTaskDelay(pdMS_TO_TICKS(1000));
}
}3、修改sensors.c ,实现通过PWM控制板载的RGB颜色和亮度;
添加以下功能代码
#include "cy_pdl.h"
#include "cycfg_peripherals.h"
#include "retarget_io_init.h"
#include "web_server.h"
#include <FreeRTOS.h>
#include <semphr.h>
/*******************************************************************************
* Global Variables
********************************************************************************/
pwm_duty_t pwm_duty;
/*******************************************************************************
* Function Name: initialize_sensors
********************************************************************************
* Summary:
* Initializes the three PWM channels for the RGB LED.
*******************************************************************************/
void initialize_sensors(void) {
pwm_duty.xpwm_mutex = xSemaphoreCreateRecursiveMutex();
// ==================== RED PWM ====================
Cy_TCPWM_PWM_Init(CYBSP_PWM_RED_HW, CYBSP_PWM_RED_NUM, &CYBSP_PWM_RED_config);
Cy_TCPWM_PWM_Enable(CYBSP_PWM_RED_HW, CYBSP_PWM_RED_NUM);
Cy_TCPWM_TriggerStart_Single(CYBSP_PWM_RED_HW, CYBSP_PWM_RED_NUM);
// ==================== GREEN PWM ====================
Cy_TCPWM_PWM_Init(CYBSP_PWM_GREEN_HW, CYBSP_PWM_GREEN_NUM,
&CYBSP_PWM_GREEN_config);
Cy_TCPWM_PWM_Enable(CYBSP_PWM_GREEN_HW, CYBSP_PWM_GREEN_NUM);
Cy_TCPWM_TriggerStart_Single(CYBSP_PWM_GREEN_HW, CYBSP_PWM_GREEN_NUM);
// ==================== BLUE PWM ====================
Cy_TCPWM_PWM_Init(CYBSP_PWM_BLUE_HW, CYBSP_PWM_BLUE_NUM,
&CYBSP_PWM_BLUE_config);
Cy_TCPWM_PWM_Enable(CYBSP_PWM_BLUE_HW, CYBSP_PWM_BLUE_NUM);
Cy_TCPWM_TriggerStart_Single(CYBSP_PWM_BLUE_HW, CYBSP_PWM_BLUE_NUM);
// ==================== 设置周期与初始占空比 ====================
// 设定周期为 255
Cy_TCPWM_PWM_SetPeriod0(CYBSP_PWM_RED_HW, CYBSP_PWM_RED_NUM, 255);
Cy_TCPWM_PWM_SetPeriod0(CYBSP_PWM_GREEN_HW, CYBSP_PWM_GREEN_NUM, 255);
Cy_TCPWM_PWM_SetPeriod0(CYBSP_PWM_BLUE_HW, CYBSP_PWM_BLUE_NUM, 255);
// 初始全灭
Cy_TCPWM_PWM_SetCompare0(CYBSP_PWM_RED_HW, CYBSP_PWM_RED_NUM, 0);
Cy_TCPWM_PWM_SetCompare0(CYBSP_PWM_GREEN_HW, CYBSP_PWM_GREEN_NUM, 0);
Cy_TCPWM_PWM_SetCompare0(CYBSP_PWM_BLUE_HW, CYBSP_PWM_BLUE_NUM, 0);
APP_INFO(("RGB PWM Init Done\r\n"));
}
/*******************************************************************************
* Function Name: set_rgb_with_brightness
********************************************************************************
* Summary:
* Sets the R, G, B colors (0-255) with an overall brightness factor (0-100).
*******************************************************************************/
void set_rgb_with_brightness(uint8_t r, uint8_t g, uint8_t b,
uint8_t brightness) {
if (brightness > 100) {
brightness = 100;
}
// 获取互斥锁
xSemaphoreTakeRecursive(pwm_duty.xpwm_mutex, portMAX_DELAY);
// 根据 Period = 255 进行等比例缩放
uint32_t actual_r = ((uint32_t)r * brightness) / 100;
uint32_t actual_g = ((uint32_t)g * brightness) / 100;
uint32_t actual_b = ((uint32_t)b * brightness) / 100;
// 设置 PWM 占空比
Cy_TCPWM_PWM_SetCompare0(CYBSP_PWM_RED_HW, CYBSP_PWM_RED_NUM, actual_r);
Cy_TCPWM_PWM_SetCompare0(CYBSP_PWM_GREEN_HW, CYBSP_PWM_GREEN_NUM, actual_g);
Cy_TCPWM_PWM_SetCompare0(CYBSP_PWM_BLUE_HW, CYBSP_PWM_BLUE_NUM, actual_b);
// 释放互斥锁
xSemaphoreGiveRecursive(pwm_duty.xpwm_mutex);
}
/* [] END OF FILE */4、修改html_web_page.h,实现Web控制页面;
#ifndef HTML_WEB_PAGE_H_
#define HTML_WEB_PAGE_H_
#define SOFTAP_DEVICE_DATA \
"<!DOCTYPE html>" \
"<html>" \
"<head>" \
"<meta charset=\"UTF-8\">" \
"<title>RGB LED 控制界面</title>" \
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" \
"</head>" \
"<body style=\"text-align: center; font-family: sans-serif; " \
"margin-top: " \
"50px;\">" \
"<h1> RGB LED 控制界面 </h1>" \
"<div style=\"display: inline-block; text-align: left; " \
"margin-top: 20px;\">" \
"<label>Red (0-255): <span id=\"rVal\">0</span></label><br>" \
"<input type=\"range\" id=\"rSlider\" min=\"0\" max=\"255\" " \
"value=\"0\" " \
"oninput=\"updateUI()\" onchange=\"sendData()\" " \
"style=\"width: " \
"300px;\"><br><br>" \
"<label>Green (0-255): <span " \
"id=\"gVal\">0</span></label><br>" \
"<input type=\"range\" id=\"gSlider\" min=\"0\" max=\"255\" " \
"value=\"0\" " \
"oninput=\"updateUI()\" onchange=\"sendData()\" " \
"style=\"width: " \
"300px;\"><br><br>" \
"<label>Blue (0-255): <span id=\"bVal\">0</span></label><br>" \
"<input type=\"range\" id=\"bSlider\" min=\"0\" max=\"255\" " \
"value=\"0\" " \
"oninput=\"updateUI()\" onchange=\"sendData()\" " \
"style=\"width: " \
"300px;\"><br><br>" \
"<label>Brightness (0-100): <span " \
"id=\"brightVal\">100</span></label><br>" \
"<input type=\"range\" id=\"brightSlider\" min=\"0\" " \
"max=\"100\" " \
"value=\"100\" oninput=\"updateUI()\" " \
"onchange=\"sendData()\" " \
"style=\"width: 300px;\"><br><br>" \
"</div>" \
"<br><br>" \
"<div id=\"device_data\" style=\"font-weight: bold; color: " \
"blue;\">Status: " \
"Ready</div>" \
"<script>" \
"var timeout = null;" \
"function updateUI() {" \
" document.getElementById('rVal').innerText = " \
"document.getElementById('rSlider').value;" \
" document.getElementById('gVal').innerText = " \
"document.getElementById('gSlider').value;" \
" document.getElementById('bVal').innerText = " \
"document.getElementById('bSlider').value;" \
" document.getElementById('brightVal').innerText = " \
"document.getElementById('brightSlider').value;" \
"}" \
"function sendData() {" \
" clearTimeout(timeout);" \
" timeout = setTimeout(function() {" \
" var r = document.getElementById('rSlider').value;" \
" var g = document.getElementById('gSlider').value;" \
" var b = document.getElementById('bSlider').value;" \
" var bright = " \
"document.getElementById('brightSlider').value;" \
" var xhttp = new XMLHttpRequest();" \
" xhttp.open('POST', '/', true);" \
" xhttp.setRequestHeader('Content-type', " \
"'application/x-www-form-urlencoded');" \
" xhttp.send('Bright=' + bright + '&R=' + r + '&G=' + g " \
"+ '&B=' + b);" \
" }, 100);" \
"}" \
"</script>" \
"</body>" \
"</html>"
#endif /* HTML_WEB_PAGE_H_ */
/* [] END OF FILE */四、程序烧录
1、连接设备至电脑端;
连接至开发板的J1 USB口(KitProg3)
2、选择Application页面的 Program 进行程序烧录;
Build:增量编译
Rebuild:重新编译
Clean:清空编译内容
Erase:擦除 Flash
Program:编译并烧录程序到开发板中

五、效果演示



我要赚赏金
