打印
[RTOS]

AT32F435使用 RT-Thread给外部SDRAM分配内存堆出现hard fault。

[复制链接]
1001|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
AT32F435使用 RT-Thread给外部SDRAM分配内存堆出现hard fault。在执行内存堆分配函数rt_memheap_init(&system_heap, "sdram", (void *)SDRAM_BANK_ADDR, SDRAM_SIZE);时出现hard fault。在为执行内存堆分配时测试SDRAM的读写功能正常。求助下这个是什么原因造成的。怎么才能解决,谢谢!
static int sdram_init(void)
{
    int result = RT_EOK;
    xmc_cmd_bank1_2_type target_bank = XMC_CMD_BANK1;

    xmc_sdram_init_type sdram_init_struct;
    xmc_sdram_timing_type sdram_timing_struct;

    at32_msp_sdram_init(NULL);

    /* xmc configuration */
    xmc_sdram_default_para_init(&sdram_init_struct, &sdram_timing_struct);

#if SDRAM_TARGET_BANK == 1
    sdram_init_struct.sdram_bank = XMC_SDRAM_BANK1;
#else
    sdram_init_struct.sdram_bank = XMC_SDRAM_BANK2;
#endif
#if SDRAM_COLUMN_BITS == 8
    sdram_init_struct.column_address = XMC_COLUMN_8;
#elif SDRAM_COLUMN_BITS == 9
    sdram_init_struct.column_address = XMC_COLUMN_9;
#elif SDRAM_COLUMN_BITS == 10
    sdram_init_struct.column_address = XMC_COLUMN_10;
#else
    sdram_init_struct.column_address = XMC_COLUMN_11;
#endif
#if SDRAM_ROW_BITS == 11
    sdram_init_struct.row_address = XMC_ROW_11;
#elif SDRAM_ROW_BITS == 12
    sdram_init_struct.row_address = XMC_ROW_12;
#else
    sdram_init_struct.row_address = XMC_ROW_13;
#endif
#if SDRAM_DATA_WIDTH == 8
    sdram_init_struct.width = XMC_MEM_WIDTH_8;
#elif SDRAM_DATA_WIDTH == 16
    sdram_init_struct.width = XMC_MEM_WIDTH_16;
#endif

    sdram_init_struct.internel_banks = XMC_INBK_4;

#if SDRAM_CAS_LATENCY == 1
    sdram_init_struct.cas = XMC_CAS_1;
#elif SDRAM_CAS_LATENCY == 2
    sdram_init_struct.cas = XMC_CAS_2;
#else
    sdram_init_struct.cas = XMC_CAS_3;
#endif
#if SDRAM_RPIPE_DELAY == 0
    sdram_init_struct.read_delay = XMC_READ_DELAY_0;
#elif SDRAM_RPIPE_DELAY == 1
    sdram_init_struct.read_delay = XMC_READ_DELAY_1;
#else
    sdram_init_struct.read_delay = XMC_READ_DELAY_2;
#endif
#if SDCLOCK_PERIOD == 2
    sdram_init_struct.clkdiv = XMC_CLKDIV_2;
#else
    sdram_init_struct.clkdiv = XMC_CLKDIV_3;
#endif

    sdram_init_struct.write_protection = FALSE;
    sdram_init_struct.burst_read = TRUE;

    sdram_timing_struct.tmrd = LOADTOACTIVEDELAY;
    sdram_timing_struct.txsr = EXITSELFREFRESHDELAY;
    sdram_timing_struct.tras = SELFREFRESHTIME;
    sdram_timing_struct.trc = ROWCYCLEDELAY;
    sdram_timing_struct.twr = WRITERECOVERYTIME;
    sdram_timing_struct.trp = RPDELAY;
    sdram_timing_struct.trcd = RCDDELAY;

    xmc_sdram_init(&sdram_init_struct, &sdram_timing_struct);

#if SDRAM_TARGET_BANK == 1
    target_bank = XMC_CMD_BANK1;
#else
    target_bank = XMC_CMD_BANK2;
#endif

    sdram_init_sequence(target_bank);
       
        LOG_D("sdram init success, mapped at 0x%X, size is %d bytes, data width is %d", SDRAM_BANK_ADDR, SDRAM_SIZE, SDRAM_DATA_WIDTH);


#ifdef RT_USING_MEMHEAP_AS_HEAP
        /* If RT_USING_MEMHEAP_AS_HEAP is enabled, SDRAM is initialized to the heap */
       rt_memheap_init(&system_heap, "sdram", (void *)SDRAM_BANK_ADDR, SDRAM_SIZE);
#endif

    return result;
}

INIT_BOARD_EXPORT(sdram_init);


微信图片_20230902101350.png (17.2 KB )

微信图片_20230902101350.png

微信图片_20230902102920.png (17.34 KB )

微信图片_20230902102920.png

微信图片_20230902101350.png (17.2 KB )

微信图片_20230902101350.png

使用特权

评论回复
沙发
ryan_jiang|  楼主 | 2023-9-2 16:39 | 只看该作者
解决了。

使用特权

评论回复
板凳
caigang13| | 2023-9-2 18:21 | 只看该作者
hardfault一般都是内存或堆栈溢出

使用特权

评论回复
地板
aozima| | 2023-9-3 09:11 | 只看该作者

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

20

帖子

1

粉丝