STM32創建靜態庫lib

創建靜態庫lib

  • 1. 新建工程
    • 1.1 創建工程文件夾
    • 1.2 編寫用戶相關代碼
      • 1.2.1 stm32f4xx_it.h
      • 1.2.2 stm32f4xx_it.c
      • 1.2.3 標準庫配置:stm32f4xx_conf.h
      • 1.2.4 HAL庫的配置:stm32f4xx_hal_conf.h
      • 1.2.5 LL庫配置:stm32f4xx_ll_conf.h
    • 1.3 移植通用文件
      • 1.3.1 標準外設庫SPL
      • 1.3.2 HAL庫
      • 1.3.3 LL庫
    • 1.4 修改相關文件(SPL/HAL/LL庫)
      • 1.4.1 啟動文件 startup_stm32f40xx.s
    • 1.5 將移植的文件添加到工程中
      • 1.5.1 標準外設庫SPL
      • 1.5.2 HAL庫
      • 1.5.3 LL庫
  • 2. 創建lib庫
    • 2.1 創建標準外設庫SPL庫
    • 2.2 創建HAL庫
    • 2.3 創建LL庫

//標準外設庫SPL
#include	"stm32f4xx.h"void Delay(__IO uint32_t nCount);
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. 新建工程

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.h"void 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 #endif

1.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

  1. Drivers/SPL/BSP目錄 下存放用戶開發的相應驅動文件,如LED、Beep等。

  2. 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

  3. 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

  4. User目錄 下存放下列文件 :
    用戶自己編寫源碼文件, stm32f4xx_conf.h、stm32f4xx_it.c、stm32f4xx_it.h

1.3.2 HAL庫

  1. Drivers/HAL/BSP目錄 下存放用戶開發的相應驅動文件,如LED、Beep等。

  2. 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

  3. 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

  4. User目錄 下存放下列文件 :
    用戶自己編寫源碼文件, stm32f4xx_hal_conf.h、stm32f4xx_it.h、stm32f4xx_it.h

1.3.3 LL庫

  1. Drivers/LL/BSP目錄 下存放用戶開發的相應驅動文件,如LED、Beep等。

  2. 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

  3. Drivers/LL/STM32F4xx_LL_Driver目錄 下存放下列文件 :
    在這里插入圖片描述

  4. 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 R0ENDP

1.5 將移植的文件添加到工程中

1.5.1 標準外設庫SPL

在這里插入圖片描述
選擇AC5編譯器,因為AC6編譯器對中文支持和代碼兼容較差,編譯會出現很多告警。
全局宏變量:STM32F40_41xxx,USE_STDPERIPH_DRIVER

?
移植所需的所有文件:

Bsp
CMSISsystem_stm32f4xx.cstartup_stm32f40xx.s
Driver只添加下列文件:
在這里插入圖片描述
stm32f4xx_fmc.c不添加到工程,否則編譯會報錯。
CMiddlewares
Userstm32f4xx_it.cmain.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類似,需要修改如下:

  1. 全局宏變量:STM32F407xx,USE_HAL_DRIVER
  2. 頭文件路徑:
    在這里插入圖片描述
  3. 移植所需的所有文件
Bsp
CMSISsystem_stm32f4xx.cstartup_stm32f407xx.s
Driver只添加下列文件:
在這里插入圖片描述
或添加所有文件,除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.cmain.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類似,需要修改如下:

  1. 全局宏變量:USE_FULL_LL_DRIVER,STM32F407xx

  2. 頭文件路徑:
    在這里插入圖片描述

  3. 移植所需的所有文件

Bsp
CMSISsystem_stm32f4xx.cstartup_stm32f407xx.s
Driver添加下列文件:在這里插入圖片描述
CMiddlewares
Userstm32f4xx_it.cmain.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.h"void 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.h"

2. 創建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庫

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/70181.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/70181.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/70181.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

elabradio入門第二講——BPSK數字調制與解調(插值、升余弦濾波、速率匹配、符號同步)

數字信號可以通過數字基帶傳輸系統進行傳輸&#xff0c;而基帶傳輸系統僅僅適用于低頻信道下的數字信號傳輸。然而&#xff0c;在實際的通信系統中信道通常具有帶通特性&#xff0c;因而需要將基帶信號搬移到適合信道傳輸的高頻載波上&#xff0c;使得信號與信道相匹配&#xf…

汽車 OTA 升級:提升下載與升級速度,優化用戶體驗

摘要&#xff1a; 隨著汽車智能化的飛速發展&#xff0c;OTA&#xff08;Over - the - Air&#xff09;升級已成為汽車行業的重要技術&#xff0c;它能為車輛持續帶來功能更新與性能優化。然而&#xff0c;下載及升級速度較慢的問題常常影響用戶體驗。本文深入探討在汽車 OTA …

【Spring+MyBatis】留言墻的實現

目錄 1. 添加依賴 2. 配置數據庫 2.1 創建數據庫與數據表 2.2 創建與數據庫對應的實體類 3. 后端代碼 3.1 目錄結構 3.2 MessageController類 3.3 MessageService類 3.4 MessageMapper接口 4. 前端代碼 5. 單元測試 5.1 后端接口測試 5.2 使用前端頁面測試 在Spri…

SQLite Select 語句詳解

SQLite Select 語句詳解 SQLite 是一個輕量級的數據庫管理系統&#xff0c;以其簡潔的設計和高效的性能被廣泛應用于各種場景。在 SQLite 中&#xff0c;SELECT 語句是用于查詢數據庫中的數據的命令。本文將詳細介紹 SQLite 的 SELECT 語句&#xff0c;包括其基本語法、常用功…

深度學習05 ResNet殘差網絡

目錄 傳統卷積神經網絡存在的問題 如何解決 批量歸一化BatchNormalization, BN 殘差連接方式 ?殘差結構 ResNet網絡 ResNet 網絡是在 2015年 由微軟實驗室中的何凱明等幾位大神提出&#xff0c;斬獲當年ImageNet競賽中分類任務第一名&#xff0c;目標檢測第一名。獲得CO…

組件庫地址

react&#xff1a; https://react-vant.3lang.dev/components/dialoghttps://react-vant.3lang.dev/components/dialog vue用v2的 Vant 2 - Mobile UI Components built on Vue

docker 進階命令(基于Ubuntu)

數據卷 Volume: 目錄映射, 目錄掛載 匿名綁定: 匿名綁定的 volume 在容器刪除的時候, 數據卷也會被刪除, 匿名綁定是不能做到持久化的, 地址一般是 /var/lib/docker/volumes/xxxxx/_data 綁定卷時修改宿主機的目錄或文件, 容器內的數據也會同步修改, 反之亦然 # 查看所有 vo…

從入門到精通:Postman 實用指南

Postman 是一款超棒的 API 開發工具&#xff0c;能用來測試、調試和管理 API&#xff0c;大大提升開發效率。下面就給大家詳細講講它的安裝、使用方法&#xff0c;再分享些實用技巧。 一、安裝 Postman 你能在 Postman 官網&#xff08;https://www.postman.com &#xff09;下…

將圖片base64編碼后,數據轉成圖片

將圖片數據進行base64編碼后&#xff0c;可以在瀏覽器上查看圖片&#xff0c;只需在前端加上data:image/png;base64,即可 在線工具&#xff1a; Base64轉圖片 - 加菲工具

【動態規劃】詳解 0-1背包問題

文章目錄 1. 問題引入2. 從 dfs 到動態規劃3. 動態規劃過程分析4. 二維 dp 的遍歷順序5. 從二維數組到一維數組6. 一維數組的遍歷次序7. 背包的遍歷順序8. 代碼總結9. 總結 1. 問題引入 0-1 背包是比較經典的動態規劃問題&#xff0c;這里以代碼隨想錄里面的例子來介紹下。總的…

LeetCode每日精進:20.有效的括號

題目鏈接&#xff1a;20.有效的括號 題目描述&#xff1a; 給定一個只包括 (&#xff0c;)&#xff0c;{&#xff0c;}&#xff0c;[&#xff0c;] 的字符串 s &#xff0c;判斷字符串是否有效。 有效字符串需滿足&#xff1a; 左括號必須用相同類型的右括號閉合。左括號必須以…

llama.cpp部署 DeepSeek-R1 模型

一、llama.cpp 介紹 使用純 C/C推理 Meta 的LLaMA模型&#xff08;及其他模型&#xff09;。主要目標llama.cpp是在各種硬件&#xff08;本地和云端&#xff09;上以最少的設置和最先進的性能實現 LLM 推理。純 C/C 實現&#xff0c;無任何依賴項Apple 芯片是一流的——通過 A…

Web后端 - Maven管理工具

一 Maven簡單介紹 Maven是apache旗下的一個開源項目&#xff0c;是一款用于管理和構建java項目的工具。 Maven的作用 二 Maven 安裝配置 依賴配置 依賴傳遞 依賴范圍 生命周期 注意事項&#xff1a;在同一套生命周期中&#xff0c;當運行后面的階段時&#xff0c;前面的階段都…

[LeetCode力扣hot100]-C++常用數據結構

0.Vector 1.Set-常用滑動窗口 set<char> ans;//根據類型定義&#xff0c;像vector ans.count()//檢查某個元素是否在set里&#xff0c;1在0不在 ans.insert();//插入元素 ans.erase()//刪除某個指定元素 2.棧 3.樹 樹是一種特殊的數據結構&#xff0c;力扣二叉樹相…

vite+vue3開發uni-app時低版本瀏覽器不支持es6語法的問題排坑筆記

重要提示&#xff1a;請首先完整閱讀完文章內容后再操作&#xff0c;以免不必要的時間浪費&#xff01;切記&#xff01;&#xff01;&#xff01;在使用vitevue3開發uni-app項目時&#xff0c;存在低版本瀏覽器不兼容es6語法的問題&#xff0c;如“?.” “??” 等。為了方便…

《計算機視覺》——角點檢測和特征提取sift

角點檢測 角點的定義&#xff1a; 從直觀上理解&#xff0c;角點是圖像中兩條或多條邊緣的交點&#xff0c;在圖像中表現為局部區域內的灰度變化較為劇烈的點。在數學和計算機視覺中&#xff0c;角點可以被定義為在兩個或多個方向上具有顯著變化的點。比如在一幅建筑物的圖像…

WWW 2025 | 中南、微軟提出端到端雙重動態推薦模型,釋放LLM在序列推薦中的潛力...

©PaperWeekly 原創 作者 | 殷珺 單位 | 中南大學碩士研究生 研究方向 | 大語言模型、推薦系統 論文題目&#xff1a; Unleash LLMs Potential for Sequential Recommendation by Coordinating Dual Dynamic Index Mechanism 論文鏈接&#xff1a; https://openreview.net…

c# 2025/2/17 周一

16. 《表達式&#xff0c;語句詳解4》 20 未完。。 表達式&#xff0c;語句詳解_4_嗶哩嗶哩_bilibili

數據結構與算法面試專題——堆排序

完全二叉樹 完全二叉樹中如果每棵子樹的最大值都在頂部就是大根堆 完全二叉樹中如果每棵子樹的最小值都在頂部就是小根堆 設計目標&#xff1a;完全二叉樹的設計目標是高效地利用存儲空間&#xff0c;同時便于進行層次遍歷和數組存儲。它的結構使得每個節點的子節點都可以通過簡…

iOS開發書籍推薦 - 《高性能 iOS應用開發》(附帶鏈接)

引言 在 iOS 開發的過程中&#xff0c;隨著應用功能的增加和用戶需求的提升&#xff0c;性能優化成為了不可忽視的一環。尤其是面對復雜的界面、龐大的數據處理以及不斷增加的后臺操作&#xff0c;如何確保應用的流暢性和響應速度&#xff0c;成為開發者的一大挑戰。《高性能 …