1 如前贴所见,上手就碰了大墙。板载调试器没有啊,
怎么办,先从原理图扒一下,关键就在右侧的调试节点上了。可以通过RST和MD的组合控制,快速实现类似外设BOOT的的启动,这个是 启动一个可以访问boot 内存的USB CDC。
左侧也展示了可以外接JTAG调试器的解决方案,但是看起来这样板载调试器就不用工作了,而且应该断开 R54等电阻,这里接口么有焊接是DNP状态,不到没办法,就先不选择这个方案了。
#include <rtthread.h>
#include "hal_data.h"
#include <rtdevice.h>
#include <board.h>
#define DBG_TAG "led"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
/* 配置 LED 灯引脚 */
#define LED_PIN_R BSP_IO_PORT_00_PIN_13
#define LED_PIN_B BSP_IO_PORT_00_PIN_12
#define LED_PIN_G BSP_IO_PORT_06_PIN_13
/* 定义 LED 亮灭电平 */
#define LED_ON (0)
#define LED_OFF (1)
/* 定义 8 组 LED 闪灯表,其顺序为 R B G */
static const rt_uint8_t _blink_tab[][3] =
{
{LED_OFF, LED_OFF, LED_OFF},
{LED_ON, LED_OFF, LED_OFF},
{LED_OFF, LED_ON, LED_OFF},
{LED_OFF, LED_OFF, LED_ON},
{LED_ON, LED_OFF, LED_ON},
{LED_ON, LED_ON, LED_OFF},
{LED_OFF, LED_ON, LED_ON},
{LED_ON, LED_ON, LED_ON},
};
void hal_entry(void)
{
rt_kprintf("\nHello RT-Thread!\n");
rt_kprintf("==================================================\n");
rt_kprintf("This example project is an RGB flicker routine!\n");
rt_kprintf("==================================================\n");
unsigned int count = 0;
unsigned int group_num = sizeof(_blink_tab)/sizeof(_blink_tab[0]);
unsigned int group_current;
/* 设置 RGB 灯引脚为输出模式 */
rt_pin_mode(LED_PIN_R, PIN_MODE_OUTPUT);
rt_pin_mode(LED_PIN_G, PIN_MODE_OUTPUT);
rt_pin_mode(LED_PIN_B, PIN_MODE_OUTPUT);
rt_pin_write(LED_PIN_R, LED_OFF);
rt_pin_write(LED_PIN_G, LED_OFF);
rt_pin_write(LED_PIN_B, LED_OFF);
do
{
/* 获得组编号 */
group_current = count % group_num;
/* 控制 RGB 灯 */
rt_pin_write(LED_PIN_R, _blink_tab[group_current][0]);
rt_pin_write(LED_PIN_B, _blink_tab[group_current][1]);
rt_pin_write(LED_PIN_G, _blink_tab[group_current][2]);
/* 输出 LOG 信息 */
LOG_D("group: %d | red led [%-3.3s] | | blue led [%-3.3s] | | green led [%-3.3s]",
group_current,
_blink_tab[group_current][0] == LED_ON ? "ON" : "OFF",
_blink_tab[group_current][1] == LED_ON ? "ON" : "OFF",
_blink_tab[group_current][2] == LED_ON ? "ON" : "OFF");
count++;
/* 延时一段时间 */
rt_thread_mdelay(500);
}while(count > 0);
}
编译一下,迅速成功
效果如下
视频如下
5 小结
这个板子拿到手就给出了个题目,搞了一通,还好通过了。算是搞了一个出厂工序。加深了对于boot sequence的理解