• 如果要将stm32的代码放到指定的段中运行,首先需要在.ld链接文件中定义段名:
 .text :
 {
    . = ALIGN(4);
    _stext = .;
    *(.test)           /* .text sections (code) */
    *(.test*)          /* .text* sections (code) */
 }
  • 代码中定义时需要通过__attribute__((section(XX)))修饰,其中XX为段名:
#define SECTION_NAME ".test"
#define FUC_SECTION_NAME ".test_fuc"
#define TEST_BUFF_LEN  (1024)

__attribute__((section(SECTION_NAME))) unsigned int test_buff [TEST_BUFF_LEN] = {0};

__attribute__((section(FUC_SECTION_NAME))) void test_ccmram(void)
{
    for(int i=0; i<TEST_BUFF_LEN; i++)
    {
        test_buff[i] = i;   
    }

    for(int i=0; i<TEST_BUFF_LEN; i++)
    {
        printf("[%p] = %d\n",&test_buff[i],test_buff[i]);
    }
    printf("---test success!\n");
}
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐