找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 386|回复: 0
打印 上一主题 下一主题
收起左侧

CH32V307移植RT-THREAD操作系统

[复制链接]
跳转到指定楼层
楼主
CH32V307是款国产的基于CORTEX-M4的高性能32位单片机,本例程在CH32V307单片机上移植RT-THREAD操作系统,正常运行。
以下是工程目录:


以下是主文件所在目录:


以下是部分代码显示:
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name          : main.c
  3. * Author             : WCH
  4. * Version            : V1.0.0
  5. * Date               : 2020/04/30
  6. * Description        : Main program body.
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/
  12. #include "ch32v30x.h"
  13. #include <rtthread.h>
  14. #include <rthw.h>
  15. #include "drivers/pin.h"

  16. /* Global typedef */

  17. /* Global define */

  18. /* LED0 is driven by the pin driver interface of rt  */
  19. #define LED0_PIN  18   //PC3

  20. /* Global Variable */

  21. /*********************************************************************
  22. * @fn      LED1_BLINK_INIT
  23. *
  24. * @brief   LED1 directly calls the underlying driver
  25. *
  26. * @return  none
  27. */
  28. void LED1_BLINK_INIT(void)
  29. {
  30.     GPIO_InitTypeDef GPIO_InitStructure={0};
  31.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  32.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  33.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  34.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  35.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  36. }

  37. /*********************************************************************
  38. * @fn      main
  39. *
  40. * @brief   main is just one of the threads, in addition to tshell,idle
  41. * This main is just a flashing LED, the main thread is registered in
  42. * rtthread_startup, tshell uses the serial port to receive interrupts,
  43. * and the interrupt stack and thread stack are used separately.
  44. *
  45. * @return  none
  46. */
  47. int main(void)
  48. {
  49.     rt_kprintf("\r\n MCU: CH32V307\r\n");
  50.     SystemCoreClockUpdate();
  51.         rt_kprintf(" SysClk: %dHz\r\n",SystemCoreClock);
  52.         rt_kprintf(" ChipID: %08x\r\n",DBGMCU_GetCHIPID());
  53.     rt_kprintf(" wwwwchcn\r\n");
  54.         LED1_BLINK_INIT();

  55.         GPIO_ResetBits(GPIOA,GPIO_Pin_0);
  56.         while(1)
  57.         {
  58.             GPIO_SetBits(GPIOA,GPIO_Pin_0);
  59.             rt_thread_mdelay(500);
  60.             GPIO_ResetBits(GPIOA,GPIO_Pin_0);
  61.             rt_thread_mdelay(500);
  62.         }
  63. }

  64. /*********************************************************************
  65. * @fn      led
  66. *
  67. * @brief   Test using the driver interface to operate the I/O port
  68. *
  69. * @return  none
  70. */
  71. int led(void)
  72. {
  73.     rt_uint8_t count;

  74.     rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
  75.     printf("led_SP:%08x\r\n",__get_SP());
  76.     for(count = 0 ; count < 10 ;count++)
  77.     {
  78.         rt_pin_write(LED0_PIN, PIN_LOW);
  79.         rt_kprintf("led on, count : %d\r\n", count);
  80.         rt_thread_mdelay(500);

  81.         rt_pin_write(LED0_PIN, PIN_HIGH);
  82.         rt_kprintf("led off\r\n");
  83.         rt_thread_mdelay(500);
  84.     }
  85.     return 0;
  86. }

  87. MSH_CMD_EXPORT(led,  led sample by using I/O drivers);
复制代码
原理图: 无
仿真: 无
代码: RT-Thread.7z (101.89 KB, 下载次数: 3)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表