[活动专区] 【AT-START-F407测评】RT-Thread 点LED, 顺便报RT Studio Reflash的BUG

[复制链接]
 楼主| 大头哥 发表于 2021-1-28 16:49 | 显示全部楼层 |阅读模式
    RT-Thread 点LED, 顺便报RT Studio Reflash的BUG
    1, 参见 @tlled 仁兄的帖子,做了一个LED点灯程序。
       下载最新的RT Studio,导入SDK。
       这个IDE 2.0已经做得很方便了,通过简单几个选项,模板化自动生成可以run的例程。

    2,需要手工添加LED程序led.[c|h]
       代码片断贴在这里,所有代码打包见附件。
led.h
  1. #ifndef LED_H_
  2. #define LED_H_

  3. #include <drv_gpio.h>

  4. #define LED2_PIN        GET_PIN(D,  13) // PD13
  5. #define LED3_PIN        GET_PIN(D,  14) // PD14
  6. #define LED4_PIN        GET_PIN(D,  15) // PD15

  7. int led_init(int led);

  8. int led_on(int led);

  9. int led_off(int led);

  10. int led_toggle(int led);

  11. #endif // LED_H_



led.c

  1. #include <rtdevice.h>  // RT-Thread pin 设备需要包含此头文件
  2. #include "led.h"

  3. int led_init(int led)
  4. {
  5.     /* LED 引脚为推挽输出模式  */
  6.     rt_pin_mode(led, PIN_MODE_OUTPUT);
  7.     return 0;
  8. }

  9. int led_on(int led)
  10. {
  11.     /* API 输出低电平 */
  12.     rt_pin_write(led, PIN_LOW);
  13.     return 0;
  14. }

  15. int led_off(int led)
  16. {
  17.     /* API 输出高电平 */
  18.     rt_pin_write(led, PIN_HIGH);
  19.     return 0;
  20. }

  21. int led_toggle(int led)
  22. {
  23.     /* API 读出当前电平 然后输出相反电平 */
  24.     rt_pin_write(led, !rt_pin_read(led));
  25.     return 0;
  26. }

当然还有main.c
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date           Author       Notes
  8. * 2021-01-28     RT-Thread    first version
  9. */

  10. #include <rtthread.h>

  11. #define DBG_TAG "main"
  12. #define DBG_LVL DBG_LOG
  13. #include <rtdbg.h>

  14. #include "led.h"

  15. #if 0
  16. int main(void)
  17. {
  18.     int count = 1;

  19.     while (count++)
  20.     {
  21.         LOG_D("Hello RT-Thread!");
  22.         rt_thread_mdelay(1000);
  23.     }

  24.     return RT_EOK;
  25. }

  26. #else
  27. int main(void)
  28. {
  29.     int count = 1;

  30.     /* user app entry */
  31.     led_init(LED2_PIN);
  32.     led_init(LED3_PIN);
  33.     led_init(LED4_PIN);

  34.     led_on(LED2_PIN);
  35.     led_on(LED3_PIN);
  36.     led_on(LED4_PIN);

  37.     while (count++)
  38.     {
  39.         LOG_D("Hello RT, Red!");
  40.         led_toggle(LED2_PIN);
  41.         rt_thread_mdelay(500);

  42.         LOG_D("Hello RT, Yellow!");
  43.         led_toggle(LED3_PIN);
  44.         rt_thread_mdelay(500);

  45.         LOG_D("Hello RT, Green!");
  46.         led_toggle(LED4_PIN);
  47.         rt_thread_mdelay(1000);

  48.         LOG_D("Hello RT-Thread! Next One!");
  49.     }
  50.     return RT_EOK;
  51. }
  52. #endif


    3,在Download Reflash的过程中,确实发现第一次Download成功之后,无法继续Download的情况,
       多次试验后,发现和Erase过程强相关,感觉是Erease memory没有处理干净

  1.     start download flash :2021-01-28 15:47:16
  2.     D:\RT-ThreadStudio>cd /d D:\RT-ThreadStudio\repo\Extract\Debugger_Support_Packages\RealThread\PyOCD\0.1.1
  3.     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
  4.     [---|---|---|---|---|---|---|---|---|----]
  5.     0003626:CRITICAL:__main__:program_page(0x0) error: 1
  6.     Traceback (most recent call last):
  7.       File "pyocd\__main__.py", line 362, in run
  8.       File "pyocd\__main__.py", line 527, in do_flash
  9.       File "pyocd\flash\file_programmer.py", line 158, in program
  10.       File "pyocd\flash\loader.py", line 168, in commit
  11.       File "pyocd\flash\builder.py", line 470, in program
  12.       File "pyocd\flash\builder.py", line 908, in _sector_erase_program_double_buffer
  13.     pyocd.core.exceptions.FlashProgramFailure: program_page(0x0) error: 1
  14.     [==================
  15.     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
 楼主| 大头哥 发表于 2021-1-28 16:52 | 显示全部楼层
5,最后,RT点亮的RYG三色灯是这样的?串口输出一并贴出。

LED

LED

COM

COM
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

57

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部