【ESP32学习笔记】esp32-c3官方例程freertos 新建和合并 ble gatt ,ledc_fade 三个例程工程合并,手机ble蓝牙调试传输变量控制led

1. 新建freertos例程合并ble gatt 和ledc

利用vscode idf 插件,新建一个 pytest_freertos_real_time_stats的例程工程,

然后用idf.py -C components create-component led 创建新组件,

将/home/djx/esp/gatt_server_service_table 工程的demo.c 全部赋值到新组件.c文件内,改掉app_main函数名,到主app_main内调用

在CMakeLists.txt 处,添加

idf_component_register(SRCS “gatt_server.c”
REQUIRES driver
PRIV_REQUIRES nvs_flash bt
INCLUDE_DIRS “include”)
在这里插入图片描述
修改app_mai名字位对应主函数调用的名字,

直接build,会报错,

Component config → Bluetooth → Bluedroid Options 下把 Enable BLE 4.2 features 打开。

这个问题,其实你可以自己反向推出来:
1、esp_ble_gap_start_advertising 在文件 esp_gap_ble_api.c 内
2、esp_ble_gap_start_advertising 被 #if (BLE_42_FEATURE_SUPPORT == TRUE) 包着
3、然后再追 BLE_42_FEATURE_SUPPORT,可以知道其依赖于 CONFIG_BT_BLE_42_FEATURES_SUPPORTED
4、搜索 BT_BLE_42_FEATURES_SUPPORTED 可以找到 Kconfig,你就知道是哪个配置项要打开

idf.py menuconfig 把4.2勾上
在build 就编译OK了
串口打印如下:可以正常连接ble,说明BT任务已经在后台跑起来,

ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
Saved PC:0x403806bc
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1738
load:0x403cc710,len:0xb9c
load:0x403ce710,len:0x2e40
entry 0x403cc71a
I (35) boot: ESP-IDF v5.2.1 2nd stage bootloader
I (35) boot: compile time May 7 2024 11:39:13
I (35) boot: chip revision: v0.4
I (38) boot.esp32c3: SPI Speed : 80MHz
I (43) boot.esp32c3: SPI Mode : DIO
I (48) boot.esp32c3: SPI Flash Size : 2MB
I (52) boot: Enabling RNG early entropy source…
I (58) boot: Partition Table:
I (61) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (91) boot: End of partition table
I (95) esp_image: segment 0: paddr=00010020 vaddr=3c0a0020 size=242a8h (148136) map
I (127) esp_image: segment 1: paddr=000342d0 vaddr=3fc91000 size=023a8h ( 9128) load
I (129) esp_image: segment 2: paddr=00036680 vaddr=40380000 size=09998h ( 39320) load
I (140) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=945d4h (607700) map
I (236) esp_image: segment 4: paddr=000d45fc vaddr=40389998 size=0762ch ( 30252) load
I (247) boot: Loaded app from partition at offset 0x10000
I (247) boot: Disabling RNG early entropy source…
I (259) cpu_start: Unicore app
I (267) cpu_start: Pro cpu start user code
I (267) cpu_start: cpu freq: 160000000 Hz
I (267) cpu_start: Application information:
I (270) cpu_start: Project name: esp32_led_ble
I (276) cpu_start: App version: ffb3d31-dirty
I (281) cpu_start: Compile time: May 7 2024 11:49:28
I (287) cpu_start: ELF file SHA256: afdd33fec…
I (293) cpu_start: ESP-IDF: v5.2.1
I (298) cpu_start: Min chip rev: v0.3
I (302) cpu_start: Max chip rev: v1.99
I (307) cpu_start: Chip rev: v0.4
I (312) heap_init: Initializing. RAM available for dynamic allocation:
I (319) heap_init: At 3FC97DE0 len 00028220 (160 KiB): RAM
I (325) heap_init: At 3FCC0000 len 0001C710 (113 KiB): Retention RAM
I (332) heap_init: At 3FCDC710 len 00002950 (10 KiB): Retention RAM
I (339) heap_init: At 50000010 len 00001FD8 (7 KiB): RTCRAM
I (346) spi_flash: detected chip: generic
I (350) spi_flash: flash io: dio
W (354) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (368) sleep: Configure to isolate all GPIO pins in sleep state
I (374) sleep: Enable automatic switching of GPIO sleep configuration
I (381) coexist: coex firmware version: 77cd7f8
I (386) coexist: coexist rom version 9387209
I (392) main_task: Started on CPU0
I (392) main_task: Calling app_main()
I (402) BLE_INIT: BT controller compile version [30b57c4]
I (402) BLE_INIT: Bluetooth MAC: f0:f5:bd:90:06:9e
I (412) phy_init: phy_version 1150,7c3c08f,Jan 24 2024,17:32:21
I (462) GATTS_TABLE_DEMO: create attribute table successfully, the number handle = 8
I (472) GATTS_TABLE_DEMO: SERVICE_START_EVT, status 0, service_handle 40
I (472) GATTS_TABLE_DEMO: advertising start successfully

Getting real time stats over 100 ticks
I (612) main_task: Returned from app_main()
| Task | Run Time | Percentage
| stats | 1163 | 0%
| spin1 | 175364 | 17%
| spin0 | 175510 | 17%
| IDLE | 646573 | 64%
| esp_timer | 127 | 0%
| hciT | 0 | 0%
| BTU_TASK | 0 | 0%
| BTC_TASK | 0 | 0%
| btController | 843 | 0%
| Tmr Svc | 0 | 0%
| main | Deleted
Real time stats obtained

ledc_fade例程类似的添加组件方法,然后把ledc_fade的app_main改名放在spin_task 任务函数中

static void spin_task(void *arg)
{
xSemaphoreTake(sync_spin_task, portMAX_DELAY);
ledc_fade();
// while (1) {
// //Consume CPU cycles
// for (int i = 0; i < SPIN_ITER; i++) {
// asm volatile(“NOP”);
// }
// vTaskDelay(pdMS_TO_TICKS(100));
// }
}

    xTaskCreatePinnedToCore(spin_task, task_names[i], 2048, NULL, SPIN_TASK_PRIO, NULL, tskNO_AFFINITY);

需要增加ulStackDepth 深度到2048 ,1024深度会使得堆栈溢出,

2 修改gatt_server.c的代码,读取接收到的数据,

可以单独去,gatt_server 调试,调试OK,在移植到主工程中

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要下载ESP32-C3-LCD-EV板的示例程序,你可以按照以下步骤进行操作: 1. 首先,打开ESP32-C3-LCD-EV板的官方网站,通常可以在开发板的制造商网站或者ESP32官方网站上找到。 2. 在官方网站上,找到关于ESP32-C3-LCD-EV板的页面或者单独的板支持页面。这个页面通常会提供板的相关信息、规格和下载链接。 3. 查询页面上是否有与板子配套使用的IDE或者开发环境。如果有,下载并安装它们。 4. 在官方网站的页面上查找示例程序的下载链接。它们通常会以压缩文件的形式提供,可以点击链接进行下载。 5. 下载示例程序后,解压缩文件到你选择的位置。确保你已经安装了所需的开发环境,以便能够打开和编辑这些示例程序。 6. 打开解压缩后的示例程序文件夹,并查找一个入口文件(通常命名为main.c或者main.ino)。这是一个示例程序的主文件,你可以在此基础上进行修改和调试。 7. 使用你的IDE或者开发工具打开入口文件,然后将板子连接到电脑上。通常需要使用USB线缆将ESP32-C3-LCD-EV板连至电脑。 8. 在IDE或者开发工具中选择合适的开发设备(通常是ESP32系列)和端口(通常是USB端口),然后编译并烧录示例程序到板子上。 9. 编译和烧写完成后,断开ESP32-C3-LCD-EV板与电脑的连接,然后重新连接板子供电。 10. 示范程序应该会开始在板子上运行,你可以观察板子上的LCD显示屏或者其他指示灯来确认是否成功下载和运行了示例程序。 以上就是下载ESP32-C3-LCD-EV板示例程序的一般步骤。具体步骤可能因为开发环境、操作系统和板子的不同而有所差异。如果在下载或者使用示例程序的过程中遇到问题,建议参考官方文档、开发者社区或者相关论坛寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值