RTX 移植到 原子STM32开发板 遇到的问题,请大家来指教!!!谢谢!

2019-08-20 16:37发布

int main (void)
{    
    Stm32_Clock_Init(9);        
    os_sys_init (init_task);
    while(1);
}

主要问题:
1,在init_task任务中(系统初始化),调用原子的函数初始化串口程序:
uart_init(72,9600);    

运行到void MY_NVIC_PriorityGroupConfig(u8 NVIC_Group)   函数中
temp=SCB->AIRCR;  运行到这句报 HardFault_Handler
请问什么原因?(只是读个寄存器就报错?)
实际上其他外设的初始化程序中只要遇到“temp=SCB->AIRCR; ”这句就会跳到HardFault_Handler

2,如果将uart_init(72,9600);  放在main函数中:
int main (void)
{    
    Stm32_Clock_Init(9);        
    uart_init(72,9600);
    os_sys_init (init_task);
    while(1);
}
可以初始化,printf函数可以正常使用,但访问USART1->SR寄存器出现异常,比如:
        for(t=0;t<AD_ii;t++)
        {
            while((USART1->SR&40) == 0); //程序卡在这行,一直停在这句死循环。
            USART1->DR = AD_val[t];
        }

3,用AD采样CPU温度(通道16)
采样值不对:-6.7摄氏度(不加操作系统,同样的子程序裸跑得到的值是准确的)
而通道0,2的采样值是对的。

总结一下:我发现在RTX操作系统环境下,用原子开发板自带程序访问系统寄存器有时会出现意外的结果。请各位高手指点,这系统移植大致需要检查哪些方面?最后我把RTX的系统配置文件贴上来:

/*----------------------------------------------------------------------------
 *      RL-ARM - RTX
 *----------------------------------------------------------------------------
 *      Name:    RTX_CONFIG.C
 *      Purpose: Configuration of RTX Kernel for Cortex-M
 *      Rev.:    V4.20
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2011 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/


#include <RTL.h>                      /* RTX kernel functions & defines      */
#include "sys.h"
/*----------------------------------------------------------------------------
 *      RTX User configuration part BEGIN
 *---------------------------------------------------------------------------*/
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
//
// <h>Task Configuration
// =====================
//
//   <o>Number of concurrent running tasks <0-250>
//   <i> Define max. number of tasks that will run at the same time.
//   <i> Default: 6
#ifndef OS_TASKCNT
 #define OS_TASKCNT     8
#endif

//   <o>Number of tasks with user-provided stack <0-250>
//   <i> Define the number of tasks that will use a bigger stack.
//   <i> The memory space for the stack is provided by the user.
//   <i> Default: 0
#ifndef OS_PRIVCNT
 #define OS_PRIVCNT     0
#endif

//   <o>Task stack size [bytes] <20-4096:8><#/4>
//   <i> Set the stack size for tasks which is assigned by the system.
//   <i> Default: 200
#ifndef OS_STKSIZE
 #define OS_STKSIZE     128
#endif

// <q>Check for the stack overflow
// ===============================
// <i> Include the stack checking code for a stack overflow.
// <i> Note that additional code reduces the Kernel performance.
#ifndef OS_STKCHECK
 #define OS_STKCHECK    1
#endif

// <q>Run in privileged mode
// =========================
// <i> Run all Tasks in privileged mode.
// <i> Default: Unprivileged
#ifndef OS_RUNPRIV
 #define OS_RUNPRIV     0
#endif

// </h>
// <h>SysTick Timer Configuration
// =============================
//   <o>Timer clock value [Hz] <1-1000000000>
//   <i> Set the timer clock value for selected timer.
//   <i> Default: 6000000  (6MHz)
#ifndef OS_TIMER
 #define OS_TIMER       2
#endif

#ifndef OS_CLOCK
 #define OS_CLOCK       72000000  
#endif

//   <o>Timer tick value [us] <1-1000000>
//   <i> Set the timer tick value for selected timer.
//   <i> Default: 10000  (10ms)
#ifndef OS_TICK
 #define OS_TICK        10000
#endif

// </h>

// <h>System Configuration
// =======================
// <e>Round-Robin Task switching
// =============================
// <i> Enable Round-Robin Task switching.
#ifndef OS_ROBIN
 #define OS_ROBIN       1
#endif

//   <o>Round-Robin Timeout [ticks] <1-1000>
//   <i> Define how long a task will execute before a task switch.
//   <i> Default: 5
#ifndef OS_ROBINTOUT
 #define OS_ROBINTOUT   5
#endif

// </e>

//   <o>Number of user timers <0-250>
//   <i> Define max. number of user timers that will run at the same time.
//   <i> Default: 0  (User timers disabled)
#ifndef OS_TIMERCNT
 #define OS_TIMERCNT    0
#endif

//   <o>ISR FIFO Queue size<4=>   4 entries  <8=>   8 entries
//                         <12=> 12 entries  <16=> 16 entries
//                         <24=> 24 entries  <32=> 32 entries
//                         <48=> 48 entries  <64=> 64 entries
//                         <96=> 96 entries
//   <i> ISR functions store requests to this buffer,
//   <i> when they are called from the iterrupt handler.
//   <i> Default: 16 entries
#ifndef OS_FIFOSZ
 #define OS_FIFOSZ      16
#endif

// </h>

//------------- <<< end of configuration section >>> -----------------------

// Standard library system mutexes
// ===============================
//  Define max. number system mutexes that are used to protect
//  the arm standard runtime library. For microlib they are not used.
#ifndef OS_MUTEXCNT
 #define OS_MUTEXCNT    8
#endif

/*----------------------------------------------------------------------------
*      RTX User configuration part END
*---------------------------------------------------------------------------*/
#define OS_TRV          ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
/*----------------------------------------------------------------------------
 *      Global Functions
 *---------------------------------------------------------------------------*/

/*--------------------------- os_idle_demon ---------------------------------*/

__task void os_idle_demon (void) {
  /* The idle demon is a system task, running when no other task is ready */
  /* to run. The 'os_xxx' function calls are not allowed from this task.  */

  for (;;) {
  /* HERE: include optional user code to be executed when no task runs.*/
  }
}

/*--------------------------- os_error --------------------------------------*/

void os_error (U32 err_code) {
  /* This function is called when a runtime error is detected. Parameter */
  /* 'err_code' holds the runtime error code (defined in RTL.H).         */

  /* HERE: include optional code to be executed on runtime error. */
  for (;;);
}
/*----------------------------------------------------------------------------
 *      RTX Configuration Functions
 *---------------------------------------------------------------------------*/
#include <RTX_lib.c>
/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
9条回答
jinfeng
1楼-- · 2019-08-20 20:54
似乎找到原因,可能是权限问题,在特权级下不能访问该寄存器!还未确认。
jinfeng
2楼-- · 2019-08-20 22:22
[mw_shl_code=c,true]MRS R0, CONTROL ORR R0, #3 MSR CONTROL, R0 LDR R0, =0xE000ED0C LDR R1, [R0][/mw_shl_code] 已得到验证,如果处于 Unprivileged 模式,访问NVIC(除了那个可以进行软中断的寄存器)就会进入Hard Fault。

参考资料:
http://www.keil.com/support/man/docs/rlarm/rlarm_ar_cfgrunpriv.htm
cwal20
3楼-- · 2019-08-21 03:45
再顶,大神们帮帮忙
jinfeng
4楼-- · 2019-08-21 07:36
 精彩回答 2  元偷偷看……
正点原子
5楼-- · 2019-08-21 11:56
帮顶......
正点原子
6楼-- · 2019-08-21 12:23
回复【6楼】jinfeng:
---------------------------------
谢谢分享

一周热门 更多>