diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\344\275\234\344\270\232/Kconfig" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\344\275\234\344\270\232/Kconfig" new file mode 100644 index 0000000000000000000000000000000000000000..168ac016a3c29ea4c361bf91997f77a617c68ad0 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\344\275\234\344\270\232/Kconfig" @@ -0,0 +1,203 @@ +menu "Hardware Drivers Config" + +config SOC_VEXPRESS_A9 + bool + select ARCH_ARM_CORTEX_A9 + select RT_USING_CACHE + select ARCH_ARM_MMU + select RT_USING_COMPONENTS_INIT + select RT_USING_USER_MAIN + select RT_USING_GIC_V2 + default y + +menu "Onboard Peripheral Drivers" + menuconfig BSP_USING_UART + bool "Enable UART" + default y + select RT_USING_SERIAL + if BSP_USING_UART + menuconfig BSP_USING_UART0 + bool "Enable UART0 (Debugger)" + default y + if BSP_USING_UART0 + config BSP_UART0_RX_BUFSIZE + int "Set UART0 RX buffer size" + range 64 65535 + depends on RT_USING_SERIAL_V2 + default 1024 + + config BSP_UART0_TX_BUFSIZE + int "Set UART0 TX buffer size" + range 0 65535 + depends on RT_USING_SERIAL_V2 + default 0 + endif + + menuconfig BSP_USING_UART1 + bool "Enable UART1" + default n + if BSP_USING_UART1 + config BSP_UART1_RX_BUFSIZE + int "Set UART1 RX buffer size" + range 64 65535 + depends on RT_USING_SERIAL_V2 + default 1024 + + config BSP_UART1_TX_BUFSIZE + int "Set UART1 TX buffer size" + range 0 65535 + depends on RT_USING_SERIAL_V2 + default 0 + endif + + menuconfig BSP_USING_UART2 + bool "Enable UART2" + default n + if BSP_USING_UART2 + config BSP_UART2_RX_BUFSIZE + int "Set UART2 RX buffer size" + range 64 65535 + depends on RT_USING_SERIAL_V2 + default 1024 + + config BSP_UART2_TX_BUFSIZE + int "Set UART2 TX buffer size" + range 0 65535 + depends on RT_USING_SERIAL_V2 + default 0 + endif + + menuconfig BSP_USING_UART3 + bool "Enable UART3" + default n + if BSP_USING_UART3 + config BSP_UART3_RX_BUFSIZE + int "Set UART3 RX buffer size" + range 64 65535 + depends on RT_USING_SERIAL_V2 + default 1024 + + config BSP_UART3_TX_BUFSIZE + int "Set UART3 TX buffer size" + range 0 65535 + depends on RT_USING_SERIAL_V2 + default 0 + endif + + endif + + config BSP_USING_LVGL + bool "Enable LVGL for LCD" + select PKG_USING_LVGL + select BSP_DRV_CLCD + select BSP_DRV_MOUSE + default n + + if BSP_USING_LVGL + config BSP_USING_LVGL_DEMO + bool "Enable LVGL demo" + select PKG_USING_LV_MUSIC_DEMO + default y + endif + + config BSP_DRV_CLCD + bool "CLCD driver" + select RT_USING_LCD + default n + + config BSP_DRV_MOUSE + bool "MOUSE driver" + default n + + if BSP_DRV_CLCD + config BSP_LCD_WIDTH + int "Width of LCD panel" + default 640 + + config BSP_LCD_HEIGHT + int "Height of LCD panel" + default 480 + endif + + config BSP_DRV_EMAC + bool "Enable EMAC driver" + select RT_USING_LWIP + select RT_USING_POSIX_FS + select RT_USING_POSIX_SOCKET + default n + + config BSP_DRV_AUDIO + bool "Audio driver" + select RT_USING_AUDIO + default n + + endmenu + +endmenu + +menu "MQTT Configuration" + + config MQTT_ENABLE + bool "Enable MQTT Client" + default y + select PKG_USING_KAWAII_MQTT + select PKG_USING_CJSON + help + Enable MQTT client functionality + + if MQTT_ENABLE + + config STUDENT_NAME + string "Student name" + default "yuanhaohua" + help + Name to include in MQTT messages + + config STUDY_CONTENT + string "Today's study" + default "Keep up the good work!" + help + What you learned today + + config MQTT_PUB_TOPIC + string "Publish Topic" + default "student/study" + + config MQTT_SUB_TOPIC + string "Subscribe Topic" + default "student/reply" + + config MQTT_BROKER_HOST + string "MQTT Broker Host" + default "broker.emqx.io" + + config MQTT_BROKER_PORT + string "MQTT Broker Port" + default "1883" + + config MQTT_CLIENT_ID + string "MQTT Client ID" + default "rtt_student" + + config MQTT_USERNAME + string "MQTT Username" + default "kenusten" + + config MQTT_PASSWORD + string "MQTT Password" + default "3055349835" + + config MQTT_THREAD_STACK_SIZE + int "MQTT Thread Stack Size" + default 4096 + help + Stack size for MQTT thread + + config MQTT_THREAD_PRIORITY + int "MQTT Thread Priority" + default 17 + help + Priority for MQTT thread + endif + +endmenu \ No newline at end of file diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\344\275\234\344\270\232/test.c" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\344\275\234\344\270\232/test.c" new file mode 100644 index 0000000000000000000000000000000000000000..0ded58d78f78dda6b5a55066fa147f5931776528 --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\344\275\234\344\270\232/test.c" @@ -0,0 +1,202 @@ + +/* + * @Author: jiejie + * @Github: https://github.com/jiejieTop + * @LastEditTime: 2020-06-17 14:35:29 + * @Description: the code belongs to jiejie, please keep the author information and source code according to the license. + */ +#include +#include +#include +#include +#include +#include "mqttclient.h" +#include + + +#ifndef STUDENT_NAME + #ifdef CONFIG_STUDENT_NAME + #define STUDENT_NAME CONFIG_STUDENT_NAME + #else + #define STUDENT_NAME "yuanhaohua" + #endif +#endif + +#ifndef STUDY_CONTENT + #ifdef CONFIG_STUDY_CONTENT + #define STUDY_CONTENT CONFIG_STUDY_CONTENT + #else + #define STUDY_CONTENT "Keep up the good work!" + #endif +#endif +// MQTT配置 +#ifdef CONFIG_MQTT_BROKER_HOST + #define KAWAII_MQTT_HOST CONFIG_MQTT_BROKER_HOST +#else + #define KAWAII_MQTT_HOST "broker.emqx.io" +#endif +#ifndef KAWAII_MQTT_HOST +#define KAWAII_MQTT_HOST "broker.emqx.io" +#endif +#ifndef KAWAII_MQTT_PORT +#define KAWAII_MQTT_PORT "1883" +#endif +#ifndef KAWAII_MQTT_CLIENTID +#define KAWAII_MQTT_CLIENTID "mqttx_be02e5be" +#endif +#ifndef KAWAII_MQTT_USERNAME +#define KAWAII_MQTT_USERNAME "kenusten" +#endif +#ifndef KAWAII_MQTT_PASSWORD +#define KAWAII_MQTT_PASSWORD "3055349835" +#endif +#ifndef KAWAII_MQTT_SUBTOPIC +#define KAWAII_MQTT_SUBTOPIC "rtt-sub" +#endif +#ifndef KAWAII_MQTT_PUBTOPIC +#define KAWAII_MQTT_PUBTOPIC "rtt-pub" +#endif + +static void sub_topic_handle(void* client, message_data_t* msg) +{ + (void) client; + KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------"); + KAWAII_MQTT_LOG_I("Received reply from server:"); + KAWAII_MQTT_LOG_I("Topic: %s", msg->topic_name); + KAWAII_MQTT_LOG_I("Message: 辛苦了,下周的比赛加油!"); + KAWAII_MQTT_LOG_I("-----------------------------------------------------------------------------------"); +} + +// 创建JSON格式的学习数据 +// static char* create_study_json(void) +// { +// cJSON *root = cJSON_CreateObject(); +// if (root == NULL) { +// KAWAII_MQTT_LOG_E("Failed to create JSON object"); +// return NULL; +// } + +// cJSON_AddStringToObject(root, "name", STUDENT_NAME); +// cJSON_AddStringToObject(root, "study", STUDY_CONTENT); + +// char *json = cJSON_PrintUnformatted(root); +// cJSON_Delete(root); + +// if (json == NULL) { +// KAWAII_MQTT_LOG_E("Failed to print JSON"); +// } + +// return json; +// } + +// 发布学习数据 +// static int mqtt_publish_study(mqtt_client_t *client) +// { +// char *json = create_study_json(); +// if (!json) { +// KAWAII_MQTT_LOG_E("Failed to create JSON"); +// return -1; +// } + +// mqtt_message_t msg; +// memset(&msg, 0, sizeof(msg)); +// msg.qos = QOS0; +// msg.payload = json; +// msg.payloadlen = strlen(json); + +// int rc = mqtt_publish(client, MQTT_PUB_TOPIC, &msg); + +// if (rc == 0) { +// KAWAII_MQTT_LOG_I("Published: %s", json); +// } else { +// KAWAII_MQTT_LOG_E("Publish failed: %d", rc); +// } + +// cJSON_free(json); // 使用cJSON的释放函数 + +// return rc; +// } + +// MQTT主任务 +static void student_mqtt_thread(void *parameter) +{ + mqtt_client_t *client = NULL; + + mqtt_log_init(); + client = mqtt_lease(); + + // 配置MQTT参数 + mqtt_set_host(client, KAWAII_MQTT_HOST); + mqtt_set_port(client, KAWAII_MQTT_PORT); + mqtt_set_user_name(client, MQTT_USERNAME); + mqtt_set_password(client, MQTT_PASSWORD); + mqtt_set_client_id(client, MQTT_CLIENT_ID); + mqtt_set_clean_session(client, 1); + + KAWAII_MQTT_LOG_I("Student MQTT Client: %s", MQTT_CLIENT_ID); + KAWAII_MQTT_LOG_I("Name: %s", STUDENT_NAME); + KAWAII_MQTT_LOG_I("Study: %s", STUDY_CONTENT); + + // 连接MQTT服务器 + if (mqtt_connect(client) != RT_EOK) { + KAWAII_MQTT_LOG_E("MQTT connect failed!"); + return; + } + + // 订阅回复主题 + mqtt_subscribe(client, MQTT_SUB_TOPIC, QOS0, sub_topic_handle); + KAWAII_MQTT_LOG_I("Subscribed to: %s", MQTT_SUB_TOPIC); + + // // 主循环:每10秒发送一次学习数据 + // while (1) { + // if (mqtt_publish_study(client) == 0) { + // KAWAII_MQTT_LOG_I("Data sent successfully"); + // } + + // // 处理MQTT消息 + // mqtt_keep_alive(client); + + // // 10秒间隔 + // mqtt_sleep_ms(10 * 1000); + // } +} + +// 初始化函数 +int student_mqtt_init(void) +{ + rt_thread_t tid; + + #ifdef CONFIG_MQTT_THREAD_STACK_SIZE + int stack_size = CONFIG_MQTT_THREAD_STACK_SIZE; + #else + int stack_size = 4096; + #endif + + #ifdef CONFIG_MQTT_THREAD_PRIORITY + int priority = CONFIG_MQTT_THREAD_PRIORITY; + #else + int priority = 17; + #endif + + tid = rt_thread_create("student_mqtt", + student_mqtt_thread, + RT_NULL, + stack_size, + priority, + 10); // 时间片 + + if (tid == RT_NULL) { + KAWAII_MQTT_LOG_E("Create MQTT thread failed!"); + return -RT_ERROR; + } + + rt_thread_startup(tid); + KAWAII_MQTT_LOG_I("Student MQTT client started"); + return RT_EOK; +} + +#ifdef CONFIG_MQTT_ENABLE + INIT_APP_EXPORT(student_mqtt_init); // 自动初始化 +#else + MSH_CMD_EXPORT(student_mqtt_init, Start Student MQTT Client); +#endif diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/4.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..3022c198b09598e534d161e771af8c4f8109cc24 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/4.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/74d6ca4c927ffc7c2e25ca5acadad55.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/74d6ca4c927ffc7c2e25ca5acadad55.png" new file mode 100644 index 0000000000000000000000000000000000000000..85f837ffe0502f5f66203ea5aecaf3daf82209a2 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/74d6ca4c927ffc7c2e25ca5acadad55.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/8f6cb6ef6bcd73ac0e385f4f99cb488.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/8f6cb6ef6bcd73ac0e385f4f99cb488.png" new file mode 100644 index 0000000000000000000000000000000000000000..930e649f1257653d4e0a779449564d17375f6800 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/8f6cb6ef6bcd73ac0e385f4f99cb488.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image1.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image1.png" new file mode 100644 index 0000000000000000000000000000000000000000..7e9e3f8e16d02de8b4f895075272b2a8d47b2335 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image1.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image10.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image10.png" new file mode 100644 index 0000000000000000000000000000000000000000..210027af3412e39a9fbf579ffaba63a5df1e8530 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image10.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image11.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image11.png" new file mode 100644 index 0000000000000000000000000000000000000000..3243069953175023a3066fb72fdd6f4375369197 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image11.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image2.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image2.png" new file mode 100644 index 0000000000000000000000000000000000000000..99fb4782ddedb1f04fe22ef998013f66487f0cd9 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image2.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image3.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image3.png" new file mode 100644 index 0000000000000000000000000000000000000000..0fd7b24d1b1b5c81ee9a3987ab2a02edcef17cbc Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image3.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image6.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image6.png" new file mode 100644 index 0000000000000000000000000000000000000000..41f57609a8d4fb0127c662620b89d06343551832 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image6.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image7.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image7.png" new file mode 100644 index 0000000000000000000000000000000000000000..ce29c80382daf7598e9b32c3daa5e1bb0cc38c6f Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image7.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image8.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image8.png" new file mode 100644 index 0000000000000000000000000000000000000000..af035455aacc83e5b47afda6de86da2398bd49b5 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image8.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image9.png" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image9.png" new file mode 100644 index 0000000000000000000000000000000000000000..210027af3412e39a9fbf579ffaba63a5df1e8530 Binary files /dev/null and "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/image9.png" differ diff --git "a/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260.md" "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..977c1e83fcab750f9b142aef08752dd3b5cf24cc --- /dev/null +++ "b/2025/\347\254\2543\347\273\204(PSoC62 evaluation Kit)/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260/\347\254\254\344\272\224\345\244\251\347\254\224\350\256\260.md" @@ -0,0 +1,280 @@ +# 笔记 + +## Kconfig文件的应用 + +C语言项目的裁剪配置本质上通过条件编译和宏的展开来实现的,RT-Thread借助Kconfig这套机制更方便的实现了这一功能。当前以Windows下Env工具中的使用为例,简述Kconfig在RT-Thread的工作机制。 + +Kconfig机制包括了Kconfig文件和配置UI界面(如menuconfig,pyconfig等)。Kconfig机制有如下特点: + +Kconfig文件中的配置项会映射至rtconfig.h中 +Kconfig文件可以随源码分散至各级子目录,便于灵活修改。 + + +``` +# .config片段 +CONFIG_RT_USING_TIMER_SOFT=y +CONFIG_RT_TIMER_THREAD_PRIO=4 +CONFIG_RT_TIMER_THREAD_STACK_SIZE=512 +CONFIG_RT_DEBUG=y + +``` + +``` +// 相对应的rtconfig.h片段 +#define RT_USING_TIMER_SOFT +#define RT_TIMER_THREAD_PRIO 4 +#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_DEBUG + +``` +![输入图片说明](image1.png) + +## Kconfig语法及示例 + +``` + +# 作为注释标记符 +``` + +### config语句 + +示例 + + +``` +config BSP_USING_GPIO + bool "Enable GPIO" + select RT_USING_PIN + default y + help + config gpio + +``` + +相当于告诉别人这个代码的一些信息 + +![输入图片说明](image2.png) + + +语句分析: + +config 表示一个配置选项的开始,紧跟着的 BSP_USING_GPIO 是配置选项的名称,config 下面几行定义了该配置选项的属性。 + +属性可以是该配置选项的 + +类型 + +输入提示 + +依赖关系 + +默认值 + +帮助信息 + +bool 表示配置选项的类型,每个 config 菜单项都要有类型定义,变量有5种类型 + +bool 布尔类型 + +tristate 三态类型 + +string 字符串 + +hex 十六进制 + +int 整型 + +select 是反向依赖关系的意思,即当前配置选项被选中,则 RT_USING_PIN 就会被选中。 + +default 表示配置选项的默认值,bool 类型的默认值可以是 y/n。 + +help 帮助信息。 + +通过 env 选中以上配置界面的选项后,最终可在 rtconfig.h 文件中生成如下两个宏 + +``` +#define RT_USING_PIN +#define BSP_USING_GPIO + +``` +## 变量类型 + +### bool类型 + +取值范围是 y/n + + +将配置项前面变成可手动配置和不可手动配置 + + +![输入图片说明](image3.png) + + +### string类型 + +默认值是一个字符串 + +![输入图片说明](4.png) + +### int类型 + +## menu/endmenu语句 + + +menu 语句用于生成菜单。 + +以下为 RT-Thread 系统中 menu/endmenu 语句的示例 + + +``` +menu "Hardware Drivers Config" + config BSP_USING_COM2 + bool "Enable COM2 (uart2 pin conflict with Ethernet and PWM)" + select BSP_USING_UART + select BSP_USING_UART2 + default n + config BSP_USING_COM3 + bool "Enable COM3 (uart3 pin conflict with Ethernet)" + select BSP_USING_UART3 + default n +endmenu + +``` +## if/endif语句 + + +``` +menu "Hardware Drivers Config" + menuconfig BSP_USING_CAN + bool "Enable CAN" + default n + select RT_USING_CAN + if BSP_USING_CAN + config BSP_USING_CAN1 + bool "Enable CAN1" + default n + endif +endmenu + +``` + +选中后后面的-->会显现出来 + +![输入图片说明](image6.png) + + +![输入图片说明](image7.png) + +![输入图片说明](image8.png) + +![输入图片说明](image9.png) + + +### choice/endchoice语句 + + +``` +menu "Hardware Drivers Config" + menuconfig BSP_USING_ONCHIP_RTC + bool "Enable RTC" + select RT_USING_RTC + select RT_USING_LIBC + default n + if BSP_USING_ONCHIP_RTC + choice + prompt "Select clock source" + default BSP_RTC_USING_LSE + + config BSP_RTC_USING_LSE + bool "RTC USING LSE" + + config BSP_RTC_USING_LSI + bool "RTC USING LSI" + endchoice + endif +endmenu + +``` + + +## comment语句 + +出现在界面的第一行,用于定义一些提示信息。 + +## SCons + +### 什么是构建工具(系统) + +构建工具 (software construction tool) 是一种软件,它可以根据一定的规则或指令,将源代码编译成可执行的二进制程序。这是构建工具最基本也是最重要的功能。实际上构建工具的功能不止于此,通常这些规则有一定的语法,并组织成文件。这些文件用来控制构建工具的行为,在完成软件构建之外,也可以做其他事情。 + +目前最流行的构建工具是 GNU Make。很多知名开源软件,如 Linux 内核就采用 Make 构建。Make 通过读取 Makefile 文件来检测文件的组织结构和依赖关系,并完成 Makefile 中所指定的命令。 + +由于历史原因,Makefile 的语法比较混乱,不利于初学者学习。此外在 Windows 平台上使用 Make 也不方便,需要安装 Cygwin 环境。为了克服 Make 的种种缺点,人们开发了其他构建工具,如 CMake 和 SCons 等。 + +### RT-Thread 构建工具 +RT-Thread 早期使用 Make/Makefile 构建。从 RT-Thread 0.3.0 开始,RT-Thread 开发团队逐渐引入了 SCons 构建系统,引入 SCons 唯一的目是:使大家从复杂的 Makefile 配置、IDE 配置中脱离出来,把精力集中在 RT-Thread 功能开发上。 + +有些读者可能会有些疑惑,这里介绍的构建工具与 IDE 有什么不同呢?IDE 通过图形化界面的操作来完成构建。大部分 IDE 会根据用户所添加的源码生成类似 Makefile 或 SConscript 的脚本文件,在底层调用类似 Make 或 SCons 的工具来构建源码。 + +### SCons 简介 +SCons 是一套由 Python 语言编写的开源构建系统,类似于 GNU Make。它采用不同于通常 Makefile 文件的方式,而是使用 SConstruct 和 SConscript 文件来替代。这些文件也是 Python 脚本,能够使用标准的 Python 语法来编写。所以在 SConstruct、SConscript 文件中可以调用 Python 标准库进行各类复杂的处理,而不局限于 Makefile 设定的规则。 + +### RT-Thread中Scons的脚本结构 +SCons 使用 SConscript 和 SConstruct 文件来组织源码结构并进行构建,SConstruct是scons构建的主脚本,SConscript存放在源代码的子目录下,通常放在项目的子目录,以达到分层构建的目的。一个项目 (BSP) 只有一 SConstruct,但是会有多个 SConscript。一般情况下,每个存放有源代码的子目录下都会放置一个 SConscript。 + + +``` +/ + -- rtconfig.py ---- 控制SCons构建的配置文件,存放了如工具链,构建参数等配置。 + -- SConscript + -- SConstruct ---- SCons的入口脚本,初始化了SCons构建rt-thread所需的必要环境 + -- Kconfig ---- 顶层Kconfig文件,menuconfig的入口Kconfig文件 + -- rt-thread/ + --- src/ + ---- SConscript ---- 各级源码的scons子脚本,控制当前级别下的源码构建行为 + ---- Kconfig ---- 各级源码的Kconfig子脚本,存放当前级别下的配置项 + ---- **.c + +``` +![输入图片说明](image10.png) + +RT-Thread当前的构建系统由以下几个部分组成 + + +``` +flowchart LR + A(RT-Thread构建系统)-->Kconfig + A(RT-Thread构建系统)-->rtconfig.py + A(RT-Thread构建系统)-->SCons + SCons --> SConscript + SCons --> SConstruct + SConscript --> Scons标准函数 + SConscript --> RT-Thread自定义函数 + SConscript --> Python函数 + +``` + +### SCons 基本命令 + + **scons** 直接编译工程 + + **scons -c** 清除编译目标 + + **scons --target=XXX** 争对具体文件进行编译 + + **scons -jN** 多线程编译目标 + + **scons --dist** 搭建项目框架 + + **scons --dist-ide** 可以将该BSP导出一份可以被 RT-Thread Studio 导入的工程文件夹,RT-Thread Studio 已经内置该功能,已无需手动敲这个命令。 + +## 网络搭建 + +下载netutils软件包 + +配置 + +![输入图片说明](8f6cb6ef6bcd73ac0e385f4f99cb488.png) + +![输入图片说明](74d6ca4c927ffc7c2e25ca5acadad55.png) +