请选择 进入手机版 | 继续访问电脑版

硬汉嵌入式论坛

 找回密码
 立即注册
查看: 7643|回复: 10
收起左侧

[ThreadX全家桶] 基于IAR+iMX6ULL的ThreadX移植探讨

[复制链接]

2

主题

8

回帖

14

积分

新手上路

积分
14
发表于 2021-5-29 17:25:51 | 显示全部楼层 |阅读模式
在IAR V8.32.3移植ThreadX运行于iMX6ULL上,坛里的大佬有人试验过在CortexA7上运行没,望赐教指点!
移植运行可以执行到VOID  _tx_thread_shell_entry(VOID)函数的TX_DISABLE语句后,程序就跳入未定义异常
__tx_undefined
    B       __tx_undefined                      ; Undefined handler



cstartup.s (5.98 KB, 下载次数: 10)
tx_initialize_low_level.s (15.31 KB, 下载次数: 11)
tx_setup_systick.c (4.99 KB, 下载次数: 11)

在cstartup.s主要添加
;
; Add initialization needed before setup of stackpointers here.
;

        CPSID   I                       ; Mask interrupts

        ; Reset SCTLR Settings
        MRC     P15, 0, R0, C1, C0, 0   ; Read CP15 System Control register
        BIC     R0,  R0, #(0x1 << 12)   ; Clear I bit 12 to disable I Cache
        BIC     R0,  R0, #(0x1 <<  2)   ; Clear C bit  2 to disable D Cache
        BIC     R0,  R0, #0x2           ; Clear A bit  1 to disable strict alignment
        BIC     R0,  R0, #(0x1 << 11)   ; Clear Z bit 11 to disable branch prediction
        BIC     R0,  R0, #0x1           ; Clear M bit  0 to disable MMU
        MCR     P15, 0, R0, C1, C0, 0   ; Write value back to CP15 System Control register

....

;
; Add more initialization here
;
        LDR     R0, =SystemInit
        BLX     R0
        CPSIE   I                       ; Unmask interrupts


在tx_initialize_low_level.s中主要新增:
;    /* For debug purpose, execute the timer interrupt processing here.  In
;       a real system, some kind of status indication would have to be checked
;       before the timer interrupt handler could be called.  */
;
;   BL      _tx_timer_interrupt                 ; Timer interrupt handler
;
;    /* Application IRQ handlers can be called here!  */
        PUSH    {LR}                         ; Save return address+4
        PUSH    {R0-R3, R12}                 ; Push caller save registers

        MRS     R0, SPSR                     ; Save SPRS to allow interrupt reentry
        PUSH    {R0}

        MRC     P15, 4, R1, C15, C0, 0       ; Get GIC base address
        ADD     R1, R1, #0x2000              ; R1: GICC base address
        LDR     R0, [R1, #0xC]               ; R0: IAR

        PUSH    {R0, R1}

        CPS     #0x13                        ; Change to Supervisor mode to allow interrupt reentry

        PUSH    {LR}                         ; Save Supervisor LR
        LDR     R2, =SystemIrqHandler
        BLX     R2                           ; Call SystemIrqHandler with param IAR
        POP     {LR}

        CPS     #0x12                        ; Back to IRQ mode

        POP     {R0, R1}

        STR     R0, [R1, #0x10]              ; Now IRQ handler finished: write to EOIR

        POP     {R0}
        MSR     SPSR_CXSF, R0

        POP     {R0-R3, R12}
        POP     {LR}
        SUBS    PC, LR, #4
;


通过在tx_user.h中定义宏在内核启动时配置滴答定时器
extern void tx_config_systick(void);
extern void tx_startup_notify(void);

#define TX_PORT_SPECIFIC_PRE_INITIALIZATION                 tx_config_systick();
#define TX_PORT_SPECIFIC_POST_INITIALIZATION
#define TX_PORT_SPECIFIC_PRE_SCHEDULER_INITIALIZATION       tx_startup_notify();


回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106405
QQ
发表于 2021-5-29 21:48:30 | 显示全部楼层
帮顶。
回复

使用道具 举报

2

主题

21

回帖

27

积分

新手上路

积分
27
发表于 2021-5-30 23:42:44 | 显示全部楼层
检查下arm的cpsr mode,可能它处于thumb状态,无法识别arm格式的代码,我移植a9的时候好像遇到过
回复

使用道具 举报

2

主题

8

回帖

14

积分

新手上路

积分
14
 楼主| 发表于 2021-5-31 08:40:42 | 显示全部楼层
luguan1997 发表于 2021-5-30 23:42
检查下arm的cpsr mode,可能它处于thumb状态,无法识别arm格式的代码,我移植a9的时候好像遇到过

仿真跟踪在跳转_tx_thread_schedule瞬间,CPSR的T位变0了,未见有指令将其归0切换成ARM模式,挺困惑。
回复

使用道具 举报

2

主题

8

回帖

14

积分

新手上路

积分
14
 楼主| 发表于 2021-5-31 17:36:13 | 显示全部楼层
2021-05-31_171703.jpg 2021-05-31_172616.jpg
仿真跟踪进入VOID  _tx_thread_shell_entry(VOID)函数,通过TX_THREAD_GET_CURRENT(thread_ptr)给thread_ptr赋值,结果为0异常值,
#define TX_THREAD_GET_CURRENT(a)            (a) =  _tx_thread_current_ptr;
_tx_thread_current_ptr已成功指向thread_0控制块,为何执行thread_ptr = _tx_thread_current_ptr;取得0值?好是困惑。

在readme_threadx.txt中有如下说明
9.  Thumb/Cortex-A7 Mixed Mode

By default, ThreadX is setup for running in Cortex-A7 32-bit mode. This is
also true for the demonstration system. It is possible to build any
ThreadX file and/or the application in Thumb mode. The only exception
to this is the file tx_thread_shell_entry.c. This file must always be
built in 32-bit mode.
In addition, if any Thumb code is used the entire
ThreadX assembly source should be built with TX_THUMB defined.

我已在工程的汇编选项中定义TX_THUMB,如何单独编译tx_thread_shell_entry.c为32-bit mode呢,哪位大神能指导一下万分感激!
2021-05-31_173340.jpg
回复

使用道具 举报

2

主题

8

回帖

14

积分

新手上路

积分
14
 楼主| 发表于 2021-5-31 18:00:40 | 显示全部楼层
luguan1997 发表于 2021-5-30 23:42
检查下arm的cpsr mode,可能它处于thumb状态,无法识别arm格式的代码,我移植a9的时候好像遇到过

请教大神,在Cortex-A9上移植也要求将如下文件编译成32-bit模式,请问您在IAR中如何设置的呢?
tx_thread_shell_entry.c must always be built in 32-bit mode
回复

使用道具 举报

2

主题

8

回帖

14

积分

新手上路

积分
14
 楼主| 发表于 2021-5-31 20:12:48 | 显示全部楼层
XiaoLuoSi 发表于 2021-5-31 18:00
请教大神,在Cortex-A9上移植也要求将如下文件编译成32-bit模式,请问您在IAR中如何设置的呢?
tx_thre ...

问题初步解决,在C/C++ Compiler选项中的Processor mode切换Thumb为Arm模式,尝试用BAT脚本可单独编译tx_thread_shell_entry.c文件,但未搞清楚如果在IAR工程中配置进行连接,挺麻烦的,先凑合着用ARM模式编译吧。
subst W: "C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2"
W:\arm\bin\iccarm.exe  tx_thread_shell_entry.c  --cpu=Cortex-A7  --cpu_mode=arm    -D TX_INCLUDE_USER_DEFINE_FILE  -I ..\inc  -I ..\..\ports\cortex_a7\iar\inc
回复

使用道具 举报

2

主题

21

回帖

27

积分

新手上路

积分
27
发表于 2021-7-7 23:48:17 | 显示全部楼层
几个组件里a核移植 threadx module感觉要难很多,想进程隔离得真正搞明白好多东西,mmu,tlb,asid,软中断,各种模式,cache,不知道有没有人搞出来
单纯单核的threadx就 mmu简单映射下,gic配好 定时中断调用tick,svc模式下跑 跟mcu没有大的区别。
另外,我也所有文件编译全用的arm代码不用thumb,arm指令应该是性能高、内存占用大,a核跑rtos内存肯定够
本来看组件很完整但还是有坑,threadx port文件还有些小毛病,记得好像是把abort位置了,平时跑起来不响应abort异常;文件系统也没有posix接口,移植之前的应用不方便;网络上层应用那几个例子也有些bug,支持还是有些不够
回复

使用道具 举报

2

主题

21

回帖

27

积分

新手上路

积分
27
发表于 2021-7-8 00:03:30 | 显示全部楼层
a核 port里 clz指令可能没用上(它加了个#if target> v5的宏导致没编译),性能可以提升
回复

使用道具 举报

0

主题

12

回帖

12

积分

新手上路

积分
12
发表于 2021-10-20 17:47:43 | 显示全部楼层
XiaoLuoSi 发表于 2021-5-31 18:00
请教大神,在Cortex-A9上移植也要求将如下文件编译成32-bit模式,请问您在IAR中如何设置的呢?
tx_thre ...

单独选中文件,右键勾选 override 能单独配置这个文件。
我这边这样设置的能跑,但是移植之后调度有点问题,gpt 中断响应不了,按键中断可以,很神奇。方便分享下你的工程让我对比下吗?
回复

使用道具 举报

0

主题

22

回帖

22

积分

新手上路

积分
22
发表于 2021-11-5 18:20:20 | 显示全部楼层
alliance2014 发表于 2021-10-20 17:47
单独选中文件,右键勾选 override 能单独配置这个文件。
我这边这样设置的能跑,但是移植之后调度有点问 ...

楼主还没有搞定吗
回复

使用道具 举报

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

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-19 10:16 , Processed in 0.200439 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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