您当前的位置:首页动态正文

全球微速讯:图文详解如何配置Keil-MDK使用GCC编译代码

2023-04-09 08:15:04 面包芯语

2. 选择文件夹/扩展选项卡;

1. 配置 GCC 编译规则

注意勾选一下选项,填写规则

Misc Controls : -mcpu=cortex-m3 -mthumb -fdata-sections -ffunction-sections


【资料图】

注:

(1.) 这里我用的 cortex-m3,如果你是 m4 内核就改成 4;

(2.) -mthumb 的意义是:使用这个编译选项生成的目标文件是 Thumb 的;

2. 配置Assembler编译规则

3. 配置 Linker 连接规则

这里要添加连接脚本,一般可以在官方提供的固件库包找到类似的。

Misc Controls : -Wl,–gc-sections

4. stm32f10x_flash_extsram.ld 内容

/*DefaultlinkerscriptforSTM32F10x_1024K_1024KCopyrightRAISONANCES.A.S.2008*//*includethecommonSTM32F10xsub-script*//*CommonpartofthelinkerscriptsforSTM32devices*//*defaultstacksizes.Theseareusedbythestartupinordertoallocatestacksforthedifferentmodes.*/__Stack_Size=1024;PROVIDE(_Stack_Size=__Stack_Size);__Stack_Init=_estack-__Stack_Size;/*"PROVIDE"allowstoeasilyoverridethesevaluesfromanobjectfileorthecommmandline.*/PROVIDE(_Stack_Init=__Stack_Init);/*TherewillbealinkerrorifthereisnotthisamountofRAMfreeattheend.*/_Minimum_Stack_Size=0x100;/*includethememoryspacesdefinitionssub-script*//*LinkersubscriptforSTM32F10xdefinitionswith1024KFlashand1024KExternalSRAM*//*MemorySpacesDefinitions*/MEMORY{RAM(xrw):ORIGIN=0x68000000,LENGTH=1024KFLASH(rx):ORIGIN=0x8000000,LENGTH=1024KFLASHB1(rx):ORIGIN=0x00000000,LENGTH=0EXTMEMB0(rx):ORIGIN=0x00000000,LENGTH=0EXTMEMB1(rx):ORIGIN=0x00000000,LENGTH=0EXTMEMB2(rx):ORIGIN=0x00000000,LENGTH=0EXTMEMB3(rx):ORIGIN=0x00000000,LENGTH=0}/*higheraddressoftheusermodestack*/_estack=0x68100000;/*includethesectionsmanagementsub-scriptforFLASHmode*//*SectionsDefinitions*/SECTIONS{/*forCortexdevices,thebeginningofthestartupcodeisstoredinthe.isr_vectorsection,whichgoestoFLASH*/.isr_vector:{.=ALIGN(4);KEEP(*(.isr_vector))/*Startupcode*/.=ALIGN(4);}>FLASH/*forsomeSTRxdevices,thebeginningofthestartupcodeisstoredinthe.flashtextsection,whichgoestoFLASH*/.flashtext:{.=ALIGN(4);*(.flashtext)/*Startupcode*/.=ALIGN(4);}>FLASH/*theprogramcodeisstoredinthe.textsection,whichgoestoFlash*/.text:{.=ALIGN(4);*(.text)/*remainingcode*/*(.text.*)/*remainingcode*/*(.rodata)/*read-onlydata(constants)*/*(.rodata*)*(.glue_7)*(.glue_7t).=ALIGN(4);_etext=.;/*Thisisusedbythestartupinordertoinitializethe.datasecion*/_sidata=_etext;}>FLASH/*ThisistheinitializeddatasectionTheprogramexecutesknowingthatthedataisintheRAMbuttheloaderputstheinitialvaluesintheFLASH(inidata).ItisonetaskofthestartuptocopytheinitialvaluesfromFLASHtoRAM.*/.data:AT(_sidata){.=ALIGN(4);/*Thisisusedbythestartupinordertoinitializethe.datasecion*/_sdata=.;*(.data)*(.data.*).=ALIGN(4);/*Thisisusedbythestartupinordertoinitializethe.datasecion*/_edata=.;}>RAM/*Thisistheuninitializeddatasection*/.bss:{.=ALIGN(4);/*Thisisusedbythestartupinordertoinitializethe.bsssecion*/_sbss=.;*(.bss)*(COMMON).=ALIGN(4);/*Thisisusedbythestartupinordertoinitializethe.bsssecion*/_ebss=.;}>RAMPROVIDE(end=_ebss);PROVIDE(_end=_ebss);/*ThisistheuserstacksectionThisisjusttocheckthatthereisenoughRAMleftfortheUsermodestackItshouldgenerateanerrorifit"sfull.*/._usrstack:{.=ALIGN(4);_susrstack=.;.=.+_Minimum_Stack_Size;.=ALIGN(4);_eusrstack=.;}>RAM/*thisistheFLASHBank1*//*theCorassemblysourcemustexplicitlyplacethecodeordatathereusingthe"section"attribute*/.b1text:{*(.b1text)/*remainingcode*/*(.b1rodata)/*read-onlydata(constants)*/*(.b1rodata*)}>FLASHB1/*thisistheEXTMEM*//*theCorassemblysourcemustexplicitlyplacethecodeordatathereusingthe"section"attribute*//*EXTMEMBank0*/.eb0text:{*(.eb0text)/*remainingcode*/*(.eb0rodata)/*read-onlydata(constants)*/*(.eb0rodata*)}>EXTMEMB0/*EXTMEMBank1*/.eb1text:{*(.eb1text)/*remainingcode*/*(.eb1rodata)/*read-onlydata(constants)*/*(.eb1rodata*)}>EXTMEMB1/*EXTMEMBank2*/.eb2text:{*(.eb2text)/*remainingcode*/*(.eb2rodata)/*read-onlydata(constants)*/*(.eb2rodata*)}>EXTMEMB2/*EXTMEMBank0*/.eb3text:{*(.eb3text)/*remainingcode*/*(.eb3rodata)/*read-onlydata(constants)*/*(.eb3rodata*)}>EXTMEMB3/*afterthatit"sonlydebugginginformation.*//*removethedebugginginformationfromthestandardlibraries*/DISCARD:{libc.a(*)libm.a(*)libgcc.a(*)}/*Stabsdebuggingsections.*/.stab0:{*(.stab)}.stabstr0:{*(.stabstr)}.stab.excl0:{*(.stab.excl)}.stab.exclstr0:{*(.stab.exclstr)}.stab.index0:{*(.stab.index)}.stab.indexstr0:{*(.stab.indexstr)}.comment0:{*(.comment)}/*DWARFdebugsections.SymbolsintheDWARFdebuggingsectionsarerelativetothebeginningofthesectionsowebeginthemat0.*//*DWARF1*/.debug0:{*(.debug)}.line0:{*(.line)}/*GNUDWARF1extensions*/.debug_srcinfo0:{*(.debug_srcinfo)}.debug_sfnames0:{*(.debug_sfnames)}/*DWARF1.1andDWARF2*/.debug_aranges0:{*(.debug_aranges)}.debug_pubnames0:{*(.debug_pubnames)}/*DWARF2*/.debug_info0:{*(.debug_info.gnu.linkonce.wi.*)}.debug_abbrev0:{*(.debug_abbrev)}.debug_line0:{*(.debug_line)}.debug_frame0:{*(.debug_frame)}.debug_str0:{*(.debug_str)}.debug_loc0:{*(.debug_loc)}.debug_macinfo0:{*(.debug_macinfo)}/*SGI/MIPSDWARF2extensions*/.debug_weaknames0:{*(.debug_weaknames)}.debug_funcnames0:{*(.debug_funcnames)}.debug_typenames0:{*(.debug_typenames)}.debug_varnames0:{*(.debug_varnames)}}

五、启动代码,使用 GCC 专用的 .S 文件

六、编译运行

1. core_cm3.c 错误

__ASMvolatile("strexb%0,%2,[%1]":"=&r"(result):"r"(addr),"r"(value));

753 行改为:

__ASMvolatile("strexh%0,%2,[%1]":"=&r"(result):"r"(addr),"r"(value));

知识补充

–gnu

启用 ARM 编译器支持的 GNU 编译器扩展。扩展兼容的 GCC 版本可以通过检查预定义的宏__GNUC__和__GNUC_MINOR__. 此外,在 GNU 模式下,ARMCC 编译器模拟 GCC 以符合 C/C++ 标准,无论其严格程度如何。

此选项还可以与其他源语言命令行选项结合使用。例如,armcc --c90 --gnu。

–C99 和 –gnu

#ifdef__GNUC__/*WithGCC/RAISONANCE,smallprintf(optionLDLinker->Libraries->Smallprintfsetto"Yes")calls__io_putchar()*///#definePUTCHAR_PROTOTYPEint__io_putchar(intch)//comment_20190422:soemneeds--gnucompileoption,#definePUTCHAR_PROTOTYPEintfputc(intch,FILE*f)#else#definePUTCHAR_PROTOTYPEintfputc(intch,FILE*f)#endif/*__GNUC__*//***@briefRetargetstheClibraryprintffunctiontotheUSART.*@paramNone*@retvalNone*/PUTCHAR_PROTOTYPE{/*Placeyourimplementationoffputchere*//*e.g.writeacharactertotheEVAL_COM1andLoopuntiltheendoftransmission*/HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,0xFFFF);returnch;}

原文:https://blog.csdn.net/qq_32348883/article/details/123894312

关注我【一起学嵌入式】,一起学习,一起成长。

觉得文章不错,点击“分享”、“赞”、“在看” 呗!

关键词:

上一篇:
下一篇:

“如果发现本网站发布的资讯影响到您的版权,可以联系本站!同时欢迎来本站投稿!

动态

关注