I have try to connect the re6m3 board with ESP32 C6 with the at comment but i am unable to connect to the wifi can someone help me
#include "wifi.h"
#include "hal_data.h"
#include "SEGGER_RTT/SEGGER_RTT.h"
#include "tx_api.h"
#include <string.h> // For string functions
#define UART_BUFFER_SIZE 256
volatile uint8_t g_uart_rx_buffer[UART_BUFFER_SIZE];
volatile uint32_t g_uart_rx_count = 0;
#define WIFI_SSID "Redmi" // Replace with your WiFi SSID
#define WIFI_PASSWORD "12345678" // Replace with your WiFi password
#define AT_CMD_RST "AT+RST\r\n"
#define AT_CMD_CWMODE "AT+CWMODE=1\r\n"
#define AT_CMD_CWJAP "AT+CWJAP=\"" WIFI_SSID "\",\"" WIFI_PASSWORD "\"\r\n"
#define AT_CMD_CWLAP "AT+CWLAP\r\n" // Command to list available networks
void print_received_data(void);
void user_uart_callback(uart_callback_args_t *p_args);
void init_uart(void);
void init_rtt(void);
void send_at_command(const char *cmd);
void receive_response(char *buffer, uint32_t length);
// UART callback function to handle received data
void user_uart_callback(uart_callback_args_t *p_args)
{
if (UART_EVENT_RX_CHAR == p_args->event)
if (g_uart_rx_count < UART_BUFFER_SIZE)
g_uart_rx_buffer[g_uart_rx_count++] = p_args->data;
}
// UART initialization
void init_uart(void)
fsp_err_t err = R_SCI_UART_Open(&g_uart_ctrl, &g_uart_cfg);
assert(FSP_SUCCESS == err);
// RTT initialization for debugging
void init_rtt(void)
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
// Function to print received data via RTT
void print_received_data(void)
if (g_uart_rx_count > 0)
SEGGER_RTT_WriteString(0, "Received data: ");
SEGGER_RTT_Write(0, (char *)g_uart_rx_buffer, g_uart_rx_count);
SEGGER_RTT_WriteString(0, "\n");
g_uart_rx_count = 0;
// Function to send an AT command over UART
void send_at_command(const char *cmd)
g_uart.p_api->write(g_uart.p_ctrl, (uint8_t *)cmd, strlen(cmd));
// Function to receive the response from ESP32-C6
void receive_response(char *buffer, uint32_t length)
// Wait until response is received (implementing a simple polling)
while (g_uart_rx_count == 0)
tx_thread_sleep(10); // Sleep to avoid blocking the CPU
// Copy received data to buffer
if (g_uart_rx_count <= length)
memcpy(buffer, g_uart_rx_buffer, g_uart_rx_count);
buffer[g_uart_rx_count] = '\0'; // Null-terminate the string
g_uart_rx_count = 0; // Reset counter for next operation
// Entry point for WiFi connection
void wifi_entry(void)
char response[256] = {0};
int retry_count = 0;
const int max_retries = 3;
init_uart();
init_rtt();
SEGGER_RTT_WriteString(0, "Initializeling...\n");
while (retry_count < max_retries) {
SEGGER_RTT_WriteString(0, "Resetting ESP32...\n");
send_at_command(AT_CMD_RST);
tx_thread_sleep(1000); // Increased delay after reset
receive_response(response, sizeof(response));
SEGGER_RTT_WriteString(0, "Response after AT+RST: ");
SEGGER_RTT_WriteString(0, response);
if (strstr(response, "ready") == NULL) {
SEGGER_RTT_WriteString(0, "ESP32 reset failed. Retrying...\n");
retry_count++;
continue;
// Set WiFi mode
SEGGER_RTT_WriteString(0, "Setting WiFi mode...\n");
send_at_command(AT_CMD_CWMODE);
tx_thread_sleep(500);
SEGGER_RTT_WriteString(0, "Response after AT+CWMODE: ");
if (strstr(response, "OK") == NULL) {
SEGGER_RTT_WriteString(0, "Failed to set WiFi mode. Retrying...\n");
// Scan networks
SEGGER_RTT_WriteString(0, "Scanning networks...\n");
send_at_command(AT_CMD_CWLAP);
tx_thread_sleep(5000); // Increased delay for network scan
SEGGER_RTT_WriteString(0, "Available Networks: ");
// Connect to WiFi
SEGGER_RTT_WriteString(0, "Connecting to WiFi...\n");
send_at_command(AT_CMD_CWJAP);
tx_thread_sleep(10000); // Increased delay for connection attempt
SEGGER_RTT_WriteString(0, "Response after AT+CWJAP: ");
if (strstr(response, "WIFI CONNECTED") != NULL && strstr(response, "OK") != NULL) {
SEGGER_RTT_WriteString(0, "WiFi connected successfully.\n");
break;
} else {
SEGGER_RTT_WriteString(0, "WiFi connection failed. Retrying...\n");
if (retry_count == max_retries) {
SEGGER_RTT_WriteString(0, "Failed to connect after maximum retries.\n");
// Main loop
while (1) {
tx_thread_sleep(TX_TIMER_TICKS_PER_SECOND);