免费制作永久网站东莞阿里巴巴代运营公司
- 作者: 五速梦信息网
- 时间: 2026年03月21日 10:22
当前位置: 首页 > news >正文
免费制作永久网站,东莞阿里巴巴代运营公司,淘宝网页版手机版,个人做游戏网站创建静态库lib 1. 新建工程1.1 创建工程文件夹1.2 编写用户相关代码1.2.1 stm32f4xx_it.h1.2.2 stm32f4xx_it.c1.2.3 标准库配置#xff1a;stm32f4xx_conf.h1.2.4 HAL库的配置#xff1a;stm32f4xx_hal_conf.h1.2.5 LL库配置#xff1a;stm32f4xx_ll_conf.h 1.3 移植通用文… 创建静态库lib 1. 新建工程1.1 创建工程文件夹1.2 编写用户相关代码1.2.1 stm32f4xx_it.h1.2.2 stm32f4xx_it.c1.2.3 标准库配置stm32f4xx_conf.h1.2.4 HAL库的配置stm32f4xx_hal_conf.h1.2.5 LL库配置stm32f4xx_ll_conf.h 1.3 移植通用文件1.3.1 标准外设库SPL1.3.2 HAL库1.3.3 LL库 1.4 修改相关文件SPL/HAL/LL库1.4.1 启动文件 startup_stm32f40xx.s 1.5 将移植的文件添加到工程中1.5.1 标准外设库SPL1.5.2 HAL库1.5.3 LL库 2. 创建lib库2.1 创建标准外设库SPL库2.2 创建HAL库2.3 创建LL库 1. 新建工程
1.1 创建工程文件夹 在电脑的某个目录下建立一个 Template 文件夹后面所建立的工程都放在这个文件夹下。在 Template 目录下新建下列目录 新建工程 1.2 编写用户相关代码
1.2.1 stm32f4xx_it.h #ifndef __STM32F4xx_IT_H
#define __STM32F4xx_IT_H#ifdef __cplusplus
extern C {
#endif void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);#ifdef __cplusplus
}
#endif#endif /* __STM32F4xx_IT_H /1.2.2 stm32f4xx_it.c 内核相关中断 #include stm32f4xx_it.hvoid NMI_Handler(void) {
}void HardFault_Handler(void) {while (1) {}
}void MemManage_Handler(void) {while (1) {}
}void BusFault_Handler(void) {while (1) {}
}void UsageFault_Handler(void) {while (1) {}
}void SVC_Handler(void) {
}void DebugMon_Handler(void) {
}void PendSV_Handler(void) {
}void SysTick_Handler(void) {
}1.2.3 标准库配置stm32f4xx_conf.h stm32f4xx.h文件中会引用 stm32f4xx_conf.h最重要的是实现assert_param函数 //同 标准库SPL中的实例一模一样
#ifndef __STM32F4xx_CONF_H
#define __STM32F4xx_CONF_H#include stm32f4xx_adc.h
#include stm32f4xx_crc.h
#include stm32f4xx_dbgmcu.h
#include stm32f4xx_dma.h
#include stm32f4xx_exti.h
#include stm32f4xx_flash.h
#include stm32f4xx_gpio.h
#include stm32f4xx_i2c.h
#include stm32f4xx_iwdg.h
#include stm32f4xx_pwr.h
#include stm32f4xx_rcc.h
#include stm32f4xx_rtc.h
#include stm32f4xx_sdio.h
#include stm32f4xx_spi.h
#include stm32f4xx_syscfg.h
#include stm32f4xx_tim.h
#include stm32f4xx_usart.h
#include stm32f4xx_wwdg.h
#include misc.h#if defined (STM32F429_439xx)
#include stm32f4xx_cryp.h
#include stm32f4xx_hash.h
#include stm32f4xx_rng.h
#include stm32f4xx_can.h
#include stm32f4xx_dac.h
#include stm32f4xx_dcmi.h
#include stm32f4xx_dma2d.h
#include stm32f4xx_fmc.h
#include stm32f4xx_ltdc.h
#include stm32f4xx_sai.h
#endif / STM32F429_439xx /#if defined (STM32F427_437xx)
#include stm32f4xx_cryp.h
#include stm32f4xx_hash.h
#include stm32f4xx_rng.h
#include stm32f4xx_can.h
#include stm32f4xx_dac.h
#include stm32f4xx_dcmi.h
#include stm32f4xx_dma2d.h
#include stm32f4xx_fmc.h
#include stm32f4xx_sai.h
#endif / STM32F427_437xx /#if defined (STM32F40_41xxx)
#include stm32f4xx_cryp.h
#include stm32f4xx_hash.h
#include stm32f4xx_rng.h
#include stm32f4xx_can.h
#include stm32f4xx_dac.h
#include stm32f4xx_dcmi.h
#include stm32f4xx_fsmc.h
#endif / STM32F40_41xxx */#ifdef USE_FULL_ASSERT#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t )FILE, LINE))void assert_failed(uint8_t file, uint32_t line);
#else#define assert_param(expr) ((void)0)
#endif #endif1.2.4 HAL库的配置stm32f4xx_hal_conf.h stm32f4xx_hal.h文件中会引用 stm32f4xx_hal_conf.h最重要的是实现assert_param函数 //同 HAL 库中的实例一模一样
#ifndef __STM32F4xx_HAL_CONF_H
#define __STM32F4xx_HAL_CONF_H#ifdef cplusplus
extern C {
#endif#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
#define HAL_CAN_MODULE_ENABLED
/* #define HAL_CAN_LEGACY_MODULE_ENABLED /
#define HAL_CRC_MODULE_ENABLED
#define HAL_CRYP_MODULE_ENABLED
#define HAL_DAC_MODULE_ENABLED
#define HAL_DCMI_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
/ #define HAL_DMA2D_MODULE_ENABLED /
/ #define HAL_ETH_MODULE_ENABLED /
#define HAL_EXTI_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_NAND_MODULE_ENABLED
#define HAL_NOR_MODULE_ENABLED
#define HAL_PCCARD_MODULE_ENABLED
#define HAL_SRAM_MODULE_ENABLED
/ #define HAL_SDRAM_MODULE_ENABLED /
#define HAL_HASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
#define HAL_I2S_MODULE_ENABLED
#define HAL_IWDG_MODULE_ENABLED
/ #define HAL_LTDC_MODULE_ENABLED /
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_RNG_MODULE_ENABLED
#define HAL_RTC_MODULE_ENABLED
/ #define HAL_SAI_MODULE_ENABLED /
#define HAL_SD_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
#define HAL_USART_MODULE_ENABLED
#define HAL_IRDA_MODULE_ENABLED
#define HAL_SMARTCARD_MODULE_ENABLED
#define HAL_WWDG_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_PCD_MODULE_ENABLED
#define HAL_HCD_MODULE_ENABLED#if !defined (HSE_VALUE) #define HSE_VALUE (8000000U) /! Value of the External oscillator in Hz /
#endif / HSE_VALUE /#if !defined (HSE_STARTUP_TIMEOUT)#define HSE_STARTUP_TIMEOUT (100U) /! Time out for HSE start up, in ms /
#endif / HSE_STARTUP_TIMEOUT /#if !defined (HSI_VALUE)#define HSI_VALUE (16000000U) /! Value of the Internal oscillator in Hz/
#endif / HSI_VALUE /#if !defined (LSI_VALUE)
#define LSI_VALUE (32000U)
#endif / LSI_VALUE / #if !defined (LSE_VALUE)
#define LSE_VALUE (32768U) /! Value of the External Low Speed oscillator in Hz /
#endif / LSE_VALUE /#if !defined (LSE_STARTUP_TIMEOUT)#define LSE_STARTUP_TIMEOUT (5000U) /! Time out for LSE start up, in ms /
#endif / LSE_STARTUP_TIMEOUT /#if !defined (EXTERNAL_CLOCK_VALUE)#define EXTERNAL_CLOCK_VALUE (12288000U) /! Value of the External oscillator in Hz/
#endif / EXTERNAL_CLOCK_VALUE /#define VDD_VALUE (3300U) /! Value of VDD in mv /
#define TICK_INT_PRIORITY (0x0FU) /! tick interrupt priority /
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U / The prefetch will be enabled in SystemClock_Config(), depending on the used STM32F405/415/07/417 device: RevA (prefetch must be off) or RevZ (prefetch can be on/off) /
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U#define USE_HAL_ADC_REGISTER_CALLBACKS 0U / ADC register callback disabled /
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U / CAN register callback disabled /
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U / CEC register callback disabled /
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U / CRYP register callback disabled /
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U / DAC register callback disabled /
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U / DCMI register callback disabled /
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U / DFSDM register callback disabled /
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U / DMA2D register callback disabled /
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U / DSI register callback disabled /
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U / ETH register callback disabled /
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U / HASH register callback disabled /
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U / HCD register callback disabled /
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U / I2C register callback disabled /
#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U / FMPI2C register callback disabled /
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U / I2S register callback disabled /
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U / IRDA register callback disabled /
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U / LPTIM register callback disabled /
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U / LTDC register callback disabled /
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U / MMC register callback disabled /
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U / NAND register callback disabled /
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U / NOR register callback disabled /
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U / PCCARD register callback disabled /
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U / PCD register callback disabled /
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U / QSPI register callback disabled /
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U / RNG register callback disabled /
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U / RTC register callback disabled /
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U / SAI register callback disabled /
#define USE_HAL_SD_REGISTER_CALLBACKS 0U / SD register callback disabled /
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U / SMARTCARD register callback disabled /
#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U / SDRAM register callback disabled /
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U / SRAM register callback disabled /
#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U / SPDIFRX register callback disabled /
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U / SMBUS register callback disabled /
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U / SPI register callback disabled /
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U / TIM register callback disabled /
#define USE_HAL_UART_REGISTER_CALLBACKS 0U / UART register callback disabled /
#define USE_HAL_USART_REGISTER_CALLBACKS 0U / USART register callback disabled /
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U / WWDG register callback disabled /#define USE_SPI_CRC 1U#ifdef HAL_RCC_MODULE_ENABLED#include stm32f4xx_hal_rcc.h
#endif / HAL_RCC_MODULE_ENABLED /#ifdef HAL_EXTI_MODULE_ENABLED#include stm32f4xx_hal_exti.h
#endif / HAL_EXTI_MODULE_ENABLED /#ifdef HAL_GPIO_MODULE_ENABLED#include stm32f4xx_hal_gpio.h
#endif / HAL_GPIO_MODULE_ENABLED /#ifdef HAL_DMA_MODULE_ENABLED#include stm32f4xx_hal_dma.h
#endif / HAL_DMA_MODULE_ENABLED /#ifdef HAL_CORTEX_MODULE_ENABLED#include stm32f4xx_hal_cortex.h
#endif / HAL_CORTEX_MODULE_ENABLED /#ifdef HAL_ADC_MODULE_ENABLED#include stm32f4xx_hal_adc.h
#endif / HAL_ADC_MODULE_ENABLED /#ifdef HAL_CAN_MODULE_ENABLED#include stm32f4xx_hal_can.h
#endif / HAL_CAN_MODULE_ENABLED /#ifdef HAL_CAN_LEGACY_MODULE_ENABLED#include stm32f4xx_hal_can_legacy.h
#endif / HAL_CAN_LEGACY_MODULE_ENABLED /#ifdef HAL_CRC_MODULE_ENABLED#include stm32f4xx_hal_crc.h
#endif / HAL_CRC_MODULE_ENABLED /#ifdef HAL_CRYP_MODULE_ENABLED#include stm32f4xx_hal_cryp.h
#endif / HAL_CRYP_MODULE_ENABLED /#ifdef HAL_DMA2D_MODULE_ENABLED#include stm32f4xx_hal_dma2d.h
#endif / HAL_DMA2D_MODULE_ENABLED /#ifdef HAL_DAC_MODULE_ENABLED#include stm32f4xx_hal_dac.h
#endif / HAL_DAC_MODULE_ENABLED /#ifdef HAL_DCMI_MODULE_ENABLED#include stm32f4xx_hal_dcmi.h
#endif / HAL_DCMI_MODULE_ENABLED /#ifdef HAL_ETH_MODULE_ENABLED#include stm32f4xx_hal_eth.h
#endif / HAL_ETH_MODULE_ENABLED /#ifdef HAL_FLASH_MODULE_ENABLED#include stm32f4xx_hal_flash.h
#endif / HAL_FLASH_MODULE_ENABLED /#ifdef HAL_SRAM_MODULE_ENABLED#include stm32f4xx_hal_sram.h
#endif / HAL_SRAM_MODULE_ENABLED /#ifdef HAL_NOR_MODULE_ENABLED#include stm32f4xx_hal_nor.h
#endif / HAL_NOR_MODULE_ENABLED /#ifdef HAL_NAND_MODULE_ENABLED#include stm32f4xx_hal_nand.h
#endif / HAL_NAND_MODULE_ENABLED /#ifdef HAL_PCCARD_MODULE_ENABLED#include stm32f4xx_hal_pccard.h
#endif / HAL_PCCARD_MODULE_ENABLED / #ifdef HAL_SDRAM_MODULE_ENABLED#include stm32f4xx_hal_sdram.h
#endif / HAL_SDRAM_MODULE_ENABLED /#ifdef HAL_HASH_MODULE_ENABLED
#include stm32f4xx_hal_hash.h
#endif / HAL_HASH_MODULE_ENABLED /#ifdef HAL_I2C_MODULE_ENABLED
#include stm32f4xx_hal_i2c.h
#endif / HAL_I2C_MODULE_ENABLED /#ifdef HAL_I2S_MODULE_ENABLED
#include stm32f4xx_hal_i2s.h
#endif / HAL_I2S_MODULE_ENABLED /#ifdef HAL_IWDG_MODULE_ENABLED
#include stm32f4xx_hal_iwdg.h
#endif / HAL_IWDG_MODULE_ENABLED /#ifdef HAL_LTDC_MODULE_ENABLED
#include stm32f4xx_hal_ltdc.h
#endif / HAL_LTDC_MODULE_ENABLED /#ifdef HAL_PWR_MODULE_ENABLED
#include stm32f4xx_hal_pwr.h
#endif / HAL_PWR_MODULE_ENABLED /#ifdef HAL_RNG_MODULE_ENABLED
#include stm32f4xx_hal_rng.h
#endif / HAL_RNG_MODULE_ENABLED /#ifdef HAL_RTC_MODULE_ENABLED
#include stm32f4xx_hal_rtc.h
#endif / HAL_RTC_MODULE_ENABLED /#ifdef HAL_SAI_MODULE_ENABLED
#include stm32f4xx_hal_sai.h
#endif / HAL_SAI_MODULE_ENABLED /#ifdef HAL_SD_MODULE_ENABLED
#include stm32f4xx_hal_sd.h
#endif / HAL_SD_MODULE_ENABLED /#ifdef HAL_SPI_MODULE_ENABLED
#include stm32f4xx_hal_spi.h
#endif / HAL_SPI_MODULE_ENABLED /#ifdef HAL_TIM_MODULE_ENABLED
#include stm32f4xx_hal_tim.h
#endif / HAL_TIM_MODULE_ENABLED /#ifdef HAL_UART_MODULE_ENABLED
#include stm32f4xx_hal_uart.h
#endif / HAL_UART_MODULE_ENABLED /#ifdef HAL_USART_MODULE_ENABLED
#include stm32f4xx_hal_usart.h
#endif / HAL_USART_MODULE_ENABLED /#ifdef HAL_IRDA_MODULE_ENABLED
#include stm32f4xx_hal_irda.h
#endif / HAL_IRDA_MODULE_ENABLED /#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include stm32f4xx_hal_smartcard.h
#endif / HAL_SMARTCARD_MODULE_ENABLED /#ifdef HAL_WWDG_MODULE_ENABLED
#include stm32f4xx_hal_wwdg.h
#endif / HAL_WWDG_MODULE_ENABLED /#ifdef HAL_PCD_MODULE_ENABLED
#include stm32f4xx_hal_pcd.h
#endif / HAL_PCD_MODULE_ENABLED /#ifdef HAL_HCD_MODULE_ENABLED
#include stm32f4xx_hal_hcd.h
#endif / HAL_HCD_MODULE_ENABLED */#ifdef USE_FULL_ASSERT#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)FILE__, LINE))void assert_failed(uint8_t* file, uint32_t line);
#else#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */#ifdef __cplusplus
}
#endif#endif 1.2.5 LL库配置stm32f4xx_ll_conf.h stm32f4xx_hal.h文件中会引用 stm32f4xx_ll_conf.h最重要的是实现assert_param函数 //自行创建
#ifndef __STM32F4xx_LL_CONF_H
#define __STM32F4xx_LL_CONF_H#ifdef cplusplus
extern C {
#endif#define stm32f4xx_ll_adc.h
#define stm32f4xx_ll_crc.h
#define stm32f4xx_ll_dac.h
#define stm32f4xx_ll_dma.h
#define stm32f4xx_ll_dma2d.h
#define stm32f4xx_ll_exti.h
#define stm32f4xx_ll_fmc.h
#define stm32f4xx_ll_fmpi2c.h
#define stm32f4xx_ll_fsmc.h
#define stm32f4xx_ll_gpio.h
#define stm32f4xx_ll_i2c.h
#define stm32f4xx_ll_lptim.h
#define stm32f4xx_ll_pwr.h
#define stm32f4xx_ll_rcc.h
#define stm32f4xx_ll_rng.h
#define stm32f4xx_ll_rtc.h
#define stm32f4xx_ll_sdmmc.h
#define stm32f4xx_ll_spi.h
#define stm32f4xx_ll_tim.h
#define stm32f4xx_ll_usart.h
#define stm32f4xx_ll_usb.h
#define stm32f4xx_ll_utils.h#ifdef USE_FULL_ASSERT#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)FILE__, LINE))void assert_failed(uint8_t* file, uint32_t line);
#else#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */#ifdef __cplusplus
}
#endif#endif 1.3 移植通用文件
1.3.1 标准外设库SPL Drivers/SPL/BSP目录 下存放用户开发的相应驱动文件如LED、Beep等。 Drivers/SPL/CMSIS目录 下存放下列文件 2.1 STM32F4xx_DSP_StdPeriph_Lib_V1.8.0–Libraries–CMSIS–Device–ST–STM32F4xx–Include stm32f4xx.h、system_stm32f4xx.h 2.2 STM32F4xx_DSP_StdPeriph_Lib_V1.8.0–Libraries–CMSIS–Device–ST–STM32F4xx–Source–Templates system_stm32f4xx.c 2.3 STM32F4xx_DSP_StdPeriph_Lib_V1.8.0–Libraries–CMSIS–Device–ST–STM32F4xx–Source–Templates–arm startup_stm32f40xx.s 2.4 STM32F4xx_DSP_StdPeriph_Lib_V1.8.0–Libraries–CMSIS–Include core_cm4.h、core_cmFunc.h、core_cmInstr.h、core_cmSimd.h Drivers/SPL/STM32F4xx_SPL_Driver目录 下存放下列文件 3.1 STM32F4xx_DSP_StdPeriph_Lib_V1.8.0–Libraries–STM32F4xx_StdPeriph_Driver–inc stm32f4xx_ppp.h 3.2 STM32F4xx_DSP_StdPeriph_Lib_V1.8.0–Libraries–STM32F4xx_StdPeriph_Driver–src stm32f4xx_ppp.c User目录 下存放下列文件 用户自己编写源码文件, stm32f4xx_conf.h、stm32f4xx_it.c、stm32f4xx_it.h 1.3.2 HAL库 Drivers/HAL/BSP目录 下存放用户开发的相应驱动文件如LED、Beep等。 Drivers/HAL/CMSIS目录 下存放下列文件 2.1 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Device–ST–STM32F4xx–Include stm32f4xx.h、stm32f407xx.h、system_stm32f4xx.h 2.2 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Device–ST–STM32F4xx–Source–Templates system_stm32f4xx.c 2.3 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Device–ST–STM32F4xx–Source–Templates–arm startup_stm32f407xx.s 2.4 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Include cmsis_armcc.h、cmsis_armclang.h、cmsis_compiler.h、cmsis_version.h、core_cm4.h、mpu_armv7.h Drivers/HAL/STM32F4xx_HAL_Driver目录 下存放下列文件 3.1 STM32Cube_FW_F4_V1.26.0–Drivers–STM32F4xx_HAL_Driver–Inc stm32f4xx_hal_ppp.h 3.2 STM32Cube_FW_F4_V1.26.0–Drivers–STM32F4xx_HAL_Driver–Src stm32f4xx_hal_ppp.c User目录 下存放下列文件 用户自己编写源码文件, stm32f4xx_hal_conf.h、stm32f4xx_it.h、stm32f4xx_it.h 1.3.3 LL库 Drivers/LL/BSP目录 下存放用户开发的相应驱动文件如LED、Beep等。 Drivers/LL/CMSIS目录 下存放下列文件 2.1 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Device–ST–STM32F4xx–Include stm32f4xx.h、stm32f407xx.h、system_stm32f4xx.h 2.2 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Device–ST–STM32F4xx–Source–Templates system_stm32f4xx.c 2.3 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Device–ST–STM32F4xx–Source–Templates–arm startup_stm32f407xx.s 2.4 STM32Cube_FW_F4_V1.26.0–Drivers–CMSIS–Include cmsis_armcc.h、cmsis_armclang.h、cmsis_compiler.h、cmsis_version.h、core_cm4.h、mpu_armv7.h Drivers/LL/STM32F4xx_LL_Driver目录 下存放下列文件 User目录 下存放下列文件 用户自己编写源码文件, stm32f4xx_ll_conf.h、stm32f4xx_it.h、stm32f4xx_it.h 1.4 修改相关文件SPL/HAL/LL库
1.4.1 启动文件 startup_stm32f40xx.s 屏蔽SystemInit函数的调用在外部实现系统时钟的配置。 Reset_Handler PROCEXPORT Reset_Handler [WEAK];IMPORT SystemInitIMPORT __main//寄存器版本代码因为没有用到 SystemInit 函数所以注释掉//库函数版本代码建议加上这里外部必须实现 SystemInit 函数以初始化 stm32 时钟等。;LDR R0, SystemInit;BLX R0 LDR R0, mainBX R0ENDP1.5 将移植的文件添加到工程中
1.5.1 标准外设库SPL ④选择AC5编译器因为AC6编译器对中文支持和代码兼容较差编译会出现很多告警。 全局宏变量STM32F40_41xxx,USE_STDPERIPH_DRIVER 移植所需的所有文件 Bsp空CMSISsystem_stm32f4xx.c、startup_stm32f40xx.sDriver只添加下列文件stm32f4xx_fmc.c不添加到工程否则编译会报错。CMiddlewares空Userstm32f4xx_it.c、main.c //main.c文件内容如下
#include stm32f4xx.h
void Delay(IO uint32_t nCount)
{while(nCount–){}
}
int main(void)
{GPIO_InitTypeDef GPIO_InitStructure;RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);GPIO_InitStructure.GPIO_Pin GPIO_Pin_9 | GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode GPIO_Mode_OUT;GPIO_InitStructure.GPIO_OType GPIO_OType_PP;GPIO_InitStructure.GPIO_Speed GPIO_Speed_100MHz;GPIO_InitStructure.GPIO_PuPd GPIO_PuPd_UP;GPIO_Init(GPIOF, GPIO_InitStructure);while(1){GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);Delay(0x7FFFFF);GPIO_ResetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);Delay(0x7FFFFF);}
}1.5.2 HAL库 同标准外设库SPL类似需要修改如下 全局宏变量STM32F407xx,USE_HAL_DRIVER头文件路径 移植所需的所有文件 Bsp空CMSISsystem_stm32f4xx.c、startup_stm32f407xx.sDriver只添加下列文件或添加所有文件除stm32f4xx_hal_timebase_rtc_alarm_template.c、stm32f4xx_hal_timebase_rtc_wakeup_template.c、stm32f4xx_hal_timebase_tim_template.c不添加到工程否则编译会报错。添加LL库文件是由于HAL库文件中会引用一些LL库的C文件。CMiddlewares空Userstm32f4xx_it.c、main.c //main.c文件内容如下
#include stm32f4xx.h
#include core_cm4.h
#include stm32f4xx_hal.h
void Delay(IO uint32_t nCount)
{while(nCount–){}
}
int main(void)
{HAL_Init(); GPIO_InitTypeDef gpio_init_struct;HAL_RCC_GPIOF_CLK_ENABLE(); gpio_init_struct.Pin GPIO_PIN_9; gpio_init_struct.Mode GPIO_MODE_OUTPUT_PP;gpio_init_struct.Pull GPIO_PULLUP; gpio_init_struct.Speed GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOF, gpio_init_struct); gpio_init_struct.Pin GPIO_PIN_10;HAL_GPIO_Init(GPIOF, gpio_init_struct); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9 ,GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET);while(1){HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_RESET); // LED0亮HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET); // LED1灭Delay(0x1FFFFF);HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET); // LED0灭HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET); // LED1亮Delay(0x1FFFFF);}
}1.5.3 LL库 同标准外设库SPL类似需要修改如下 全局宏变量USE_FULL_LL_DRIVER,STM32F407xx 头文件路径 移植所需的所有文件 Bsp空CMSISsystem_stm32f4xx.c、startup_stm32f407xx.sDriver添加下列文件CMiddlewares空Userstm32f4xx_it.c、main.c //main.c文件内容如下
#include stm32f4xx_ll_rcc.h
#include stm32f4xx_ll_bus.h
#include stm32f4xx_ll_system.h
#include stm32f4xx_ll_exti.h
#include stm32f4xx_ll_cortex.h
#include stm32f4xx_ll_utils.h
#include stm32f4xx_ll_pwr.h
#include stm32f4xx_ll_dma.h
#include stm32f4xx.h
#include stm32f4xx_ll_gpio.hvoid SystemClock_Config(void)
{LL_FLASH_SetLatency(LL_FLASH_LATENCY_5);if(LL_FLASH_GetLatency() ! LL_FLASH_LATENCY_5){}LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);LL_RCC_HSI_SetCalibTrimming(16);LL_RCC_HSI_Enable();while(LL_RCC_HSI_IsReady() ! 1) {}LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_8, 168,LL_RCC_PLLP_DIV_2);LL_RCC_PLL_Enable();while(LL_RCC_PLL_IsReady() ! 1) {}LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_4);LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_2);LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);while(LL_RCC_GetSysClkSource() ! LL_RCC_SYS_CLKSOURCE_STATUS_PLL){}LL_Init1msTick(168000000);LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);LL_SetSystemCoreClock(168000000);
}int main(void)
{LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);NVIC_SetPriorityGrouping(0x00000003);SystemClock_Config();LL_GPIO_InitTypeDef GPIO_InitStruct {0};LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF);LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOH);LL_GPIO_ResetOutputPin(GPIOF, LL_GPIO_PIN_9|LL_GPIO_PIN_10);GPIO_InitStruct.Pin LL_GPIO_PIN_9|LL_GPIO_PIN_10;GPIO_InitStruct.Mode LL_GPIO_MODE_OUTPUT;GPIO_InitStruct.Speed LL_GPIO_SPEED_FREQ_LOW;GPIO_InitStruct.OutputType LL_GPIO_OUTPUT_PUSHPULL;GPIO_InitStruct.Pull LL_GPIO_PULL_NO;LL_GPIO_Init(GPIOF, GPIO_InitStruct);while (1){LL_GPIO_TogglePin (GPIOF,LL_GPIO_PIN_9);LL_GPIO_SetOutputPin(GPIOF,LL_GPIO_PIN_10);LL_mDelay(500);LL_GPIO_ResetOutputPin(GPIOF,LL_GPIO_PIN_10);LL_mDelay(500);}
}编译会报错将文件 stm32f4xx_ll_fmc.c、stm32f4xx_ll_fsmc.c、stm32f4xx_ll_sdmmc.c、stm32f4xx_ll_usb.c 中的下列内容注释 //#include stm32f4xx_hal.h2. 创建lib库
2.1 创建标准外设库SPL库 将创建lib库所需的下列所有头文件存放到 C:\Keil_v5\ARM\inc 目录下如果没有此目录可自行创建。 2.2 创建HAL库 将创建lib库所需的下列所有头文件存放到 C:\Keil_v5\ARM\hal_inc 目录下如果没有此目录可自行创建。 添加步骤同 创建标准外设库SPL库 2.3 创建LL库 将创建lib库所需的下列所有头文件存放到 C:\Keil_v5\ARM\ll_inc 目录下如果没有此目录可自行创建。 添加步骤同 创建标准外设库SPL库
- 上一篇: 免费制作论坛网站网站上写个招贤纳士怎么做
- 下一篇: 免费制作自己的网站长中山做网站好的公司
相关文章
-
免费制作论坛网站网站上写个招贤纳士怎么做
免费制作论坛网站网站上写个招贤纳士怎么做
- 技术栈
- 2026年03月21日
-
免费制作ai视频的软件wordpress seo插件
免费制作ai视频的软件wordpress seo插件
- 技术栈
- 2026年03月21日
-
免费只做网站网络营销权威概念是
免费只做网站网络营销权威概念是
- 技术栈
- 2026年03月21日
-
免费制作自己的网站长中山做网站好的公司
免费制作自己的网站长中山做网站好的公司
- 技术栈
- 2026年03月21日
-
免费中英文网站源码wordpress说明
免费中英文网站源码wordpress说明
- 技术栈
- 2026年03月21日
-
免费注册建网站云教育科技网站建设
免费注册建网站云教育科技网站建设
- 技术栈
- 2026年03月21日
