stm32f1xx HAL library configuration instructions

1. Engineering configuration

  1. Add the downloaded firmware library to the project directory, and add the corresponding files to the project, taking the blinking LED light as an example.
  2. Create new user and proj folders.
  3. Copy STM32Cube_FW_F1_V1.4.0\Drivers\STM32F1xx_HAL_Driver\Incthe in stm32f1xx_hal_conf_template.hto the user directory and rename it to stm32f1xx_hal_conf.h.
  4. STM32Cube_FW_F1_V1.4.0\Projects\STM32F103RB-Nucleo\Templates\SrcCopy inside the folder andstm32f1xx_it.c inside the folder to the user folder. If in is empty, please add in the place where the header file is placed in the file as shown in the figure below: , and add it in the function , as shown in the figure below: .STM32Cube_FW_F1_V1.4.0\Projects\STM32F103RB-Nucleo\Templates\Incstm32f1xx_it.hstm32f1xx_it.cSysTick_Handler#include "stm32f1xx.h"
    Pic 4-1
    SysTick_HandlerHAL_IncTick();
    Figure 4-2
  5. Create a new C file and enter the routine.
  6. Add the program code, STM32Cube_FW_F1_V1.4.0\Drivers\STM32F1xx_HAL_Driver\Srcthe microcontroller driver in the folder (add as needed), the startup file in the STM32Cube_FW_F1_V1.4.0\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templatesfolder system_stm32f1xx.c, STM32Cube_FW_F1_V1.4.0\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\armthe startup file in the folder (add according to the actual situation), the program file in the userfolder stm32f1xx_it.cand gpio_demo.cthe program file added to the project as shown in the figure below :
    Figure 4-3
  7. The added header file path is shown in the following figure:
    Figure 4-4
  8. STM32F103xE,USE_HAL_DRIVERAdd (view ) in the c/c++ compiler option macro definition column stm32f1xx.h, as shown in the following figure:
    Figure 4-5
  9. compile

2. Routines

#include "stm32f1xx.h"  

void bsp_led_init( void )
{
    GPIO_InitTypeDef gpioInitStructure;

    __HAL_RCC_GPIOD_CLK_ENABLE();
    __HAL_RCC_GPIOG_CLK_ENABLE();

    gpioInitStructure.Mode  = GPIO_MODE_OUTPUT_PP;
    gpioInitStructure.Pull  = GPIO_NOPULL;
    gpioInitStructure.Speed = GPIO_SPEED_FREQ_LOW;
    gpioInitStructure.Pin   = GPIO_PIN_13;

    HAL_GPIO_Init(GPIOD, &gpioInitStructure);

    gpioInitStructure.Mode  = GPIO_MODE_OUTPUT_PP;
    gpioInitStructure.Pull  = GPIO_NOPULL;
    gpioInitStructure.Speed = GPIO_SPEED_FREQ_LOW;
    gpioInitStructure.Pin   = GPIO_PIN_14;

    HAL_GPIO_Init(GPIOG, &gpioInitStructure);
}

void bsp_led_run( void )
{
    HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
    HAL_Delay(30);

    HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_14);
    HAL_Delay(70);
}

int main( void )
{
#ifdef USE_HAL_DRIVER
    HAL_Init();
#endif

    bsp_led_init();

    while(1)
    {
        bsp_led_run();
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325719233&siteId=291194637