Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bsp/ESP32_C3/.ci/attachconfig/ci.attachconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ devices.wifi:
- CONFIG_BSP_USING_WIFI=y
- CONFIG_RT_USING_WIFI=y
- CONFIG_RT_USING_LWIP=y
- CONFIG_RT_USING_NETDEV=y
devices.at:
kconfig:
- CONFIG_RT_USING_AT=y
- CONFIG_AT_USING_CLIENT=y
- CONFIG_RT_USING_SAL=y
- CONFIG_RT_USING_NETDEV=y
2 changes: 1 addition & 1 deletion bsp/ESP32_C3/rtconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
STRIP = PREFIX + 'strip'

DEVICE = ' -nostartfiles -march=rv32imc --specs=nosys.specs -fasynchronous-unwind-tables '
CFLAGS = DEVICE + '-gdwarf-4 -ggdb -Og '
CFLAGS = DEVICE + '-include ../../components/libc/compilers/common/include/sys/ioctl.h -gdwarf-4 -ggdb -Og '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPPPATH += [cwd + '/include/dfs_net']

试下在这里改。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@1078249029 1078249029 Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/RT-Thread/rt-thread/blob/master/components%2Flibc%2Fcompilers%2Fcommon%2FSConscript#L7-L7 或者看看这里头文件为啥没加进去

objs = PrepareBuilding(env, RTT_ROOT, remove_components = ['libc'])

这里在编译系统内把libc文件夹去掉了,如果添加后esp提供的工具链冲突
图片
所以只能在bsp内单独添加这个文件(添加文件夹也不行)。我上次报告的错误可能就是这个原因引起的
奇怪的是单独添加ioctl.h文件我的at代码竟然能用,不太了解sal层是怎么做的。

AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0 -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T idf_port/ld/memory.ld -T idf_port/ld/sections.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.api.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.libgcc.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.newlib.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.version.ld -T packages/ESP-IDF-latest/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld -T packages/ESP-IDF-latest/components/soc/esp32c3/ld/esp32c3.peripherals.ld -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting -Wl,--wrap=__register_frame_info_bases -Wl,--wrap=__register_frame_info -Wl,--wrap=__register_frame -Wl,--wrap=__register_frame_info_table_bases -Wl,--wrap=__register_frame_info_table -Wl,--wrap=__register_frame_table -Wl,--wrap=__deregister_frame_info_bases -Wl,--wrap=__deregister_frame_info -Wl,--wrap=_Unwind_Find_FDE -Wl,--wrap=_Unwind_GetGR -Wl,--wrap=_Unwind_GetCFA -Wl,--wrap=_Unwind_GetIP -Wl,--wrap=_Unwind_GetIPInfo -Wl,--wrap=_Unwind_GetRegionStart -Wl,--wrap=_Unwind_GetDataRelBase -Wl,--wrap=_Unwind_GetTextRelBase -Wl,--wrap=_Unwind_SetIP -Wl,--wrap=_Unwind_SetGR -Wl,--wrap=_Unwind_GetLanguageSpecificData -Wl,--wrap=_Unwind_FindEnclosingFunction -Wl,--wrap=_Unwind_Resume -Wl,--wrap=_Unwind_RaiseException -Wl,--wrap=_Unwind_DeleteException -Wl,--wrap=_Unwind_ForcedUnwind -Wl,--wrap=_Unwind_Resume_or_Rethrow -Wl,--wrap=_Unwind_Backtrace -Wl,--wrap=__cxa_call_unexpected -Wl,--eh-frame-hdr -Wl,--wrap=__gxx_personality_v0 -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0'
CXXFLAGS = CFLAGS
Expand Down
6 changes: 4 additions & 2 deletions components/net/at/include/at.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -222,6 +222,7 @@ int at_obj_set_urc_table(at_client_t client, const struct at_urc * table, rt_siz

/* AT client send commands to AT server and waiter response */
int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr, ...);
int at_obj_exec_cmd_format(at_client_t client, at_response_t resp, const char* format, const char *cmd_expr, ...);

/* AT response object create and delete */
at_response_t at_create_resp(rt_size_t buf_size, rt_size_t line_num, rt_int32_t timeout);
Expand All @@ -242,6 +243,7 @@ int at_resp_parse_line_args_by_kw(at_response_t resp, const char *keyword, const
*/

#define at_exec_cmd(resp, ...) at_obj_exec_cmd(at_client_get_first(), resp, __VA_ARGS__)
#define at_exec_cmd_format(resp, format, ...) at_obj_exec_cmd_format(at_client_get_first(), resp, format, __VA_ARGS__)
#define at_client_wait_connect(timeout) at_client_obj_wait_connect(at_client_get_first(), timeout)
#define at_client_send(buf, size) at_client_obj_send(at_client_get_first(), buf, size)
#define at_client_recv(buf, size, timeout) at_client_obj_recv(at_client_get_first(), buf, size, timeout)
Expand All @@ -264,4 +266,4 @@ void at_port_factory_reset(void);
}
#endif

#endif /* __AT_H__ */
#endif /* __AT_H__ */
104 changes: 100 additions & 4 deletions components/net/at/src/at_client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -20,13 +20,15 @@

#define LOG_TAG "at.clnt"
#include <at_log.h>

#ifdef AT_USING_CLIENT

#define AT_RESP_END_OK "OK"
#define AT_RESP_END_ERROR "ERROR"
#define AT_RESP_END_FAIL "FAIL"
#define AT_END_CR_LF "\r\n"
#define AT_END_CR "\r"
#define AT_END_LF "\n"
#define AT_END_RAW ""

static struct at_client at_client_table[AT_CLIENT_NUM_MAX] = { 0 };

Expand All @@ -35,6 +37,9 @@ extern rt_size_t at_utils_send(rt_device_t dev,
const void *buffer,
rt_size_t size);
extern rt_size_t at_vprintfln(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args);
extern rt_size_t at_vprintf(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args);
extern rt_size_t at_vprintfcr(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args);
extern rt_size_t at_vprintflf(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args);
extern void at_print_raw_cmd(const char *type, const char *cmd, rt_size_t size);

/**
Expand Down Expand Up @@ -342,6 +347,97 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
return result;
}

/**
* Send commands through custom formatting to AT server and wait response.
*
* @param client current AT client object
* @param resp AT response object, using RT_NULL when you don't care response
* @param format formatting macro, it can be one of these values: AT_END_CR_LF, AT_END_RAW, AT_END_CR, AT_END_LF.
* Behavior of AT_END_CR_LF is same as at_obj_exec_cmd, and it will add \r\n symnbol behind message.
* AT_END_RAW means frame work won't modify anything of message. AT_END_CR will add \r for Carriage
* Return. AT_END_LF means add \\n for Line Feed.
* @param cmd_expr AT commands expression
*
* @return 0 : success
* -1 : response status error
* -2 : wait timeout
* -7 : enter AT CLI mode
*/
int at_obj_exec_cmd_format(at_client_t client, at_response_t resp, const char* format, const char *cmd_expr, ...)
{
va_list args;
rt_err_t result = RT_EOK;

RT_ASSERT(cmd_expr);

if (client == RT_NULL)
{
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
return -RT_ERROR;
}

/* check AT CLI mode */
if (client->status == AT_STATUS_CLI && resp)
{
return -RT_EBUSY;
}

rt_mutex_take(client->lock, RT_WAITING_FOREVER);

client->resp_status = AT_RESP_OK;

if (resp != RT_NULL)
{
resp->buf_len = 0;
resp->line_counts = 0;
}

client->resp = resp;
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);

va_start(args, cmd_expr);

if (strcmp(format, AT_END_CR_LF) == 0)
{
client->last_cmd_len = at_vprintfln(client->device, client->send_buf, client->send_bufsz, cmd_expr, args);
}
else if (strcmp(format, AT_END_RAW) == 0)
{
client->last_cmd_len = at_vprintf(client->device, client->send_buf, client->send_bufsz, cmd_expr, args);
}
else if (strcmp(format, AT_END_CR) == 0)
{
client->last_cmd_len = at_vprintfcr(client->device, client->send_buf, client->send_bufsz, cmd_expr, args);
}
else if (strcmp(format, AT_END_LF) == 0)
{
client->last_cmd_len = at_vprintflf(client->device, client->send_buf, client->send_bufsz, cmd_expr, args);
}

va_end(args);

if (resp != RT_NULL)
{
if (rt_sem_take(client->resp_notice, resp->timeout) != RT_EOK)
{
LOG_W("execute command (%.*s) timeout (%d ticks)!", client->last_cmd_len, client->send_buf, resp->timeout);
client->resp_status = AT_RESP_TIMEOUT;
result = -RT_ETIMEOUT;
}
else if (client->resp_status != AT_RESP_OK)
{
LOG_E("execute command (%.*s) failed!", client->last_cmd_len, client->send_buf);
result = -RT_ERROR;
}
}

client->resp = RT_NULL;

rt_mutex_release(client->lock);

return result;
}

/**
* Waiting for connection to external devices.
*
Expand Down Expand Up @@ -775,7 +871,7 @@ static void client_parser(at_client_t client)
}
else
{
// log_d("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf);
/* log_d("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf);*/
}
}
}
Expand Down Expand Up @@ -997,4 +1093,4 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu

return result;
}
#endif /* AT_USING_CLIENT */
#endif /* AT_USING_CLIENT */
37 changes: 33 additions & 4 deletions components/net/at/src/at_utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -56,15 +56,13 @@ void at_print_raw_cmd(const char *name, const char *buf, rt_size_t size)
rt_kprintf("\n");
}
}

rt_weak rt_size_t at_utils_send(rt_device_t dev,
rt_off_t pos,
const void *buffer,
rt_size_t size)
{
return rt_device_write(dev, pos, buffer, size);
}

rt_size_t at_vprintf(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args)
{
rt_size_t len = vsnprintf(send_buf, buf_size, format, args);
Expand All @@ -79,7 +77,6 @@ rt_size_t at_vprintf(rt_device_t device, char *send_buf, rt_size_t buf_size, con

return at_utils_send(device, 0, send_buf, len);
}

rt_size_t at_vprintfln(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args)
{
rt_size_t len = vsnprintf(send_buf, buf_size - 2, format, args);
Expand All @@ -97,3 +94,35 @@ rt_size_t at_vprintfln(rt_device_t device, char *send_buf, rt_size_t buf_size, c

return at_utils_send(device, 0, send_buf, len);
}
rt_size_t at_vprintfcr(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args)
{
rt_size_t len = vsnprintf(send_buf, buf_size - 1, format, args);
if (len == 0)
{
return 0;
}

send_buf[len++] = '\r';

#ifdef AT_PRINT_RAW_CMD
at_print_raw_cmd("sendline", send_buf, len);
#endif

return at_utils_send(device, 0, send_buf, len);
}
rt_size_t at_vprintflf(rt_device_t device, char *send_buf, rt_size_t buf_size, const char *format, va_list args)
{
rt_size_t len = vsnprintf(send_buf, buf_size - 1, format, args);
if (len == 0)
{
return 0;
}

send_buf[len++] = '\n';

#ifdef AT_PRINT_RAW_CMD
at_print_raw_cmd("sendline", send_buf, len);
#endif

return at_utils_send(device, 0, send_buf, len);
}