From 2ac496daf4d70d5a85528bb3cc2f1a9c7eab4828 Mon Sep 17 00:00:00 2001 From: Vasily Markov Date: Thu, 28 Mar 2024 17:51:39 +0300 Subject: [PATCH] Structure changing --- CMakeLists.txt | 2 ++ app/app.c | 30 ++++++++++++++++++++++++++++++ app/app.h | 7 +++++++ bsp/bsp.c | 17 +++++++++++++++++ bsp/bsp.h | 11 +++++------ main.c | 33 ++++----------------------------- 6 files changed, 65 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b56d182..5d19deb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ add_compile_definitions(HSE_VALUE=8000000) include_directories( ${PROJECT_SOURCE_DIR}/bsp + ${PROJECT_SOURCE_DIR}/app ${PROJECT_SOURCE_DIR}/lib ${PROJECT_SOURCE_DIR}/lib/CMSIS ${PROJECT_SOURCE_DIR}/lib/STM32F4xx @@ -34,6 +35,7 @@ include_directories( file(GLOB_RECURSE SOURCES "main.c" "bsp/bsp.c" + "app/app.c" "system_stm32f4xx.c" "startup_stm32f4xx.S" "lib/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c" diff --git a/app/app.c b/app/app.c index e69de29..3a44d91 100644 --- a/app/app.c +++ b/app/app.c @@ -0,0 +1,30 @@ +#include "app.h" + +const uint16_t leds = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14; +const uint16_t leds_arr[4] = {GPIO_Pin_0, GPIO_Pin_7, GPIO_Pin_14}; + +void delay(uint32_t ms) { + ms *= 3360; + while(ms--) { + __NOP(); + } +} + +void loop() { + static uint32_t counter = 0; + + ++counter; + + GPIO_ResetBits(GPIOB, leds); + GPIO_SetBits(GPIOB, leds_arr[counter % 3]); + + delay(250); +} + +void app() { + + while(1) { + loop(); + }; +} + diff --git a/app/app.h b/app/app.h index e69de29..8261717 100644 --- a/app/app.h +++ b/app/app.h @@ -0,0 +1,7 @@ +#ifndef APP_H +#define APP_H +#include "bsp.h" + +void app(); + +#endif \ No newline at end of file diff --git a/bsp/bsp.c b/bsp/bsp.c index e69de29..4717fe1 100644 --- a/bsp/bsp.c +++ b/bsp/bsp.c @@ -0,0 +1,17 @@ +#include "bsp.h" + +const uint16_t LEDS = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14; +const uint16_t LED[4] = {GPIO_Pin_0, GPIO_Pin_7, GPIO_Pin_14}; + +void board_init() { + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); + GPIO_InitTypeDef gpio; + GPIO_StructInit(&gpio); + gpio.GPIO_Mode = GPIO_Mode_OUT; + gpio.GPIO_Pin = LEDS; + GPIO_Init(GPIOB, &gpio); + + GPIO_SetBits(GPIOB, LEDS); +} + + diff --git a/bsp/bsp.h b/bsp/bsp.h index 68cff2b..5bbfbca 100644 --- a/bsp/bsp.h +++ b/bsp/bsp.h @@ -1,12 +1,11 @@ +#ifndef BSP_H +#define BSP_H + #include "stm32f4xx.h" #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_usart.h" -const uint16_t LEDS = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14; -const uint16_t LED[4] = {GPIO_Pin_0, GPIO_Pin_7, GPIO_Pin_14}; +void board_init(); -void init(); -void loop(); - -void delay(); +#endif diff --git a/main.c b/main.c index 3bf8140..68937e3 100644 --- a/main.c +++ b/main.c @@ -1,38 +1,13 @@ #include "bsp.h" +#include "app.h" + int main() { - init(); - - do { - loop(); - } while (1); + board_init(); + app(); } -void init() { - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); - GPIO_InitTypeDef gpio; - GPIO_StructInit(&gpio); - gpio.GPIO_Mode = GPIO_Mode_OUT; - gpio.GPIO_Pin = LEDS; - GPIO_Init(GPIOB, &gpio); - GPIO_SetBits(GPIOB, LEDS); -} -void loop() { - static uint32_t counter = 0; - ++counter; - GPIO_ResetBits(GPIOB, LEDS); - GPIO_SetBits(GPIOB, LED[counter % 3]); - - delay(250); -} - -void delay(uint32_t ms) { - ms *= 3360; - while(ms--) { - __NOP(); - } -}