野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4728|回复: 3

[rt-thread] 请教下,在移植 rt-thread 系统时,总是提示 heap 溢出是怎么回事啊 ?

[复制链接]
发表于 2019-5-21 21:25:45 | 显示全部楼层 |阅读模式
请教下,在移植 rt-thread 系统时,总是提示 heap 溢出是怎么回事啊 ?

我的 heap 配置 为 2MByte

#define   SDRAM_OS_HEAP_BASE_SIZE    1024*1024*2
#define  SDRAM_OS_HEAP_BASE_ADDR   0xC0000000
#define RT_HEAP_SIZE    (SDRAM_OS_HEAP_BASE_SIZE / 4)  //因为指针使用的是 32bit 的,所以需要 /4

static  uint32_t   *rt_heap = (uint32_t *)SDRAM_OS_HEAP_BASE_ADDR;

RT_WEAK void *rt_heap_begin_get(void)
{
    return rt_heap;
}


RT_WEAK void *rt_heap_end_get(void)
{
    return  rt_heap + RT_HEAP_SIZE;
}


rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());

444.png





回复

使用道具 举报

发表于 2019-5-22 12:02:11 | 显示全部楼层
先不使用 SDRAM 看看
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-22 20:04:44 | 显示全部楼层
aozima 发表于 2019-5-22 12:02
先不使用 SDRAM 看看

使用内部的也是一样
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-23 14:03:56 | 显示全部楼层
终于找到原因了,

在串口输出函数里面,需要屏蔽 中断开关函数就可以了

void rt_hw_console_output(const char *str)
{       
        uint16_t  _i;
        /* 进入临界段 , 此处不能够使用, 否则会进入内存溢出错误,切记切记   */
//    rt_enter_critical();
       
                for(_i=0; _i<strlen(str); _i++)       
                {
                        USART1->TDR = (int)str[_i];

                        /* 等待发送结束 */
                        while((USART1->ISR & USART_ISR_TC) == 0)
                        {}
                }
       
        /* 退出临界段 , 此处不能够使用, 否则会进入内存溢出错误,切记切记 */
//   rt_exit_critical();
}
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-20 20:51 , Processed in 0.055745 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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