完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
背景介绍了
开发的时候,习惯应用自己的开发扩展库与工程模板,因此每次开始新的项目时,都会直接上一个项目工程,在其基础上进行复制。当新项目与原项目的单片机型号不一样的时候,就涉及到如何将工程中的单片机型号的修改过来的问题。 本文将以工程中MCU型号从STM32F103C8Tx改为STM32F103VCTx为例,说明一下具体的操作步骤。 操作步骤 修改工程文件.cproject 用文本编辑器(记事本++)打开.cproject工程文件,采用查找替换的方式,将工程文件中的原单片机型号“STM32F103C8”替换成“STM32F103VC”并保存。.project工程文件中没有需要修改的内容。 删除部分工程文件 删除XXX.elf.launch文件和XXX.map文件,这两个默认文件在工程目录文件夹中,在设置Run/Debug Configurations的时候会自动重新生成。替换 启动文件 将原来型号的启动文件(XXX.s文件)替换为startup_stm32f103vctx.s,这个启动文件可以通过在STM32CubeIDE中新建一个MCU型号为STM32F103VCTx的工程并自动生成代码而获得。同时也可以在源码中保留这些文件,而在Makefile中指定调用的文件名。 替换LinkerScript文件 将原来型号的链接文件(XXX.ld文件)替换为STM32F103VCTX_FLASH.ld,这个链接文件可以通过在STM32CubeIDE中新建一个MCU为STM32F103VCTx的工程并自动生成代码而获得。也可以在源码中同时保留这些文件,而在Makefile中指定调用的文件名。 当然也可以直接修改原来的链接文件: /* Highest address of the user mode stack */ _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of “RAM” Ram type memory */ _Min_Heap_Size = 0x200 ; /* required amount of heap */ _Min_Stack_Size = 0x400 ; /* required amount of stack */ /* Memories definition */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K } 主要的地方就在内存空间分配与 RAM Flash 的定义。 修改Makefile文件 主要修改到连接类型、启动文件、文件等的内容: LINK_SCRIPT = “STM32F103VCTX_FLASH.ld” ASSEMBLER_FLAGS =-c -g -O0 -mcpu=cortex-m3 -mthumb -D“STM32F10X_HD” -D“USE_STDPERIPH_DRIVER” -x assembler-with-cpp $(INCLUDE_DIR) COMPILER_FLAGS =-c -g -MMD -mcpu=cortex-m3 -O0 -Wall -ffunction-sections -fdata-sections -mthumb -D“STM32F10X_HD” -D“USE_STDPERIPH_DRIVER” $(INCLUDE_DIR) 启动文件属于文件,所以只要替换即可: SRCSASM := $(wildcard */*/*/*/*/*/*/*/*.s) $(wildcard */*/*/*/*/*/*/*.s) $(wildcard */*/*/*/*/*/*.s) $(wildcard */*/*/*/*/*.s) $(wildcard */*/*/*/*.s) $(wildcard */*/*/*.s) $(wildcard */*/*.s) $(wildcard */*.s) 如果存在多个启动文件,可以排除不匹配的型号的文件: #SRCSASM := $(filter-out Source/StdPeriLib/Startup/startup_stm32f103vctx.s, $(SRCSASM)) SRCSASM := $(filter-out Source/StdPeriLib/Startup/startup_stm32f10x_md.s, $(SRCSASM)) Alwhales库的修改 需要修改eeprom.h中关于闪烁划分作为EEPROM的地址范围。 对于C8T6型号,flash的结束地址为“0x08010000”; 对于VCT6型号,flash的结束地址为“0x08040000”; #if defined (STM32F10X_LD) || defined (STM32F10X_MD) #define PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */ #define FLASH_END_ADDRESS 0x08010000 #elif defined (STM32F10X_HD) || defined (STM32F10X_CL) #define PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */ #define FLASH_END_ADDRESS 0x08040000 #endif /* EEPROM start address in Flash */ #define EEPROM_START_ADDRESS ((uint32_t)(FLASH_END_ADDRESS - 2 * PAGE_SIZE)) 已经设置好了条件,只需要在合适的位置(默认在 stm32f10x.h 中):# define STM32F10X_HD标准库的修改 在 stm32f10x.h 文件中,需要根据所使用的 MCU 型号,选择对应的宏定义: /* Uncomment the line below according to the target STM32 device used in your application */ #if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL) /* #define STM32F10X_LD */ /*!《 STM32F10X_LD: STM32 Low density devices */ /* #define STM32F10X_LD_VL */ /*!《 STM32F10X_LD_VL: STM32 Low density Value Line devices */ /* #define STM32F10X_MD */ /*!《 STM32F10X_MD: STM32 Medium density devices */ /* #define STM32F10X_MD_VL */ /*!《 STM32F10X_MD_VL: STM32 Medium density Value Line devices */ #define STM32F10X_HD /*!《 STM32F10X_HD: STM32 High density devices */ /* #define STM32F10X_HD_VL */ /*!《 STM32F10X_HD_VL: STM32 High density value line devices */ /* #define STM32F10X_XL */ /*!《 STM32F10X_XL: STM32 XL-density devices */ /* #define STM32F10X_CL */ /*!《 STM32F10X_CL: STM32 Connectivity line devices */ #endif /* Tip: To avoid modifying this file each time you need to switch between these devices, you can define the device in your toolchain compiler preprocessor. - Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes. - Low-density value line devices are STM32F100xx microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes. - Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes. - Medium-density value line devices are STM32F100xx microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes. - High-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes. - High-density value line devices are STM32F100xx microcontrollers where the Flash memory density ranges between 256 and 512 Kbytes. - XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the Flash memory density ranges between 512 and 1024 Kbytes. - Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers. */ |
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
4145 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
3230 浏览 1 评论
2756 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
2185 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
14998 浏览 2 评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
3092浏览 4评论
stm32f4下spi+dma读取数据不对是什么原因导致的?
1898浏览 3评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
2070浏览 3评论
1981浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
2171浏览 3评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 10:36 , Processed in 0.547665 second(s), Total 43, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1591