找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 1713|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

CH32V307移植RT-THREAD操作系統(tǒng)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
CH32V307是款國(guó)產(chǎn)的基于CORTEX-M4的高性能32位單片機(jī),本例程在CH32V307單片機(jī)上移植RT-THREAD操作系統(tǒng),正常運(yùn)行。
以下是工程目錄:


以下是主文件所在目錄:


以下是部分代碼顯示:
  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);
復(fù)制代碼
原理圖: 無(wú)
仿真: 無(wú)
代碼: RT-Thread.7z (101.89 KB, 下載次數(shù): 5)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表