在前面第二步的时候,其实已经实践了hello world的例子。现在回顾一下

ESP-IDF里hello world的例子

配好环境变量

进入esp-idf目录,执行

cd ~/esp/esp-idf

. ./export.sh

将例子cp到一个目录并编译

cd ~/esp

cp -r ~/esp/esp-idf/example/get-start/hello_world ~/esp/

idf.py build

上传并查看输出

烧录

idf.py /dev/cu.usbmodem58FC0414401 flash

查看输出

idf.py -p /dev/cu.usbmodem58FC0414401 monitor 

蓝牙例子

将例子cp到一个目录并编译

cd ~/esp

cp -r ~/esp/esp-idf/examples/bluetooth/hci/controller_hci_uart_esp32c3_and_esp32s3 ~/esp/

idf.py build

目录/esp/controller_hci_uart_esp32c3_and_esp32s3

理论上编译后烧录即可,实际碰到了板子一直报错的问题,本次实践失败告终。

总结

不明白为什么会烧录失败。在经过几天的折腾后,成功将esp32c3开发板折腾坏,也就是不停的报错:大约是rom或ram的读取错误。

以为把它玩坏了,后来到Windows下重新烧录了固件,开发板就起死回生了。

目前得出的结论就是:在Mac下烧录固件有问题,不清楚是不是乐鑫esp-idf在本人的Mac系统里没有装好导致的。也有可能是开发板型号没有选好导致的。Windows下烧录固件没有问题。

后来为了开发方便,烧录了MicroPython环境,学习调试起来就更方便了。

MicroPython下连蓝牙见:

esp32c3开发板通过micropython的ubluetooth库连蓝牙设备-CSDN博客

调试

蓝牙例子编译报错ninja: build stopped: subcommand failed.

Bootloader binary size 0x6880 bytes. 0x780 bytes (7%) free.

ninja: build stopped: subcommand failed.

ninja failed with exit code 1, output of the command is in the /Users/skywalk/esp/controller_hci_uart_esp32c3_and_esp32s3/build/log/idf_py_stderr_output_29752 and /Users/skywalk/esp/controller_hci_uart_esp32c3_and_esp32s3/build/log/idf_py_stdout_output_29752

再次执行,查看报错:

/Users/skywalk/esp/controller_hci_uart_esp32c3_and_esp32s3/main/main.c:35:65: error: unknown type name 'esp_bt_hci_tl_callback_t'; did you mean 'esp_vhci_host_callback_t'?

   35 | static void hci_uart_tl_recv_async(uint8_t *buf, uint32_t size, esp_bt_hci_tl_callback_t callback, void *arg);

      |                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~

      |                                                                 esp_vhci_host_callback_t

/Users/skywalk/esp/controller_hci_uart_esp32c3_and_esp32s3/main/main.c:36:65: error: unknown type name 'esp_bt_hci_tl_callback_t'; did you mean 'esp_vhci_host_callback_t'?

   36 | static void hci_uart_tl_send_async(uint8_t *buf, uint32_t size, esp_bt_hci_tl_callback_t callback, void *arg);

      |                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~

      |                                                                 esp_vhci_host_callback_t

哦哦, 原来是没有设置对开发板类型啊,设置:

idf.py set-target esp32c3

 然后编译,编译通过。

烧录时报错

Serial port /dev/cu.usbmodem58FC0414401

Connecting....

Chip is ESP32-C3 (QFN32) (revision v0.4)

Features: WiFi, BLE

Crystal is 40MHz

MAC: e4:b0:63:22:df:68

Uploading stub...

A fatal error occurred: Failed to write to target RAM (result was 01070000: Operation timed out)

CMake Error at run_serial_tool.cmake:66 (message):

  

  /Users/skywalk/.espressif/python_env/idf5.3_py3.11_env/bin/python;;/Users/skywalk/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32c3

  failed.

FAILED: CMakeFiles/flash /Users/skywalk/esp/controller_hci_uart_esp32c3_and_esp32s3/build/CMakeFiles/flash

不明白为什么会烧录失败。在经过几天的折腾后,成功将esp32c3开发板折腾坏,也就是不停的报错:大约是rom或ram的读取错误。

以为把它玩坏了,后来到Windows下重新烧录了固件,开发板就起死回生了。

目前得出的结论就是:在Mac下烧录固件有问题,不清楚是不是乐鑫esp-idf在Mac没有装好导致的。也有可能是开发板型号没有选好导致的。Windows下烧录固件没有问题。

后来为了开发方便,烧录了MicroPython环境,学习调试起来就更方便了。

MicroPython下连蓝牙见:

esp32c3开发板通过micropython的ubluetooth库连蓝牙设备-CSDN博客 

更多推荐