1#define HEAP_SRAM2_BEGIN (0x10000000) 2#define HEAP_SRAM2_SIZE (32 * 1024) 3static struct rt_memheap memheap_sram2; 4int system_sram2_init(void) 5{ 6 return rt_memheap_init(&memheap_sram2, "sram2", (void *)HEAP_SRAM2_BEGIN, (rt_size_t)HEAP_SRAM2_SIZE); 7} 8INIT_BOARD_EXPORT(system_sram2_init); 功能测试
1void *user_alloc(rt_size_t size) 2{ 3 return rt_memheap_alloc(&memheap_sram2, size); 4} 5void user_free(void *ptr) 6{ 7 rt_memheap_free(ptr); 8} 9void user_alloc_test(void) 10{ 11 for (int i = 0; i < MEMHEAP_BLOCK_NUM; i++) 12 { 13 user_ptr[i] = user_alloc(500); 14 if (!user_ptr[i]) 15 { 16 rt_kprintf("malloc failed, index = %d ", i); 17 return; 18 } 19 else 20 { 21 rt_kprintf("[%d] : 0x%08x ", i, user_ptr[i]); 22 } 23 } 24} 25MSH_CMD_EXPORT(user_alloc_test, user_alloc_test); 26void user_free_test(void) 27{ 28 for (int i = 0; i < MEMHEAP_BLOCK_NUM; i++) 29 { 30 if (user_ptr[i]) 31 { 32 rt_kprintf("[%d] : 0x%08x ", i, user_ptr[i]); 33 user_free(user_ptr[i]); 34 } 35 } 36} 37MSH_CMD_EXPORT(user_free_test, user_free_test);
1#define STM32_SRAM1_START (0x20000000) 2#define HEAP_BEGIN STM32_SRAM1_START
1#if defined(__ARMCC_VERSION) 2extern int Image$$RW_IRAM1$$ZI$$Limit; 3#define HEAP_BEGIN ((void *)&Image$$RW_IRAM1$$ZI$$Limit) 4#elif __ICCARM__ 5#pragma section="CSTACK" 6#define HEAP_BEGIN (__segment_end("CSTACK")) 7#else 8extern int __bss_end; 9#define HEAP_BEGIN ((void *)&__bss_end) 10#endif
1 RW_IRAM1 0x20000000 0x00018000 { ; RW data 2 .ANY (+RW +ZI) 3 }
原文:https://club.rt-thread.org/ask/article/736c78aba1dcd82e.html
———————End———————
RT-Thread线下入门培训
6月 - 郑州、杭州、深圳
1.免费 2.动手实验+理论 3.主办方免费提供开发板 4.自行携带电脑,及插线板用于笔记本电脑充电 5.参与者需要有C语言、单片机(ARM Cortex-M核)基础,请提前安装好RT-Thread Studio 开发环境
立即扫码报名
报名链接
https://jinshuju.net/f/UYxS2k
巡回城市:青岛、北京、西安、成都、武汉、郑州、杭州、深圳、上海、南京
你可以添加微信:rtthread2020 为好友,注明:公司+姓名,拉进RT-Thread官方微信交流群!
点击阅读原文,进入RT-Thread 官网
原文标题:RT-Thread 学习笔记:memheap 死机问题的分析与解决
文章出处:【微信公众号:RTThread物联网操作系统】欢迎添加关注!文章转载请注明出处。
全部0条评论
快来发表一下你的评论吧 !