diff --git a/STM_sdk/Core/Src/stm32f4xx_hal_msp.c b/STM_sdk/Core/Src/stm32f4xx_hal_msp.c index 18c4db5..07efcb7 100644 --- a/STM_sdk/Core/Src/stm32f4xx_hal_msp.c +++ b/STM_sdk/Core/Src/stm32f4xx_hal_msp.c @@ -1,28 +1,25 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32f4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32f4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" -// #include "STM_main.h" -// #include "../../Main/include/Main/main.h" -// #include "../../Main/include/Main/main.h" +#include "stm32f4xx_hal.h" /* USER CODE BEGIN Includes */ @@ -62,10 +59,9 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ + * Initializes the Global MSP. + */ +void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ @@ -86,11 +82,9 @@ void HAL_MspInit(void) * @param hdac: DAC handle pointer * @retval None */ -void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) -{ +void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (hdac->Instance == DAC) - { + if (hdac->Instance == DAC) { /* USER CODE BEGIN DAC_MspInit 0 */ /* USER CODE END DAC_MspInit 0 */ @@ -118,10 +112,8 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) * @param hdac: DAC handle pointer * @retval None */ -void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac) -{ - if (hdac->Instance == DAC) - { +void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac) { + if (hdac->Instance == DAC) { /* USER CODE BEGIN DAC_MspDeInit 0 */ /* USER CODE END DAC_MspDeInit 0 */ @@ -140,16 +132,14 @@ void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac) } /** -* @brief UART MSP Initialization -* This function configures the hardware resources used in this example -* @param huart: UART handle pointer -* @retval None -*/ -void HAL_UART_MspInit(UART_HandleTypeDef *huart) -{ + * @brief UART MSP Initialization + * This function configures the hardware resources used in this example + * @param huart: UART handle pointer + * @retval None + */ +void HAL_UART_MspInit(UART_HandleTypeDef *huart) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (huart->Instance == USART2) - { + if (huart->Instance == USART2) { /* USER CODE BEGIN USART2_MspInit 0 */ /* USER CODE END USART2_MspInit 0 */ @@ -183,10 +173,8 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) * @param huart: UART handle pointer * @retval None */ -void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) -{ - if (huart->Instance == USART2) - { +void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) { + if (huart->Instance == USART2) { /* USER CODE BEGIN USART2_MspDeInit 0 */ /* USER CODE END USART2_MspDeInit 0 */ @@ -213,11 +201,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) * @param htim_encoder: TIM_Encoder handle pointer * @retval None */ -void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim_encoder) -{ +void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim_encoder) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (htim_encoder->Instance == TIM2) - { + if (htim_encoder->Instance == TIM2) { /* USER CODE BEGIN TIM2_MspInit 0 */ /* USER CODE END TIM2_MspInit 0 */ @@ -248,10 +234,8 @@ void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim_encoder) * @param htim_encoder: TIM_Encoder handle pointer * @retval None */ -void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim_encoder) -{ - if (htim_encoder->Instance == TIM2) - { +void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim_encoder) { + if (htim_encoder->Instance == TIM2) { /* USER CODE BEGIN TIM2_MspDeInit 0 */ /* USER CODE END TIM2_MspDeInit 0 */ diff --git a/STM_sdk/Core/Src/stm32f4xx_it.c b/STM_sdk/Core/Src/stm32f4xx_it.c index 8d339b0..ea55af0 100644 --- a/STM_sdk/Core/Src/stm32f4xx_it.c +++ b/STM_sdk/Core/Src/stm32f4xx_it.c @@ -1,27 +1,24 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32f4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32f4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" -// #include "STM_main.h" -// #include "../../Main/include/Main/Main.h" -// #include "../../Main/include/Main/main.h" +#include "stm32f4xx_hal.h" #include "stm32f4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -68,85 +65,74 @@ extern UART_HandleTypeDef huart2; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ -void NMI_Handler(void) -{ + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - while (1) - { + while (1) { } /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ -void HardFault_Handler(void) -{ + * @brief This function handles Hard fault interrupt. + */ +void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } } /** - * @brief This function handles Memory management fault. - */ -void MemManage_Handler(void) -{ + * @brief This function handles Memory management fault. + */ +void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } } /** - * @brief This function handles Pre-fetch fault, memory access fault. - */ -void BusFault_Handler(void) -{ + * @brief This function handles Pre-fetch fault, memory access fault. + */ +void BusFault_Handler(void) { /* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */ } } /** - * @brief This function handles Undefined instruction or illegal state. - */ -void UsageFault_Handler(void) -{ + * @brief This function handles Undefined instruction or illegal state. + */ +void UsageFault_Handler(void) { /* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { + while (1) { /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */ } } /** - * @brief This function handles System service call via SWI instruction. - */ -void SVC_Handler(void) -{ + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) { /* USER CODE BEGIN SVCall_IRQn 0 */ /* USER CODE END SVCall_IRQn 0 */ @@ -156,10 +142,9 @@ void SVC_Handler(void) } /** - * @brief This function handles Debug monitor. - */ -void DebugMon_Handler(void) -{ + * @brief This function handles Debug monitor. + */ +void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ @@ -169,10 +154,9 @@ void DebugMon_Handler(void) } /** - * @brief This function handles Pendable request for system service. - */ -void PendSV_Handler(void) -{ + * @brief This function handles Pendable request for system service. + */ +void PendSV_Handler(void) { /* USER CODE BEGIN PendSV_IRQn 0 */ /* USER CODE END PendSV_IRQn 0 */ @@ -182,10 +166,9 @@ void PendSV_Handler(void) } /** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) -{ + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ @@ -205,8 +188,7 @@ void SysTick_Handler(void) /** * @brief This function handles USART2 global interrupt. */ -void USART2_IRQHandler(void) -{ +void USART2_IRQHandler(void) { /* USER CODE BEGIN USART2_IRQn 0 */ /* USER CODE END USART2_IRQn 0 */ diff --git a/src/Main.lf b/src/Main.lf index ac1b9f3..2214a60 100644 --- a/src/Main.lf +++ b/src/Main.lf @@ -1,9 +1,8 @@ target C { single-threaded: true, - platform: { - name: "STM32", - board: "F446RE" - } + platform: "STM32F4", + cmake-include: "cmake/stm.cmake", + cmake-init-include: "cmake/stm-init.cmake", } preamble {= diff --git a/src/cmake/arm-none-eabi-gcc.cmake b/src/cmake/arm-none-eabi-gcc.cmake new file mode 100644 index 0000000..2e49051 --- /dev/null +++ b/src/cmake/arm-none-eabi-gcc.cmake @@ -0,0 +1,23 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) + +# Some default GCC settings +set(TOOLCHAIN_PREFIX arm-none-eabi-) +set(FLAGS + "-fdata-sections -ffunction-sections \ + --specs=nano.specs -Wl,--gc-sections") +set(CPP_FLAGS + "-fno-rtti -fno-exceptions \ + -fno-threadsafe-statics") + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS}) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS}) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) + +set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) \ No newline at end of file diff --git a/src/cmake/stm-init.cmake b/src/cmake/stm-init.cmake new file mode 100644 index 0000000..6520b63 --- /dev/null +++ b/src/cmake/stm-init.cmake @@ -0,0 +1,46 @@ +# Includes the correct toolchain file and sets global compile options, linker options +# compile definitions and include directories for the STM32F446RE MCU. + +set(CMAKE_TOOLCHAIN_FILE ${LF_SOURCE_DIRECTORY}/cmake/arm-none-eabi-gcc.cmake) + +set(MCU_FAMILY STM32F4xx) +set(MCU_MODEL STM32F446xx) +set(CPU_PARAMETERS -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp) + +set(STM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../STM_sdk) +set(MCU_LINKER_SCRIPT ${STM_DIR}/STM32F446RETx_FLASH.ld) + +add_compile_options( + ${CPU_PARAMETERS} + -Wall + -Wextra + -Wpedantic + -Wno-unused-parameter +) + +add_link_options( + -T${MCU_LINKER_SCRIPT} + ${CPU_PARAMETERS} + -Wl,-Map=${CMAKE_PROJECT_NAME}.map + --specs=nosys.specs + -Wl,--start-group + -lc + -lm + -lstdc++ + -Wl,--end-group + -Wl,--print-memory-usage) + + +add_compile_definitions(${MCU_MODEL} USE_HAL_DRIVER) + +set(CUBEMX_INCLUDE_DIRECTORIES + ${PROJECT_DIR} + ${PROJECT_DIR}/include/Main + ${STM_DIR}/Core/Inc + ${STM_DIR}/Drivers/STM32F4xx_HAL_Driver/Inc + ${STM_DIR}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy + ${STM_DIR}/Drivers/CMSIS/Device/ST/STM32F4xx/Include + ${STM_DIR}/Drivers/CMSIS/Include +) + +include_directories(${CUBEMX_INCLUDE_DIRECTORIES}) \ No newline at end of file diff --git a/src/cmake/stm.cmake b/src/cmake/stm.cmake new file mode 100644 index 0000000..b04a84b --- /dev/null +++ b/src/cmake/stm.cmake @@ -0,0 +1,14 @@ + +set(STM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../STM_sdk) +file(GLOB_RECURSE STM32CUBEMX_SOURCES ${STM_DIR}/Core/*.c ${STM_DIR}/Drivers/STM32F4xx_HAL_Driver/*.c) +set(STARTUP_SCRIPT ${STM_DIR}/startup_stm32f446xx.s) + +target_sources(${LF_MAIN_TARGET} PRIVATE ${STM32CUBEMX_SOURCES} ) + +add_custom_command(TARGET ${LF_MAIN_TARGET} POST_BUILD + COMMAND ${CMAKE_SIZE} $) +add_custom_command(TARGET ${LF_MAIN_TARGET} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -O ihex $ + ${LF_MAIN_TARGET}.hex + COMMAND ${CMAKE_OBJCOPY} -O binary $ + ${LF_MAIN_TARGET}.bin) \ No newline at end of file