您尚未登录。

楼主 # 2024-09-24 13:51:35

海石生风
会员
所在地: 深圳
注册时间: 2019-07-02
已发帖子: 660
积分: 793
个人网站

D21x RTOS SDK 1.0.5使能AWTK并添加C++源码后系统运行异常

经测试AWTK和C++源码只要不是同时使能,系统都能正常运行。但两都同时使能编译在一起运行就会进入不了main函数并出现Exception如下:

CPU Exception: NO.1
x1(ra)   : 00000000400361c6     x2(sp)   : 00000000402de558     x3(gp)   : 000000004026e530f
x5(t0)   : 000000004026fef8     x6(t1)   : 0000000000000002     x7(t2)   : 00000000000000724
x9(s1)   : 0000000040269670     x10(a0)  : 0000000000000000     x11(a1)  : 00000000000000008
x13(a3)  : 00000000402a35a0     x14(a4)  : 0000000066f25211     x15(a5)  : 401f1830000000008
x17(a7)  : 0000000000000064     x18(s2)  : 00000000deadbeef     x19(s3)  : 00000000deadbeeff
x21(s5)  : 00000000deadbeef     x22(s6)  : 00000000deadbeef     x23(s7)  : 00000000deadbeeff
x25(s9)  : 00000000deadbeef     x26(s10) : 00000000deadbeef     x27(s11) : 00000000deadbeefa
x29(t4)  : 0000000000000190     x30(t5)  : 000000000000002d     x31(t6)  : 0000000000000000
mcause   : 0000000000000001
mtval    : 0000003000000000
mepc     : 0000003000000000
mstatus  : 8000000a00007880

完整启动日志如下:

tinySPL [Built on Sep 11 2024 16:34:02]
[W] usbh_is_connected()105 usb 1 port change wait failed.
[E] main()172 Not find udisk.
qspi0 freq (input): 91636363Hz
qspi0 freq ( bus ): 91636363Hz
nftl vol: data, size 0
Selecting default config 'Luban-lite firmware'
spl read: 2549040 byte, 348034 us -> 7152 KB/s
Boot time:
108099 : Enter main
109631 : Clock and pinmux done
110143 : Console UART ready
111287 : Heap init done
114980 : Banner shown
204155 : UDISK checked
571345 : Run APP
Welcome to ArtInChip Luban-Lite 1.0.5 [D21x Inside]
Built on Sep 24 2024 13:43:04
09-24 13:45:53 I/PWM main: ArtInChip PWM loaded
09-24 13:45:53 I/touch main: rt_touch init success
09-24 13:45:53 I/gt911 main: touch device gt911 init success
[I] aic_find_panel()83 find panel driver : panel-lvds
[I] aicfb_probe()978 fb0 allocated at 0x42000040
[I] hal_ge_init()1620 dither line phys: 0x424B0100
[I] pcm1803a_init()22 pcm1803a init
09-24 13:45:53 I/PSADC main: ArtInChip PSADC loaded
[I] aic_sdmc_clk_init()548 SDMC1 sclk: 50400 KHz, parent clk 1008000 KHz
09-24 13:45:53 I/SDMC main: SDMC1 BW 1, sclk 50400 KHz, clk 400 KHz(406 KHz), div 2-62

[I] aic_sdmc_probe()665 SDMC1 driver loaded
qspi0 freq (input): 91636363Hz
qspi0 freq ( bus ): 91636363Hz
[I] spinand_info_read()473 find raw ID efaa2200
[I] spinand_flash_init()524 Enabled BUF, HWECC. Unprotected.
nftl vol: data, size 0
09-24 13:45:53 I/sensor main: rt_sensor[temp_tsen_cpu] init success
09-24 13:45:53 I/WDT main: ArtInChip WDT loaded
CPU Exception: NO.1
x1(ra)   : 00000000400361c6     x2(sp)   : 00000000402de558     x3(gp)   : 000000004026e530f
x5(t0)   : 000000004026fef8     x6(t1)   : 0000000000000002     x7(t2)   : 00000000000000724
x9(s1)   : 0000000040269670     x10(a0)  : 0000000000000000     x11(a1)  : 00000000000000008
x13(a3)  : 00000000402a35a0     x14(a4)  : 0000000066f25211     x15(a5)  : 401f1830000000008
x17(a7)  : 0000000000000064     x18(s2)  : 00000000deadbeef     x19(s3)  : 00000000deadbeeff
x21(s5)  : 00000000deadbeef     x22(s6)  : 00000000deadbeef     x23(s7)  : 00000000deadbeeff
x25(s9)  : 00000000deadbeef     x26(s10) : 00000000deadbeef     x27(s11) : 00000000deadbeefa
x29(t4)  : 0000000000000190     x30(t5)  : 000000000000002d     x31(t6)  : 0000000000000000
mcause   : 0000000000000001
mtval    : 0000003000000000
mepc     : 0000003000000000
mstatus  : 8000000a00007880

离线

#1 2024-09-24 15:53:02

AICxia
会员
注册时间: 2024-08-12
已发帖子: 22
积分: 142

Re: D21x RTOS SDK 1.0.5使能AWTK并添加C++源码后系统运行异常

会不会是栈越界,C++代码加少一点试试

离线

楼主 #2 2024-09-24 16:26:12

海石生风
会员
所在地: 深圳
注册时间: 2019-07-02
已发帖子: 660
积分: 793
个人网站

Re: D21x RTOS SDK 1.0.5使能AWTK并添加C++源码后系统运行异常

试过将main线程栈开到4MB都一样。C++代码如下,非常简单,且只是加入编译没有在其它地方调用C++源码的函数。
发现只要用了C++的标准库就出问题,不用C++标准库就没有问题;即使能宏ENABLE_CPP_STD就会出问题

#include <stdio.h>

#define ENABLE_CPP_STD 1

#if ENABLE_CPP_STD
#include <vector>
#endif

class MyOutputStream {
public:
    MyOutputStream(){}

    MyOutputStream& operator<<(int v) {
        printf("%d", v);
        return *this;
    }

    MyOutputStream& operator<<(unsigned int v) {
        printf("%u", v);
        return *this;
    }

    MyOutputStream& operator<<(long int v) {
        printf("%ld", v);
        return *this;
    }

    MyOutputStream& operator<<(unsigned long int v) {
        printf("%lu", v);
        return *this;
    }

    MyOutputStream& operator<<(char v) {
        printf("%c", v);
        return *this;
    }

    MyOutputStream& operator<<(const char* v) {
        printf("%s", v);
        return *this;
    }

    MyOutputStream& operator<<(char* v) {
        printf("%s", v);
        return *this;
    }
};

class A {
public:
    A();
    ~A();

private:
#if ENABLE_CPP_STD
    std::vector<int> vi;
#endif

    MyOutputStream cout;
};

A::A()
{
    cout << "A init\n";

#if ENABLE_CPP_STD
    vi = {1, 2, 3};
    vi.push_back(4);
    vi.push_back(5);

    cout << "is size:" << vi.size() << '\n';
    for(auto &i: vi) {
        cout << i << ", ";
    }
    cout << '\n';
#endif
}

A::~A()
{
    cout << "A deinit\n";
}

void a_test()
{
    A a;
}

离线

楼主 #3 2024-09-24 19:08:05

海石生风
会员
所在地: 深圳
注册时间: 2019-07-02
已发帖子: 660
积分: 793
个人网站

Re: D21x RTOS SDK 1.0.5使能AWTK并添加C++源码后系统运行异常

找到问题了!D21x是64位机,C++的初始化函数表.init_array应该是8字节对齐的,而SDK的链接脚本里弄成4字节对齐了。
按以下patch将链接脚本里的改为8字节对齐即可:

diff --git a/bsp/artinchip/sys/d21x/link_script/gcc_aic.ld.S b/bsp/artinchip/sys/d21x/link_script/gcc_aic.ld.S
index 7600a467..561a79ed 100644
--- a/bsp/artinchip/sys/d21x/link_script/gcc_aic.ld.S
+++ b/bsp/artinchip/sys/d21x/link_script/gcc_aic.ld.S
@@ -149,7 +149,7 @@ SECTIONS
*(.rodata.*)
*(.srodata*)
*(.rodata.str1.4)
-  . = ALIGN(0x4) ;
+  . = ALIGN(0x8) ;
PROVIDE(__ctors_start__ = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))

最近编辑记录 海石生风 (2024-09-24 19:08:58)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn