RT-Thread 点LED, 顺便报RT Studio Reflash的BUG
1, 参见 @tlled 仁兄的帖子,做了一个LED点灯程序。
下载最新的RT Studio,导入SDK。
这个IDE 2.0已经做得很方便了,通过简单几个选项,模板化自动生成可以run的例程。
2,需要手工添加LED程序led.[c|h]
代码片断贴在这里,所有代码打包见附件。
led.h#ifndef LED_H_
#define LED_H_
#include <drv_gpio.h>
#define LED2_PIN GET_PIN(D, 13) // PD13
#define LED3_PIN GET_PIN(D, 14) // PD14
#define LED4_PIN GET_PIN(D, 15) // PD15
int led_init(int led);
int led_on(int led);
int led_off(int led);
int led_toggle(int led);
#endif // LED_H_
led.c
#include <rtdevice.h> // RT-Thread pin 设备需要包含此头文件
#include "led.h"
int led_init(int led)
{
/* LED 引脚为推挽输出模式 */
rt_pin_mode(led, PIN_MODE_OUTPUT);
return 0;
}
int led_on(int led)
{
/* API 输出低电平 */
rt_pin_write(led, PIN_LOW);
return 0;
}
int led_off(int led)
{
/* API 输出高电平 */
rt_pin_write(led, PIN_HIGH);
return 0;
}
int led_toggle(int led)
{
/* API 读出当前电平 然后输出相反电平 */
rt_pin_write(led, !rt_pin_read(led));
return 0;
}
当然还有main.c
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-01-28 RT-Thread first version
*/
#include <rtthread.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#include "led.h"
#if 0
int main(void)
{
int count = 1;
while (count++)
{
LOG_D("Hello RT-Thread!");
rt_thread_mdelay(1000);
}
return RT_EOK;
}
#else
int main(void)
{
int count = 1;
/* user app entry */
led_init(LED2_PIN);
led_init(LED3_PIN);
led_init(LED4_PIN);
led_on(LED2_PIN);
led_on(LED3_PIN);
led_on(LED4_PIN);
while (count++)
{
LOG_D("Hello RT, Red!");
led_toggle(LED2_PIN);
rt_thread_mdelay(500);
LOG_D("Hello RT, Yellow!");
led_toggle(LED3_PIN);
rt_thread_mdelay(500);
LOG_D("Hello RT, Green!");
led_toggle(LED4_PIN);
rt_thread_mdelay(1000);
LOG_D("Hello RT-Thread! Next One!");
}
return RT_EOK;
}
#endif
3,在Download Reflash的过程中,确实发现第一次Download成功之后,无法继续Download的情况,
多次试验后,发现和Erase过程强相关,感觉是Erease memory没有处理干净。
start download flash :2021-01-28 15:47:16
D:\RT-ThreadStudio>cd /d D:\RT-ThreadStudio\repo\Extract\Debugger_Support_Packages\RealThread\PyOCD\0.1.1
D:\RT-ThreadStudio\repo\Extract\Debugger_Support_Packages\RealThread\PyOCD\0.1.1>pyocd.exe flash --target=AT32F407VGT7 --erase=auto --frequency=1000000 D:\RT-ThreadStudio\workspace\at32f407vgt7\at32f407vgt7_hello\Debug\rtthread.bin
[---|---|---|---|---|---|---|---|---|----]
0003626:CRITICAL:__main__:program_page(0x0) error: 1
Traceback (most recent call last):
File "pyocd\__main__.py", line 362, in run
File "pyocd\__main__.py", line 527, in do_flash
File "pyocd\flash\file_programmer.py", line 158, in program
File "pyocd\flash\loader.py", line 168, in commit
File "pyocd\flash\builder.py", line 470, in program
File "pyocd\flash\builder.py", line 908, in _sector_erase_program_double_buffer
pyocd.core.exceptions.FlashProgramFailure: program_page(0x0) error: 1
[==================
completed, elapse time :5797ms.
只能通过别的过程把Flash擦除干净之后,才能正常下载。
4,另外一个问题是编译返回码错误,编译成功了,返回值(-1)
16:39:47 **** Incremental Build of configuration Debug for project at32f407vgt7_hello ****
make -j4 all
arm-none-eabi-size --format=berkeley "rtthread.elf"
text
|