3回答

0收藏

[分享] 移植uTenux操作系统到GD32F207ZE小红板

GD32 GD32 4770 人阅读 | 3 人回复 | 2016-02-24

本帖最后由 lvhuayi 于 2016-2-24 15:34 编辑

   首先感谢这次由爱板网等相关各方赞助并发起的GD32设计大赛活动。GD32系列MCU作为较罕见的国产MCU产品表现出了很高的品质,特别是GD32F207ZET6芯片为基于Cortex-M3内核的通用MCU属于一款较高端的产品。
   目前国产的RTOS更是百花齐放,既有本次活动的发起者之一trochiliOS,还有RT-Thread、SylixOS、djyos、raw-os、uTenux等等。在这里选择了uTenux移植到小红板。
   uTenux实时操作系统是由大连悠龙软件公司以基于TRON标准的T-Kernel精简版本uT/Kernel为核心开发的,主要针对ARM系列微控制器从ARM7/9Cortex M系列。在大连悠龙的官网上有关于uTenux的具体介绍,这里不再过多说明。
   接下来,对uTenux的移植进行介绍。
   根据GD32F207ZE小红板自带的软件(GD32-Colibri-F207ZE-DEMO)我们看到其已经对小红板的leduartkey等给出了BSP(目录board中),因此这对方便我们移植起到了帮助。本次移植要实现led点亮和uart打印输出的功能以帮助测试uTenux
       悠龙公司官网下载uTenux的源码包,目前最新版的uTenuxV2.0.00r400版,本移植工作就是针对这一版本进行。解压下载的源码包,可以在其中看到有uTenux的内核文件(source)、说明文件(manual)、代码示例(sample)等多个文件夹。其中uTenux与具体芯片无关的内核文件位于目录/source/uTenux/uTOS中,可将其整体复制到准备新建的工程中使用。
      采用Keil MDK 5.16a工具进行移植开发工作。建立的文件目录如图所示,其中
uTOS中存放为上述的uTenux与具体芯片无关的内核文件;
Obj中为建立的keil工程文件;
GD32F207ZET6中为小红板的所有硬件相关文件;
App中为用户主程序和任务应用程序;
   实现uTenux在小红板上的移植主要是对tk_config_depend.h、tm_monitor.c和startup_gd32f20x.s三个文件进行修改。
   tk_config_depend.h中定义了所移植芯片的一些参数,以及对uTenux的配置参数,具体设置可以参考文件《uTOS内核移植指南_uTenux_uTOS_Porting_Guide_C》;
  1. #ifndef __TK_CONFIG_DEPEND_H__
  2. #define __TK_CONFIG_DEPEND_H__

  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif

  6. /*
  7. * Vector ROM region definition, must be same as with startup code.
  8. */
  9. #define TK_ROM_VECTORAREA_TOP     0x08000000UL   /* ROM VCETOR table start      */
  10. #define TK_ROM_VECTORAREA_END     0x080001A8UL   /* ROM VCETOR table end   418B */
  11. #define TK_ROM_VECTOR_NUMBER              106U   /* ROM VCETOR table size       */

  12. /*
  13. * Kernel RAM region definition, ram region defined in link script must be same.
  14. */
  15. #define TK_RAM_TOTALAREA_TOP      0x20000000UL   /* Total Internal RAM start    */
  16. #define TK_RAM_VECTORAREA_TOP     0x20000000UL   /* RAM VCETOR table start      */
  17. #define TK_RAM_VECTORAREA_END     0x200001A8UL   /* RAM VCETOR table end   0.4K */
  18. #define TK_RAM_BSSDATAAREA_TOP    0x200001A8UL   /* Bss and Data area start     */
  19. #define TK_RAM_BSSDATAAREA_END    0x20002000UL   /* Bss and Data area end  7.6k */
  20. #define TK_RAM_SYSTEMAREA_TOP     0x20002000UL   /* Kernel malloc area start    */
  21. #define TK_RAM_SYSTEMAREA_END     0x20012000UL   /* Kernel malloc area end  64k */
  22. #define TK_RAM_USERAREA_TOP       0x20012000UL   /* User manual area start      */
  23. #define TK_RAM_USERAREA_END       0x20020000UL   /* User manual area end    56k */
  24. #define TK_RAM_STACKAREA_TOP      0x20020000UL   /* Stack startup area start    */
  25. #define TK_RAM_STACKAREA_END      0x20020000UL   /* Stack startup area end   0k */
  26. #define TK_RAM_TOTALAREA_END      0x20020000UL   /* Total Internal RAM end 128k */
  27. #define TK_RAM_VECTOR_NUMBER              106U   /* RAM VCETOR table size       */

  28. /*
  29. * Use Chip Deep Sleep ( Stop and Standby ) function
  30. */
  31. #define TK_USE_POW_DEEP           0U             /* 0:Disable 1:Enable */

  32. /*
  33. * Kernel tick source timer clock function and definition
  34. */
  35. #define TK_USE_SYSTICK_LESS       0U             /* 0: use systick, 1: use other timer */
  36. #define KNL_CFG_TIMER_CLOCK       72U           /* Timer clock input(MHz)?ê?select MCK */
  37. #define KNL_CFG_TIMER_INTLEVEL    0U             /* Timer interrupt level */
  38. #define KNL_CFG_TIMER_PERIOD      10U            /* Timer period(ms), between 1 and 50 */
  39.   
  40. /*
  41. *  System object number config
  42. */
  43. #define KNL_CFG_MAX_TSKID         8
  44. #define KNL_CFG_MAX_SEMID         4
  45. #define KNL_CFG_MAX_FLGID         4
  46. #define KNL_CFG_MAX_MBXID         2
  47. #define KNL_CFG_MAX_MTXID         2
  48. #define KNL_CFG_MAX_MBFID         2
  49. #define KNL_CFG_MAX_PORID         2
  50. #define KNL_CFG_MAX_MPLID         2
  51. #define KNL_CFG_MAX_MPFID         2
  52. #define KNL_CFG_MAX_CYCID         2
  53. #define KNL_CFG_MAX_ALMID         2

  54. /*
  55. * Task priority config
  56. */
  57. #define KNL_CFG_MAX_PRI           16U                        /* Large means low priority */

  58. /*
  59. * Use dynamic memory allocation when kernel init
  60. */
  61. #define TK_USE_MALLOC             1U

  62. /*
  63. * Use dynamic exception and high level programming language handler support define
  64. */
  65. #define TK_USE_INT_DEFHDR         1U             /* Dynamic exception handler support */
  66. #define TK_USE_INT_HLLHDR         1U             /* High level program language support*/

  67. /*
  68. * Use FPU for active FPU function
  69. */
  70. #define TK_USE_FPU                0U             /* 0:Disable 1:Enable */

  71. /*
  72. * Use clean-up sequence when kernel exit
  73. */
  74. #define KNL_CFG_USE_CLEANUP       1U

  75. /*
  76. * Debugger support function
  77. *   0: Invalid
  78. *   1: Valid
  79. */
  80. #define TK_USE_DBGSPT             0U

  81. /*
  82. * Use program trace function (in debugger support)
  83. */
  84. #define TK_USE_HOOK_TRACE         0U

  85. /*
  86. * Use object name to each control block
  87. *   0: Do not use object name
  88. *   1: Use object name
  89. */
  90. #define TK_USE_OBJ_NAME           1U
  91. #define TK_OBJ_NAME_LENGTH        8U             /* Object name length (Byte) */

  92. /*
  93. * Use tm_monitor to output kernel message
  94. */
  95. #define TK_USE_TM_MONITOR         1U

  96. /*
  97. * Output (error) messages from Kernel
  98. *   0: Do not output message
  99. *   1: Output message
  100. */
  101. #define TK_USE_MESSAGE            1U

  102. /*
  103. * Predefined boot message
  104. */
  105. #define KNL_CFG_BOOT_MESSAGE \
  106.             "\n" \
  107.             "-------------------------------------------------------\n" \
  108.             "                       micro Tenux                     \n" \
  109.             "              Supported MCU is GD32F207ZET6            \n" \
  110.             "                       (build 0400)                    \n" \
  111.             "  Copyright(c) 2008-2014 by Tenux Open Source Society  \n" \
  112.             "-------------------------------------------------------\n" \
  113.             "\n\0"

  114. #ifdef __cplusplus
  115. }
  116. #endif

  117. #endif /* __TK_CONFIG_DEPEND_H__ */
复制代码
   tm_monitor.c中主要是用于uTenux输出信息的一些函数,需要对其与小红板BSP进行适配修改,这里只需小的修改就可和小红板自带DEMO中colibri_bsp_uart.c文件中的函数进行替换;
  1. #include "colibri_bsp_uart.h"
  2. #include "gd32f20x.h"
  3. #include <tm_monitor.h>


  4. #if TK_USE_TM_MONITOR

  5. /* Definition of normal control char */
  6. #define TM_CHAR_NUL          0x00U               /* null character */
  7. #define TM_CHAR_ETX          0x03U               /* end of text character */
  8. #define TM_CHAR_CR           0x0DU               /* carriage return character */
  9. #define TM_CHAR_LF           0x0AU               /* line feed character */

  10. /*
  11. *    Function Name : tm_getchar
  12. *    Create Date   : 2013/2/18-2014/4/1
  13. *    Author        : wangshb
  14. *    Description   : disable interrupt,then receive char from console,util success
  15. *                    supported only on wait != 0 (polling not supported)
  16. *    Param         : int32_t wait: no used
  17. *    Return Code   : int32_t c: char to receive
  18. */
  19. int32_t tm_getchar( int32_t wait )
  20. {
  21.     uint8_t c;
  22.     uint32_t imask;
  23.           char character;

  24.     /* Disable interrupt */
  25.     imask = __get_PRIMASK();
  26.     __set_PRIMASK( 0x1u );

  27.     //c = tm_recvuart();
  28.           EvbUart1ReadByte(&character);
  29.           c = (uint8_t)character;

  30.     /* Enable interrupt */
  31.     __set_PRIMASK( imask );

  32.     return (int32_t)c;
  33. }

  34. /*
  35. *    Function Name : tm_getline
  36. *    Create Date   : 2013/2/18-2014/4/1
  37. *    Author        : wangshb
  38. *    Description   : disable interrupt,then receive a line from console,util success
  39. *                    special key is not supported
  40. *    Param         : uint8_t *buff: buffer to save one line chars
  41. *    Return Code   : int32_t len: line length to receive
  42. */
  43. int32_t tm_getline( uint8_t *buff )
  44. {
  45.     int32_t len = 0;
  46.     uint32_t imask;

  47.     /* Disable interrupt */
  48.     imask = __get_PRIMASK();
  49.     __set_PRIMASK( 0x1u );

  50.     for (;;) {
  51.         //*buff = tm_recvuart();
  52.                           EvbUart1ReadByte(buff);
  53.         //tm_senduart(*buff);                      /* echo back */
  54.                           EvbUart1WriteByte(*buff);
  55.         if ( *buff == TM_CHAR_CR ) {
  56.             //tm_senduart(TM_CHAR_LF);
  57.                                           EvbUart1WriteByte(TM_CHAR_LF);
  58.             *buff = TM_CHAR_NUL;
  59.         } else if ( *buff == TM_CHAR_ETX ) {
  60.             *buff = TM_CHAR_NUL;
  61.             len = -1;
  62.         }
  63.         if ( *buff == TM_CHAR_NUL ) {
  64.             break;
  65.         }
  66.         len++;
  67.         buff++;
  68.     }

  69.     /* Enable interrupt */
  70.     __set_PRIMASK( imask );

  71.     return len;
  72. }
  73. #endif /* TK_USE_TM_MONITOR */

  74. /*
  75. *    Function Name : tm_monitor
  76. *    Create Date   : 2013/2/18-2013/4/26
  77. *    Author        : wangshb
  78. *    Description   : Empty loop
  79. *    Param         : none
  80. *    Return Code   : none
  81. */
  82. void tm_monitor( void )
  83. {
  84.     for(;;) {
  85.         ;
  86.     }
  87. }

  88. #if TK_USE_TM_MONITOR
  89. /*
  90. *    Function Name : tm_putchar
  91. *    Create Date   : 2013/2/18-2014/4/1
  92. *    Author        : wangshb
  93. *    Description   : send a char to console util success
  94. *                    Ctrl-C is not supported
  95. *    Param         : int32_t c: char to send
  96. *    Return Code   : int32_t len: not used
  97. */
  98. int32_t tm_putchar( int32_t c )
  99. {
  100.     uint8_t buf = (uint8_t)c;
  101.     uint32_t imask;

  102.     /* Disable interrupt */
  103.     imask = __get_PRIMASK();
  104.     __set_PRIMASK( 0x1u );

  105.     if (buf == TM_CHAR_LF) {
  106.         //tm_senduart(TM_CHAR_CR);
  107.                           EvbUart1WriteByte(TM_CHAR_CR);
  108.     }
  109.     //tm_senduart(buf);
  110.                 EvbUart1WriteByte(buf);

  111.     /* Enable interrupt */
  112.     __set_PRIMASK( imask );

  113.     return 0;
  114. }

  115. /*
  116. *    Function Name : tm_putstring
  117. *    Create Date   : 2013/2/18-2014/4/1
  118. *    Author        : wangshb
  119. *    Description   : send a string to console util success
  120. *                    Ctrl-C is not supported
  121. *    Param         : const uint8_t *buff: string to send
  122. *    Return Code   : int32_t len: not used
  123. */
  124. int32_t tm_putstring( const uint8_t *buff )
  125. {
  126.     uint32_t imask;

  127.     /* Disable interrupt */
  128.     imask = __get_PRIMASK();
  129.     __set_PRIMASK( 0x1u );

  130.     while ( *buff != TM_CHAR_NUL ) {
  131.         if (*buff == TM_CHAR_LF) {
  132.             //tm_senduart(TM_CHAR_CR);
  133.                                           EvbUart1WriteByte(TM_CHAR_CR);
  134.         }
  135.         //tm_senduart(*buff);
  136.                                 EvbUart1WriteByte(*buff);
  137.         buff++;
  138.     }

  139.     /* Enable interrupt */
  140.     __set_PRIMASK( imask );

  141.     return 0;
  142. }
  143. #endif /* TK_USE_TM_MONITOR */
复制代码
   startup_gd32f20x.s中为小红板的启动文件,是汇编语言写的。这里需要将sysTick和PendSV所对应的中断处理函数替换为uTenux所提供的函数;
  1. Stack_Size          EQU     0x400

  2.                     AREA    STACK, NOINIT, READWRITE, ALIGN = 3
  3. Stack_Mem           SPACE   Stack_Size
  4. __initial_sp

  5. ;// <h> Heap Configuration
  6. ;//   <o>  Heap Size (in Bytes) <0-4096:8>
  7. ;// </h>
  8. Heap_Size           EQU     0x200

  9.                     AREA    HEAP, NOINIT, READWRITE, ALIGN = 3
  10. __heap_base
  11. Heap_Mem            SPACE   Heap_Size
  12. __heap_limit

  13.                     IMPORT knl_dsp_entry                      [WEAK]
  14.                                         IMPORT knl_int_tckhdr                     [WEAK]                 

  15.                     PRESERVE8
  16.                     THUMB

  17. ; Vector table entries with the exceptions ISR address
  18.                     AREA    RESET, DATA, READONLY
  19.                     EXPORT  __Vectors
  20.                     EXPORT  __Vectors_End
  21.                     EXPORT  __Vectors_Size

  22. __Vectors           DCD     __initial_sp                      ; Top of Stack
  23.                     DCD     Reset_Handler                     ; Vector Number 1,Reset Handler
  24.                     DCD     NMI_Handler                       ; Vector Number 2,NMI Handler
  25.                     DCD     HardFault_Handler                 ; Vector Number 3,Hard Fault Handler
  26.                     DCD     MemManage_Handler                 ; Vector Number 4,MPU Fault Handler
  27.                     DCD     BusFault_Handler                  ; Vector Number 5,Bus Fault Handler
  28.                     DCD     UsageFault_Handler                ; Vector Number 6,Usage Fault Handler
  29.                     DCD     0                                 ; Reserved
  30.                     DCD     0                                 ; Reserved
  31.                     DCD     0                                 ; Reserved
  32.                     DCD     0                                 ; Reserved
  33.                     DCD     SVC_Handler                       ; Vector Number 11,SVCall Handler
  34.                     DCD     DebugMon_Handler                  ; Vector Number 12,Debug Monitor Handler
  35.                     DCD     0                                 ; Reserved
  36.                     ;DCD     PendSV_Handler                    ; Vector Number 14,PendSV Handler
  37.                                         ;DCD     SysTick_Handler                   ; Vector Number 15,SysTick Handler
  38.                     DCD     knl_dsp_entry                     ; Vector Number 14,knl_dsp_entry
  39.                                         DCD     knl_int_tckhdr                    ; Vector Number 15,knl_int_tckhdr
复制代码
   uTenux启动任务的过程为:
main()->initctsk()->usermain()->App_TaskCreate()->App_TaskStart()
   这里建立三个用户任务:tsk_id_LED_R;tsk_id_LED_G;tsk_id_LED_Y分别点亮三个LED并通过uart输出相应的信息。
   以上就是对在小红板上移植uTenux的阶段总结。目前移植工作还未完成,存在任务启动后没有输出信息的问题,正在进一步解决中,所以就先不上传代码了。还是先把作业交了占个位置吧。
   TRON标准是国际上嵌入式领域OS开发的一个标准,因此这里对uTenux进行了研究和移植。当然对于RTOS还是要根据开发工作的需要进行选择。对于学习而言更推荐参考资料全面的trochiliOS,它有和小红板配套的教材《嵌入式实时操作系统原理与最佳实践》。毕竟RTOS的原理基本是类似的,一通百通吗。



分享到:
回复

使用道具 举报

回答|共 3 个

倒序浏览

沙发

yanhaijian

发表于 2016-2-24 15:58:58 | 只看该作者

没听过这个操作系统。
板凳

sellen-314350

发表于 2016-2-24 16:40:28 | 只看该作者

yanhaijian 发表于 2016-2-24 15:58
没听过这个操作系统。

我有段时间玩过。
好像是出自日本,记不住了。
地板

糖悦之果飞

发表于 2016-2-25 15:24:04 | 只看该作者

亲,可以将内容一并发到经验频道,很有机会获得每月之星的呢http://jingyan.eeboard.com/
您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条