Structure changing

This commit is contained in:
Vasily Markov 2024-03-28 17:51:39 +03:00
parent 60c580b634
commit 2ac496daf4
6 changed files with 65 additions and 35 deletions

View File

@ -25,6 +25,7 @@ add_compile_definitions(HSE_VALUE=8000000)
include_directories( include_directories(
${PROJECT_SOURCE_DIR}/bsp ${PROJECT_SOURCE_DIR}/bsp
${PROJECT_SOURCE_DIR}/app
${PROJECT_SOURCE_DIR}/lib ${PROJECT_SOURCE_DIR}/lib
${PROJECT_SOURCE_DIR}/lib/CMSIS ${PROJECT_SOURCE_DIR}/lib/CMSIS
${PROJECT_SOURCE_DIR}/lib/STM32F4xx ${PROJECT_SOURCE_DIR}/lib/STM32F4xx
@ -34,6 +35,7 @@ include_directories(
file(GLOB_RECURSE SOURCES file(GLOB_RECURSE SOURCES
"main.c" "main.c"
"bsp/bsp.c" "bsp/bsp.c"
"app/app.c"
"system_stm32f4xx.c" "system_stm32f4xx.c"
"startup_stm32f4xx.S" "startup_stm32f4xx.S"
"lib/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c" "lib/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c"

View File

@ -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();
};
}

View File

@ -0,0 +1,7 @@
#ifndef APP_H
#define APP_H
#include "bsp.h"
void app();
#endif

View File

@ -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);
}

View File

@ -1,12 +1,11 @@
#ifndef BSP_H
#define BSP_H
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_gpio.h" #include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h" #include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h" #include "stm32f4xx_usart.h"
const uint16_t LEDS = GPIO_Pin_0 | GPIO_Pin_7 | GPIO_Pin_14; void board_init();
const uint16_t LED[4] = {GPIO_Pin_0, GPIO_Pin_7, GPIO_Pin_14};
void init(); #endif
void loop();
void delay();

33
main.c
View File

@ -1,38 +1,13 @@
#include "bsp.h" #include "bsp.h"
#include "app.h"
int main() { int main() {
init(); board_init();
app();
do {
loop();
} while (1);
} }
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();
}
}