diff --git a/CMakeLists.txt b/CMakeLists.txt index 90c17a2..3353425 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ set(TARGET_SOURCES "SDK/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_ll_utils.c" "SDK/Drivers/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f030x6.s" "SDK/Drivers/CMSIS/Device/PY32F0xx/Source/system_py32f0xx.c" + "board/board.c" "src/py32f0xx_hal_msp.c" "src/py32f0xx_it.c" "src/app_syscalls.c" @@ -67,6 +68,7 @@ set(TARGET_C_INCLUDES "SDK/Drivers/PY32F0xx_HAL_Driver/Inc" "SDK/Drivers/CMSIS/Include" "SDK/Drivers/CMSIS/Device/PY32F0xx/Include" + "board" "include" ) diff --git a/board/board.c b/board/board.c new file mode 100644 index 0000000..230da30 --- /dev/null +++ b/board/board.c @@ -0,0 +1,16 @@ +#include "board.h" + +#include "py32f0xx_hal.h" + +void BOARD_InitBootPins(void) { + __HAL_RCC_GPIOB_CLK_ENABLE(); + + GPIO_InitTypeDef init = { + .Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3, + .Mode = GPIO_MODE_OUTPUT_PP, + .Speed = GPIO_SPEED_FREQ_LOW, + .Pull = GPIO_NOPULL, + }; + + HAL_GPIO_Init(GPIOB, &init); +} \ No newline at end of file diff --git a/board/board.h b/board/board.h new file mode 100644 index 0000000..3f5fdcf --- /dev/null +++ b/board/board.h @@ -0,0 +1,14 @@ +#ifndef BOARD_H +#define BOARD_H + +#define BOARD_LED_1_PORT GPIOB +#define BOARD_LED_2_PORT GPIOB +#define BOARD_LED_3_PORT GPIOB + +#define BOARD_LED_1_PIN GPIO_PIN_1 +#define BOARD_LED_2_PIN GPIO_PIN_0 +#define BOARD_LED_3_PIN_GPIO_PIN_3 + +void BOARD_InitBootPins(void); + +#endif // BOARD_H diff --git a/src/main.c b/src/main.c index a08acee..a79b4be 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,8 @@ #include +/* BSP */ +#include "board.h" + /* App */ #include "app_syscalls.h" #include "main.h" @@ -9,11 +12,14 @@ UART_HandleTypeDef huart1; int main(void) { HAL_Init(); + BOARD_InitBootPins(); + app_syscalls_init(); printf("Hello world.\r\n"); for (;;) { - /* -- */ + HAL_GPIO_TogglePin(BOARD_LED_1_PORT, BOARD_LED_1_PIN); + HAL_Delay(500); } } \ No newline at end of file