diff --git a/CMakeLists.txt b/CMakeLists.txt index a04a81d..9f80f33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,10 @@ set(FSFW_OSAL rtems CACHE STRING "OS for the FSFW") set(STM32_ADD_NETWORKING_CODE OFF) set(FSFW_HAL_ADD_STM32H7 ON) +# Set TGT_BSP to correct target for pre-project configuration +set(TGT_BSP "arm/stm32h743zi-nucleo") +add_definitions(-DSTM32H743ZI_NUCLEO) + # This call has to come before the project call include("${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake") @@ -32,9 +36,6 @@ project(fsfw-example-stm32h7-rtems ASM C CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) - -set(TGT_BSP "arm/stm32h743zi-nucleo") - # Set names and variables set(TARGET_NAME ${CMAKE_PROJECT_NAME}) set(LIB_FSFW_NAME fsfw) @@ -43,10 +44,11 @@ set(LIB_FSFW_NAME fsfw) set(FSFW_PATH fsfw) set(COMMON_PATH example_common) -set(BSP_PATH "bsp_stm32h7_freertos") +set(BSP_PATH "bsp_stm32h7_rtems") set(COMMON_CONFIG_PATH "${COMMON_PATH}/config") set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig") -set(BSP_NUCLEO_PATH "${BSP_PATH}/NUCLEO-H743ZI") +set(BSP_NUCLEO_PATH "${BSP_PATH}/boarconfig/NUCLEO-H743ZI") +set(BSP_NUCLEO_PATH_INC "${BSP_PATH}/boardconfig/NUCLEO-H743ZI/Inc") set(FSFW_ADDITIONAL_INC_PATHS "${COMMON_CONFIG_PATH}" @@ -58,7 +60,7 @@ set(FSFW_ADDITIONAL_INC_PATHS configure_file(${COMMON_CONFIG_PATH}/commonConfig.h.in commonConfig.h) configure_file(${FSFW_CONFIG_PATH}/FSFWConfig.h.in FSFWConfig.h) configure_file(${FSFW_CONFIG_PATH}/OBSWConfig.h.in OBSWConfig.h) -configure_file(${BSP_NUCLEO_PATH}/lwipopts.h.in lwipopts.h) +configure_file(${BSP_NUCLEO_PATH_INC}/lwipopts.h.in lwipopts.h) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(WARNING_FLAGS diff --git a/bsp_stm32h7_rtems/CMakeLists.txt b/bsp_stm32h7_rtems/CMakeLists.txt new file mode 100644 index 0000000..4c666d2 --- /dev/null +++ b/bsp_stm32h7_rtems/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(${TARGET_NAME} PRIVATE + init.c + main.cpp +) + +add_subdirectory(boardconfig) +add_subdirectory(fsfwconfig) +add_subdirectory(core) +add_subdirectory(boardtest) diff --git a/bsp_stm32h7_rtems/RTEMSConfig.h b/bsp_stm32h7_rtems/RTEMSConfig.h new file mode 100644 index 0000000..0b27269 --- /dev/null +++ b/bsp_stm32h7_rtems/RTEMSConfig.h @@ -0,0 +1,44 @@ +#ifndef BSP_STM32_RTEMS_RTEMSCONFIG_H_ +#define BSP_STM32_RTEMS_RTEMSCONFIG_H_ + +#include + +/* Forward declaration required */ +rtems_task Init(rtems_task_argument argument); + +#define CONFIGURE_MICROSECONDS_PER_TICK 1000 + +//! Specify the allocation scheme used for RTEMS. +//! See: https://docs.rtems.org/branches/master/c-user/config/intro.html +#define RTEMS_USE_UNLIMITED_OBJECTS_ALLOCATION 0 + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#if RTEMS_USE_UNLIMITED_OBJECTS_ALLOCATION == 1 + +#define CONFIGURE_UNIFIED_WORK_AREAS +#define CONFIGURE_UNLIMITED_OBJECTS +#define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 6) + +#else + +#define CONFIGURE_MAXIMUM_TASKS 20 +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 30 +#define CONFIGURE_MAXIMUM_SEMAPHORES 20 +#define CONFIGURE_MAXIMUM_TIMERS 10 +//! Required for Rate-Monotonic Scheduling (RMS) +#define CONFIGURE_MAXIMUM_PERIODS 15 +#define CONFIGURE_INIT_TASK_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 6) +//! Around 41 kB extra task stack for now. +#define CONFIGURE_EXTRA_TASK_STACKS (10 * RTEMS_MINIMUM_STACK_SIZE) + +#endif /* RTEMS_USE_UNLIMITED_OBJECTS_ALLOCATION == 1 */ + +#define CONFIGURE_INIT + +#include + +#endif /* BSP_STM32_RTEMS_RTEMSCONFIG_H_ */ diff --git a/bsp_stm32h7_rtems/boardconfig/CMakeLists.txt b/bsp_stm32h7_rtems/boardconfig/CMakeLists.txt new file mode 100644 index 0000000..8ab53fb --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${TARGET_NAME} PRIVATE +) + +add_subdirectory(NUCLEO-H743ZI) diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/CMakeLists.txt b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/CMakeLists.txt new file mode 100644 index 0000000..b4f4a8b --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/CMakeLists.txt @@ -0,0 +1,5 @@ +add_subdirectory(Src) + +target_include_directories(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Inc +) diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/hardware_init.h b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/hardware_init.h new file mode 100644 index 0000000..e09a15e --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/hardware_init.h @@ -0,0 +1,17 @@ +#ifndef BSP_STM32H7_RTEMS_NUCLEO_H743ZI_INC_HARDWARE_INIT_H_ +#define BSP_STM32H7_RTEMS_NUCLEO_H743ZI_INC_HARDWARE_INIT_H_ + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void hardware_init(); + +#ifdef __cplusplus +} +#endif + +#endif /* BSP_STM32H7_RTEMS_NUCLEO_H743ZI_INC_HARDWARE_INIT_H_ */ diff --git a/bsp_stm32h7_rtems/NUCLEO-H743ZI/lwipopts.h.in b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/lwipopts.h.in similarity index 100% rename from bsp_stm32h7_rtems/NUCLEO-H743ZI/lwipopts.h.in rename to bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/lwipopts.h.in diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo.h b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo.h new file mode 100644 index 0000000..5608b9c --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo.h @@ -0,0 +1,338 @@ +/** + ****************************************************************************** + * @file stm32h7xx_nucleo.h + * @author MCD Application Team + * @brief This file contains definitions for: + * - LEDs and push-button available on STM32H7xx-Nucleo Kit + * from STMicroelectronics + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32H7XX_NUCLEO_H +#define STM32H7XX_NUCLEO_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32h7xx_nucleo_conf.h" +#include "stm32h7xx_nucleo_errno.h" + +#if (USE_BSP_COM_FEATURE > 0) + #if (USE_COM_LOG > 0) + #ifndef __GNUC__ + #include + #endif + #endif +#endif + +/** @addtogroup BSP + * @{ + */ + +/** @defgroup STM32H7XX_NUCLEO STM32H7XX_NUCLEO + * @{ + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL LOW LEVEL + * @{ + */ + +/** + * @brief Define for STM32H7XX_NUCLEO board + */ +#if !defined (USE_STM32H7XX_NUCLEO) + #define USE_STM32H7XX_NUCLEO +#endif + +#if !defined (USE_NUCLEO_144) + #error "Board Pin number not defined!! Add USE_NUCLEO_144 define within stm32h7xx_nucleo_conf.h file" +#endif + +#if !defined (USE_NUCLEO_H745ZI_Q) && !defined (USE_NUCLEO_H743ZI) && !defined (USE_NUCLEO_H743ZI2) &&\ + !defined (USE_NUCLEO_H7A3ZI_Q) && !defined (USE_NUCLEO_H723ZG) + #error "Board Part number not defined!! Add one of the following define within stm32h7xx_nucleo_conf.h file:\ + USE_NUCLEO_H745ZI_Q, USE_NUCLEO_H743ZI, USE_NUCLEO_H743ZI2, USE_NUCLEO_H7A3ZI_Q, USE_NUCLEO_H723ZG" +#endif + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Types LOW LEVEL Exported Types + * @{ + */ +#if defined (USE_NUCLEO_H745ZI_Q) || defined (USE_NUCLEO_H743ZI2) || defined (USE_NUCLEO_H7A3ZI_Q) || defined (USE_NUCLEO_H723ZG) +typedef enum +{ + LED1 = 0, + LED_GREEN = LED1, + LED2 = 1, + LED_YELLOW = LED2, + LED3 = 2, + LED_RED = LED3, + LEDn +}Led_TypeDef; +#else /* USE_NUCLEO_H743ZI */ +typedef enum +{ + LED1 = 0, + LED_GREEN = LED1, + LED2 = 1, + LED_BLUE = LED2, + LED3 = 2, + LED_RED = LED3, + LEDn +}Led_TypeDef; +#endif + +typedef enum +{ + BUTTON_USER = 0U, + BUTTONn +}Button_TypeDef; + +typedef enum +{ + BUTTON_MODE_GPIO = 0, + BUTTON_MODE_EXTI = 1 +}ButtonMode_TypeDef; + +#if (USE_BSP_COM_FEATURE > 0) +typedef enum +{ + COM1 = 0U, + COMn +}COM_TypeDef; + +typedef enum +{ + COM_STOPBITS_1 = UART_STOPBITS_1, + COM_STOPBITS_2 = UART_STOPBITS_2, +}COM_StopBitsTypeDef; + +typedef enum +{ + COM_PARITY_NONE = UART_PARITY_NONE, + COM_PARITY_EVEN = UART_PARITY_EVEN, + COM_PARITY_ODD = UART_PARITY_ODD, +}COM_ParityTypeDef; + +typedef enum +{ + COM_HWCONTROL_NONE = UART_HWCONTROL_NONE, + COM_HWCONTROL_RTS = UART_HWCONTROL_RTS, + COM_HWCONTROL_CTS = UART_HWCONTROL_CTS, + COM_HWCONTROL_RTS_CTS = UART_HWCONTROL_RTS_CTS, +}COM_HwFlowCtlTypeDef; + +typedef enum +{ + COM_WORDLENGTH_7B = UART_WORDLENGTH_7B, + COM_WORDLENGTH_8B = UART_WORDLENGTH_8B, + COM_WORDLENGTH_9B = UART_WORDLENGTH_9B, +}COM_WordLengthTypeDef; + +typedef struct +{ + uint32_t BaudRate; + COM_WordLengthTypeDef WordLength; + COM_StopBitsTypeDef StopBits; + COM_ParityTypeDef Parity; + COM_HwFlowCtlTypeDef HwFlowCtl; +}COM_InitTypeDef; + +#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) +typedef struct +{ + void (* pMspInitCb)(UART_HandleTypeDef *); + void (* pMspDeInitCb)(UART_HandleTypeDef *); +}BSP_COM_Cb_t; +#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 1) */ + +#define MX_UART_InitTypeDef COM_InitTypeDef +#endif + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Constants LOW LEVEL Exported Constants + * @{ + */ + +/** + * @brief STM32H7XX NUCLEO BSP Driver version number V1.3.0 + */ +#define STM32H7XX_NUCLEO_BSP_VERSION_MAIN (0x01U) /*!< [31:24] main version */ +#define STM32H7XX_NUCLEO_BSP_VERSION_SUB1 (0x03U) /*!< [23:16] sub1 version */ +#define STM32H7XX_NUCLEO_BSP_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */ +#define STM32H7XX_NUCLEO_BSP_VERSION_RC (0x00U) /*!< [7:0] release candidate */ +#define STM32H7XX_NUCLEO_BSP_VERSION ((STM32H7XX_NUCLEO_BSP_VERSION_MAIN << 24)\ + |(STM32H7XX_NUCLEO_BSP_VERSION_SUB1 << 16)\ + |(STM32H7XX_NUCLEO_BSP_VERSION_SUB2 << 8 )\ + |(STM32H7XX_NUCLEO_BSP_VERSION_RC)) + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_LED LOW LEVEL LED + * @{ + */ +#define LEDn 3U + +#define LED1_PIN GPIO_PIN_0 +#define LED1_GPIO_PORT GPIOB +#define LED1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() +#define LED1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() + +#if defined (USE_NUCLEO_H745ZI_Q) || defined (USE_NUCLEO_H743ZI2) || defined (USE_NUCLEO_H7A3ZI_Q) || defined (USE_NUCLEO_H723ZG) +#define LED2_PIN GPIO_PIN_1 +#define LED2_GPIO_PORT GPIOE +#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE() +#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOE_CLK_DISABLE() +#else /* USE_NUCLEO_H743ZI */ +#define LED2_PIN GPIO_PIN_7 +#define LED2_GPIO_PORT GPIOB +#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() +#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() +#endif + +#define LED3_PIN GPIO_PIN_14 +#define LED3_GPIO_PORT GPIOB +#define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() +#define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_BUTTON LOW LEVEL BUTTON + * @{ + */ +/* Button state */ +#define BUTTON_RELEASED 0U +#define BUTTON_PRESSED 1U +#define BUTTONn 1U + +/** + * @brief Key push-button + */ +#define BUTTON_USER_PIN GPIO_PIN_13 +#define BUTTON_USER_GPIO_PORT GPIOC +#define BUTTON_USER_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() +#define BUTTON_USER_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE() +#define BUTTON_USER_EXTI_IRQn EXTI15_10_IRQn +#define BUTTON_USER_EXTI_LINE EXTI_LINE_13 + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_COM LOW LEVEL COM + * @{ + */ +/** + * @brief Definition for COM port1, connected to USART3 + */ +#if (USE_BSP_COM_FEATURE > 0) + +#define COMn 1U +#define COM1_UART USART3 +#define COM1_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE() +#define COM1_CLK_DISABLE() __HAL_RCC_USART3_CLK_DISABLE() + +#define COM1_TX_PIN GPIO_PIN_8 +#define COM1_TX_GPIO_PORT GPIOD +#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() +#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() +#define COM1_TX_AF GPIO_AF7_USART3 + +#define COM1_RX_PIN GPIO_PIN_9 +#define COM1_RX_GPIO_PORT GPIOD +#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() +#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE() +#define COM1_RX_AF GPIO_AF7_USART3 +#define COM_POLL_TIMEOUT 1000 +#endif + +/** + * @} + */ + +/** + * @} + */ + +/** @addtogroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Variables + * @{ + */ +extern EXTI_HandleTypeDef hpb_exti[]; +#if (USE_BSP_COM_FEATURE > 0) +extern UART_HandleTypeDef hcom_uart[]; +extern USART_TypeDef* COM_USART[]; +#endif + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_FunctionsPrototypes LOW LEVEL Exported Functions Prototypes + * @{ + */ +int32_t BSP_GetVersion(void); +int32_t BSP_LED_Init(Led_TypeDef Led); +int32_t BSP_LED_DeInit(Led_TypeDef Led); +int32_t BSP_LED_On(Led_TypeDef Led); +int32_t BSP_LED_Off(Led_TypeDef Led); +int32_t BSP_LED_Toggle(Led_TypeDef Led); +int32_t BSP_LED_GetState (Led_TypeDef Led); +int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode); +int32_t BSP_PB_DeInit(Button_TypeDef Button); +int32_t BSP_PB_GetState(Button_TypeDef Button); +void BSP_PB_IRQHandler(Button_TypeDef Button); +void BSP_PB_Callback(Button_TypeDef Button); + +#if (USE_BSP_COM_FEATURE > 0) +int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init); +int32_t BSP_COM_DeInit(COM_TypeDef COM); +#if (USE_COM_LOG > 0) +int32_t BSP_COM_SelectLogPort (COM_TypeDef COM); +#endif + +#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) +int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM); +int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM , BSP_COM_Cb_t *Callback); +#endif /* USE_HAL_UART_REGISTER_CALLBACKS */ +HAL_StatusTypeDef MX_USART3_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init); +#endif /* USE_BSP_COM_FEATURE */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* STM32H7XX_NUCLEO_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo_conf.h b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo_conf.h new file mode 100644 index 0000000..4ff2a87 --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo_conf.h @@ -0,0 +1,82 @@ +/** + ****************************************************************************** + * @file stm32h7xx_nucleo_conf.h + * @author MCD Application Team + * @brief STM32H7xx_Nuleo board configuration file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32H7XX_NUCLEO_CONF_H +#define STM32H7XX_NUCLEO_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32h7xx_hal.h" +#include "stm32h743xx.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup STM32H7XX_NUCLEO + * @{ + */ + +/** @defgroup STM32H7XX_NUCLEO_CONFIG Config + * @{ + */ + +/** @defgroup STM32H7XX_NUCLEO_CONFIG_Exported_Constants Exported Constants + * @{ + */ +/* Nucleo pin and part number defines */ +#define USE_NUCLEO_144 +#define USE_NUCLEO_H743ZI + +/* COM define */ +#define USE_COM_LOG 0U +#define USE_BSP_COM_FEATURE 1U + +/* IRQ priorities */ +#define BSP_BUTTON_USER_IT_PRIORITY 15U + +#define BUS_SPI1_BAUDRATE 18000000 + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* STM32H7XX_NUCLEO_CONF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo_errno.h b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo_errno.h new file mode 100644 index 0000000..8fc1334 --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Inc/stm32h7xx_nucleo_errno.h @@ -0,0 +1,48 @@ +/** + ****************************************************************************** + * @file stm32h7xx_nucleo_errno.h + * @author MCD Application Team + * @brief Error Code. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32H7XX_NUCLEO_ERRNO_H +#define STM32H7XX_NUCLEO_ERRNO_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Common Error codes */ +#define BSP_ERROR_NONE 0 +#define BSP_ERROR_NO_INIT -1 +#define BSP_ERROR_WRONG_PARAM -2 +#define BSP_ERROR_BUSY -3 +#define BSP_ERROR_PERIPH_FAILURE -4 +#define BSP_ERROR_COMPONENT_FAILURE -5 +#define BSP_ERROR_UNKNOWN_FAILURE -6 +#define BSP_ERROR_UNKNOWN_COMPONENT -7 +#define BSP_ERROR_BUS_FAILURE -8 +#define BSP_ERROR_CLOCK_FAILURE -9 +#define BSP_ERROR_MSP_FAILURE -10 +#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11 + +#ifdef __cplusplus +} +#endif + +#endif /* STM32H7XX_NUCLEO_ERRNO_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/CMakeLists.txt b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/CMakeLists.txt new file mode 100644 index 0000000..548f080 --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${TARGET_NAME} PRIVATE + hardware_init.cpp + stm32h7xx_nucleo.c +) diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/hardware_init.cpp b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/hardware_init.cpp new file mode 100644 index 0000000..e7ab06a --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/hardware_init.cpp @@ -0,0 +1,5 @@ +#include "hardware_init.h" + +void hardware_init() { + +} diff --git a/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/stm32h7xx_nucleo.c b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/stm32h7xx_nucleo.c new file mode 100644 index 0000000..c872fec --- /dev/null +++ b/bsp_stm32h7_rtems/boardconfig/NUCLEO-H743ZI/Src/stm32h7xx_nucleo.c @@ -0,0 +1,693 @@ +/** + ****************************************************************************** + * @file stm32h7xx_nucleo.c + * @author MCD Application Team + * @brief This file provides set of firmware functions to manage: + * - LEDs and push-button available on STM32H7xx-Nucleo Kit + * from STMicroelectronics + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2018 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32h7xx_nucleo.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup STM32H7XX_NUCLEO + * @{ + */ + +/** @addtogroup STM32H7XX_NUCLEO_LOW_LEVEL + * @brief This file provides set of firmware functions to manage Leds and push-button + * available on STM32H7xx-Nucleo Kit from STMicroelectronics. + * @{ + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_Defines LOW LEVEL Private Defines + * @{ + */ + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions LOW LEVEL Private Typedef + * @{ + */ +typedef void (* BSP_EXTI_LineCallback) (void); +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Variables + * @{ + */ +EXTI_HandleTypeDef hpb_exti[BUTTONn]; +#if (USE_BSP_COM_FEATURE > 0) +UART_HandleTypeDef hcom_uart[COMn]; +USART_TypeDef* COM_USART[COMn] = {COM1_UART}; +#endif +/** + * @} + */ +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_Variables LOW LEVEL Private Variables + * @{ + */ +static GPIO_TypeDef* LED_PORT[LEDn] = {LED1_GPIO_PORT, + LED2_GPIO_PORT, + LED3_GPIO_PORT}; + +static const uint16_t LED_PIN[LEDn] = {LED1_PIN, + LED2_PIN, + LED3_PIN}; + +static GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {BUTTON_USER_GPIO_PORT}; +static const uint16_t BUTTON_PIN[BUTTONn] = {BUTTON_USER_PIN}; +static const IRQn_Type BUTTON_IRQn[BUTTONn] = {BUTTON_USER_EXTI_IRQn}; + + + +#if (USE_BSP_COM_FEATURE > 0) + #if (USE_COM_LOG > 0) + static COM_TypeDef COM_ActiveLogPort = COM1; + #endif + #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) + static uint32_t IsComMspCbValid[COMn] = {0}; + #endif +#endif + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes LOW LEVEL Private functions Prototypes + * @{ + */ +static void BUTTON_USER_EXTI_Callback(void); +#if (USE_BSP_COM_FEATURE > 0) +static void COM1_MspInit(UART_HandleTypeDef *huart); +static void COM1_MspDeInit(UART_HandleTypeDef *huart); +#endif +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Functions LOW LEVEL Exported Functions + * @{ + */ + +/** + * @brief This method returns the STM32H7XX NUCLEO BSP Driver revision + * @retval version: 0xXYZR (8bits for each decimal, R for RC) + */ +int32_t BSP_GetVersion(void) +{ + return (int32_t)STM32H7XX_NUCLEO_BSP_VERSION; +} + +/** + * @brief Configures LED GPIO. + * @param Led Specifies the Led to be configured. + * This parameter can be one of following parameters: + * @arg LED1 + * @arg LED2 + * @arg LED3 + * @retval BSP status + */ +int32_t BSP_LED_Init(Led_TypeDef Led) +{ + int32_t ret = BSP_ERROR_NONE; + GPIO_InitTypeDef gpio_init_structure; + + if((Led != LED1) && (Led != LED2) && (Led != LED3)) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + /* Enable the GPIO LED Clock */ + if(Led == LED1) + { + LED1_GPIO_CLK_ENABLE(); + } + else if(Led == LED2) + { + LED2_GPIO_CLK_ENABLE(); + } + else + { + LED3_GPIO_CLK_ENABLE(); + } + /* Configure the GPIO_LED pin */ + gpio_init_structure.Pin = LED_PIN[Led]; + gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; + gpio_init_structure.Pull = GPIO_NOPULL; + gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + + HAL_GPIO_Init(LED_PORT[Led], &gpio_init_structure); + HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET); + } + + return ret; +} + +/** + * @brief DeInit LEDs. + * @param Led LED to be de-init. + * This parameter can be one of the following values: + * @arg LED1 + * @arg LED2 + * @arg LED3 + * @note Led DeInit does not disable the GPIO clock nor disable the Mfx + * @retval BSP status + */ +int32_t BSP_LED_DeInit(Led_TypeDef Led) +{ + int32_t ret = BSP_ERROR_NONE; + GPIO_InitTypeDef gpio_init_structure; + + if((Led != LED1) && (Led != LED2) && (Led != LED3)) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + /* Turn off LED */ + HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET); + /* DeInit the GPIO_LED pin */ + gpio_init_structure.Pin = LED_PIN[Led]; + HAL_GPIO_DeInit(LED_PORT[Led], gpio_init_structure.Pin); + } + + return ret; +} + +/** + * @brief Turns selected LED On. + * @param Led Specifies the Led to be set on. + * This parameter can be one of following parameters: + * @arg LED1 + * @arg LED2 + * @arg LED3 + * @retval BSP status + */ +int32_t BSP_LED_On(Led_TypeDef Led) +{ + int32_t ret = BSP_ERROR_NONE; + + if((Led != LED1) && (Led != LED2) && (Led != LED3)) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET); + } + + return ret; +} + +/** + * @brief Turns selected LED Off. + * @param Led: Specifies the Led to be set off. + * This parameter can be one of following parameters: + * @arg LED1 + * @arg LED2 + * @arg LED3 + * @retval BSP status + */ +int32_t BSP_LED_Off(Led_TypeDef Led) +{ + int32_t ret = BSP_ERROR_NONE; + + if((Led != LED1) && (Led != LED2) && (Led != LED3)) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET); + } + + return ret; +} + +/** + * @brief Toggles the selected LED. + * @param Led Specifies the Led to be toggled. + * This parameter can be one of following parameters: + * @arg LED1 + * @arg LED2 + * @arg LED3 + * @retval BSP status + */ +int32_t BSP_LED_Toggle(Led_TypeDef Led) +{ + int32_t ret = BSP_ERROR_NONE; + + if((Led != LED1) && (Led != LED2) && (Led != LED3)) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]); + } + + return ret; +} + +/** + * @brief Get the state of the selected LED. + * @param Led LED to get its state + * This parameter can be one of following parameters: + * @arg LED1 + * @arg LED2 + * @arg LED3 + * @retval LED status + */ +int32_t BSP_LED_GetState (Led_TypeDef Led) +{ + int32_t ret; + + if((Led != LED1) && (Led != LED2) && (Led != LED3)) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + ret = (int32_t)HAL_GPIO_ReadPin (LED_PORT [Led], LED_PIN [Led]); + } + + return ret; +} + +/** + * @brief Configures button GPIO and EXTI Line. + * @param Button Button to be configured + * This parameter can be one of the following values: + * @arg BUTTON_USER: Wakeup Push Button + * @param ButtonMode Button mode + * This parameter can be one of the following values: + * @arg BUTTON_MODE_GPIO: Button will be used as simple IO + * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line + * with interrupt generation capability + */ +int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) +{ + GPIO_InitTypeDef gpio_init_structure; + static BSP_EXTI_LineCallback ButtonCallback[BUTTONn] = {BUTTON_USER_EXTI_Callback}; + static uint32_t BSP_BUTTON_PRIO [BUTTONn] = {BSP_BUTTON_USER_IT_PRIORITY}; + static const uint32_t BUTTON_EXTI_LINE[BUTTONn] = {BUTTON_USER_EXTI_LINE}; + + /* Enable the BUTTON clock */ + BUTTON_USER_GPIO_CLK_ENABLE(); + + gpio_init_structure.Pin = BUTTON_PIN [Button]; + gpio_init_structure.Pull = GPIO_PULLDOWN; + gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; + + if(ButtonMode == BUTTON_MODE_GPIO) + { + /* Configure Button pin as input */ + gpio_init_structure.Mode = GPIO_MODE_INPUT; + HAL_GPIO_Init(BUTTON_PORT [Button], &gpio_init_structure); + } + else /* (ButtonMode == BUTTON_MODE_EXTI) */ + { + /* Configure Button pin as input with External interrupt */ + gpio_init_structure.Mode = GPIO_MODE_IT_RISING; + + HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); + + (void)HAL_EXTI_GetHandle(&hpb_exti[Button], BUTTON_EXTI_LINE[Button]); + (void)HAL_EXTI_RegisterCallback(&hpb_exti[Button], HAL_EXTI_COMMON_CB_ID, ButtonCallback[Button]); + + /* Enable and set Button EXTI Interrupt to the lowest priority */ + HAL_NVIC_SetPriority((BUTTON_IRQn[Button]), BSP_BUTTON_PRIO[Button], 0x00); + HAL_NVIC_EnableIRQ((BUTTON_IRQn[Button])); + } + + return BSP_ERROR_NONE; +} + +/** + * @brief Push Button DeInit. + * @param Button Button to be configured + * This parameter can be one of the following values: + * @arg BUTTON_USER: Wakeup Push Button + * @note PB DeInit does not disable the GPIO clock + */ +int32_t BSP_PB_DeInit(Button_TypeDef Button) +{ + GPIO_InitTypeDef gpio_init_structure; + + gpio_init_structure.Pin = BUTTON_PIN[Button]; + HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); + HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin); + + return BSP_ERROR_NONE; +} + +/** + * @brief Returns the selected button state. + * @param Button Button to be checked + * This parameter can be one of the following values: + * @arg BUTTON_USER: Wakeup Push Button + * @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed) + */ +int32_t BSP_PB_GetState(Button_TypeDef Button) +{ + return (int32_t)HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); +} + +/** + * @brief BSP Button IRQ handler + * @param Button Can only be BUTTON_USER + * @retval None + */ +void BSP_PB_IRQHandler(Button_TypeDef Button) +{ + HAL_EXTI_IRQHandler(&hpb_exti[Button]); +} + +/** + * @brief BSP Push Button callback + * @param Button Specifies the pin connected EXTI line + * @retval None + */ +__weak void BSP_PB_Callback(Button_TypeDef Button) +{ + /* Prevent unused argument(s) compilation warning */ + UNUSED(Button); + + /* This function should be implemented by the user application. + It is called into this driver when an event on Button is triggered. */ +} + +#if (USE_BSP_COM_FEATURE > 0) +/** + * @brief Configures COM port. + * @param COM COM port to be configured. + * This parameter can be COM1 + * @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the + * configuration information for the specified USART peripheral. + * @retval BSP error code + */ +int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init) +{ + int32_t ret = BSP_ERROR_NONE; + + if(COM >= COMn) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { +#if (USE_HAL_UART_REGISTER_CALLBACKS == 0) + /* Init the UART Msp */ + COM1_MspInit(&hcom_uart[COM]); +#else + if(IsComMspCbValid[COM] == 0U) + { + if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE) + { + return BSP_ERROR_MSP_FAILURE; + } + } +#endif + + if(MX_USART3_Init(&hcom_uart[COM], COM_Init) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + + return ret; +} + +/** + * @brief DeInit COM port. + * @param COM COM port to be configured. + * This parameter can be COM1 + * @retval BSP status + */ +int32_t BSP_COM_DeInit(COM_TypeDef COM) +{ + int32_t ret = BSP_ERROR_NONE; + + if(COM >= COMn) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + /* USART configuration */ + hcom_uart[COM].Instance = COM_USART[COM]; + +#if (USE_HAL_UART_REGISTER_CALLBACKS == 0) + COM1_MspDeInit(&hcom_uart[COM]); +#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0) */ + + if(HAL_UART_DeInit(&hcom_uart[COM]) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + + return ret; +} + +/** + * @brief Configures COM port. + * @param huart USART handle + * @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the + * configuration information for the specified USART peripheral. + * @retval HAL error code + */ +__weak HAL_StatusTypeDef MX_USART3_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init) +{ + /* USART configuration */ + huart->Instance = COM_USART[COM1]; + huart->Init.BaudRate = COM_Init->BaudRate; + huart->Init.Mode = UART_MODE_TX_RX; + huart->Init.Parity = (uint32_t)COM_Init->Parity; + huart->Init.WordLength = (uint32_t)COM_Init->WordLength; + huart->Init.StopBits = (uint32_t)COM_Init->StopBits; + huart->Init.HwFlowCtl = (uint32_t)COM_Init->HwFlowCtl; + huart->Init.OverSampling = UART_OVERSAMPLING_8; + + return HAL_UART_Init(huart); +} + +#if (USE_HAL_UART_REGISTER_CALLBACKS == 1) +/** + * @brief Register Default COM Msp Callbacks + * @param COM COM port to be configured. + * This parameter can be COM1 + * @retval BSP status + */ +int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM) +{ + int32_t ret = BSP_ERROR_NONE; + + if(COM >= COMn) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + __HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]); + + /* Register default MspInit/MspDeInit Callback */ + if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, COM1_MspInit) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, COM1_MspDeInit) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else + { + IsComMspCbValid[COM] = 1U; + } + } + + /* BSP status */ + return ret; +} + +/** + * @brief Register COM Msp Callback registering + * @param COM COM port to be configured. + * This parameter can be COM1 + * @param Callbacks pointer to COM1 MspInit/MspDeInit callback functions + * @retval BSP status + */ +int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM , BSP_COM_Cb_t *Callback) +{ + int32_t ret = BSP_ERROR_NONE; + + if(COM >= COMn) + { + ret = BSP_ERROR_WRONG_PARAM; + } + else + { + __HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]); + + /* Register MspInit/MspDeInit Callbacks */ + if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, Callback->pMspInitCb) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, Callback->pMspDeInitCb) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else + { + IsComMspCbValid[COM] = 1U; + } + } + /* BSP status */ + return ret; +} +#endif /* USE_HAL_UART_REGISTER_CALLBACKS */ + +#if (USE_COM_LOG > 0) +/** + * @brief Select the active COM port. + * @param COM COM port to be activated. + * This parameter can be COM1 + * @retval BSP status + */ +int32_t BSP_COM_SelectLogPort(COM_TypeDef COM) +{ + if(COM_ActiveLogPort != COM) + { + COM_ActiveLogPort = COM; + } + return BSP_ERROR_NONE; +} + +/** + * @brief Redirect console output to COM + */ + #ifdef __GNUC__ + int __io_putchar (int ch) + #else + int fputc (int ch, FILE *f) + #endif /* __GNUC__ */ +{ + HAL_UART_Transmit (&hcom_uart [COM_ActiveLogPort], (uint8_t *) &ch, 1, COM_POLL_TIMEOUT); + return ch; +} +#endif /* USE_COM_LOG */ +#endif /* USE_BSP_COM_FEATURE */ + +/** + * @} + */ + +/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_Functions LOW LEVEL Private functions + * @{ + */ +/** + * @brief Key EXTI line detection callbacks. + * @retval BSP status + */ +static void BUTTON_USER_EXTI_Callback(void) +{ + BSP_PB_Callback(BUTTON_USER); +} + +#if (USE_BSP_COM_FEATURE > 0) +/** + * @brief Initializes UART MSP. + * @param huart UART handle + * @retval BSP status + */ +static void COM1_MspInit(UART_HandleTypeDef *huart) +{ + GPIO_InitTypeDef gpio_init_structure; + + /* Prevent unused argument(s) compilation warning */ + UNUSED(huart); + + /* Enable GPIO clock */ + COM1_TX_GPIO_CLK_ENABLE(); + COM1_RX_GPIO_CLK_ENABLE(); + + /* Enable USART clock */ + COM1_CLK_ENABLE(); + + /* Configure USART Tx as alternate function */ + gpio_init_structure.Pin = COM1_TX_PIN; + gpio_init_structure.Mode = GPIO_MODE_AF_PP; + gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; + gpio_init_structure.Pull = GPIO_PULLUP; + gpio_init_structure.Alternate = COM1_TX_AF; + HAL_GPIO_Init(COM1_TX_GPIO_PORT, &gpio_init_structure); + + /* Configure USART Rx as alternate function */ + gpio_init_structure.Pin = COM1_RX_PIN; + gpio_init_structure.Mode = GPIO_MODE_AF_PP; + gpio_init_structure.Alternate = COM1_RX_AF; + HAL_GPIO_Init(COM1_RX_GPIO_PORT, &gpio_init_structure); +} + +/** + * @brief Initialize USART3 Msp part + * @param huart UART handle + * @retval BSP status + */ +static void COM1_MspDeInit(UART_HandleTypeDef *huart) +{ + GPIO_InitTypeDef gpio_init_structure; + + /* Prevent unused argument(s) compilation warning */ + UNUSED(huart); + + /* COM GPIO pin configuration */ + gpio_init_structure.Pin = COM1_TX_PIN; + HAL_GPIO_DeInit(COM1_TX_GPIO_PORT, gpio_init_structure.Pin); + + gpio_init_structure.Pin = COM1_RX_PIN; + HAL_GPIO_DeInit(COM1_RX_GPIO_PORT, gpio_init_structure.Pin); + + /* Disable USART clock */ + COM1_CLK_DISABLE(); +} +#endif /* USE_BSP_COM_FEATURE */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/bsp_stm32h7_rtems/boardtest/CMakeLists.txt b/bsp_stm32h7_rtems/boardtest/CMakeLists.txt new file mode 100644 index 0000000..8e57e01 --- /dev/null +++ b/bsp_stm32h7_rtems/boardtest/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(${TARGET_NAME} PRIVATE +) diff --git a/bsp_stm32h7_rtems/core/CMakeLists.txt b/bsp_stm32h7_rtems/core/CMakeLists.txt new file mode 100644 index 0000000..77cba85 --- /dev/null +++ b/bsp_stm32h7_rtems/core/CMakeLists.txt @@ -0,0 +1,6 @@ +target_sources(${TARGET_NAME} PRIVATE + InitMission.cpp + ObjectFactory.cpp + printChar.c +) + diff --git a/bsp_stm32h7_rtems/core/InitMission.cpp b/bsp_stm32h7_rtems/core/InitMission.cpp new file mode 100644 index 0000000..7e8ccad --- /dev/null +++ b/bsp_stm32h7_rtems/core/InitMission.cpp @@ -0,0 +1,196 @@ +#include "InitMission.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +void InitMission::createTasks() { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; +#if OBSW_ADD_CORE_COMPONENTS == 1 + /* TMTC Distribution */ + PeriodicTaskIF* distributerTask = TaskFactory::instance()->createPeriodicTask( + "DIST", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, nullptr); + result = distributerTask->addComponent(objects::CCSDS_DISTRIBUTOR); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("CCSDS distributor", objects::CCSDS_DISTRIBUTOR); + } + result = distributerTask->addComponent(objects::PUS_DISTRIBUTOR); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("PUS distributor", objects::CCSDS_DISTRIBUTOR); + } + result = distributerTask->addComponent(objects::TM_FUNNEL); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("TM funnel", objects::TM_FUNNEL); + } + + PeriodicTaskIF* eventManagerTask = TaskFactory::instance()->createPeriodicTask( + "EVENT_MGMT", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.1, nullptr); + result = eventManagerTask->addComponent(objects::EVENT_MANAGER); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("TM funnel", objects::TM_FUNNEL); + } + +#if OBSW_ADD_LWIP_NETWORKING == 1 + /* UDP bridge */ + PeriodicTaskIF* udpBridgeTask = TaskFactory::instance()->createPeriodicTask( + "UDP_UNIX_BRIDGE", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, nullptr); + result = udpBridgeTask->addComponent(objects::UDP_BRIDGE); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("UDP bridge", objects::UDP_BRIDGE); + } + + PeriodicTaskIF* udpPollingTask = TaskFactory::instance()->createPeriodicTask( + "UDP_POLLING", 75, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.1, nullptr); + result = udpPollingTask->addComponent(objects::UDP_POLLING_TASK); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("UDP polling task", objects::UDP_POLLING_TASK); + } +#endif /* OBSW_ADD_LWIP_NETWORKING == 1 */ +#endif /* OBSW_ADD_CORE_COMPONENTS == 1 */ + +#if OBSW_ADD_PUS_STACK == 1 + /* PUS Services */ + PeriodicTaskIF* pusVerification = TaskFactory::instance()->createPeriodicTask( + "PUS_VERIF_1", 45, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, nullptr); + result = pusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION); + if(result != HasReturnvaluesIF::RETURN_OK){ + task::printInitError("PUS 1", objects::PUS_SERVICE_1_VERIFICATION); + } + + PeriodicTaskIF* pusHighPrio = TaskFactory::instance()->createPeriodicTask( + "PUS_HIGH_PRIO", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, nullptr); + result = pusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("PUS 2", objects::PUS_SERVICE_2_DEVICE_ACCESS); + } + result = pusHighPrio->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING); + if(result != HasReturnvaluesIF::RETURN_OK){ + task::printInitError("PUS 5", objects::PUS_SERVICE_5_EVENT_REPORTING); + } + result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("PUS 9", objects::PUS_SERVICE_9_TIME_MGMT); + } + + PeriodicTaskIF* pusMedPrio = TaskFactory::instance()->createPeriodicTask( + "PUS_MED_PRIO", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8, nullptr); + result = pusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("PUS 8", objects::PUS_SERVICE_8_FUNCTION_MGMT); + } + result = pusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("PUS 200", objects::PUS_SERVICE_200_MODE_MGMT); + } + + PeriodicTaskIF* pusLowPrio = TaskFactory::instance()->createPeriodicTask( + "PUS_LOW_PRIO", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.6, nullptr); + result = pusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST); + if(result != HasReturnvaluesIF::RETURN_OK){ + task::printInitError("PUS 17", objects::PUS_SERVICE_17_TEST); + } +#endif /* OBSW_ADD_PUS_STACK == 1 */ + +#if OBSW_ADD_TASK_EXAMPLE == 1 + FixedTimeslotTaskIF* timeslotDemoTask = TaskFactory::instance()->createFixedTimeslotTask( + "PST_TASK", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, nullptr); + result = pst::pollingSequenceExamples(timeslotDemoTask); + if(result != HasReturnvaluesIF::RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "InitMission::createTasks: Examples PST initialization failed!" << std::endl; +#else + sif::printError("InitMission::createTasks: Examples PST initialization failed!\n"); +#endif + } + + PeriodicTaskIF* readerTask = TaskFactory::instance()-> + createPeriodicTask("READER_TASK", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr); + result = readerTask->addComponent(objects::TEST_DUMMY_4); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("Demo Reader Task", objects::TEST_DUMMY_4); + } +#endif /* OBSW_ADD_TASK_EXAMPLE == 1 */ + +#if OBSW_ADD_DEVICE_HANDLER_DEMO == 1 + FixedTimeslotTaskIF* testTimeslotTask = TaskFactory::instance()->createFixedTimeslotTask( + "PST_TEST_TASK", 10, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr); + result = pst::pollingSequenceDevices(testTimeslotTask); + if(result != HasReturnvaluesIF::RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "InitMission::createTasks: Devices PST initialization failed!" << std::endl; +#else + sif::printError("InitMission::createTasks: Devices PST initialization failed!\n"); +#endif + } +#endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */ + + PeriodicTaskIF* testTask = TaskFactory::instance()-> + createPeriodicTask("TEST", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr); + result = testTask->addComponent(objects::TEST_TASK); + if(result != HasReturnvaluesIF::RETURN_OK) { + task::printInitError("Test Task", objects::TEST_TASK); + } + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Starting tasks.." << std::endl; +#else + sif::printInfo("Starting tasks..\n"); +#endif + +#if OBSW_ADD_CORE_COMPONENTS == 1 + distributerTask->startTask(); + eventManagerTask->startTask(); +#if OBSW_ADD_LWIP_NETWORKING == 1 + udpBridgeTask->startTask(); + udpPollingTask->startTask(); +#endif /* OBSW_ADD_LWIP_NETWORKING == 1 */ +#endif /* OBSW_ADD_CORE_COMPONENTS == 1 */ + +#if OBSW_ADD_PUS_STACK == 1 + pusVerification->startTask(); + pusHighPrio->startTask(); + pusMedPrio->startTask(); + pusLowPrio->startTask(); +#endif /* OBSW_ADD_PUS_STACK == 1 */ + +#if OBSW_ADD_TASK_EXAMPLE == 1 + timeslotDemoTask->startTask(); + readerTask->startTask(); +#endif /* OBSW_ADD_TASK_EXAMPLE == 1 */ + +#if OBSW_ADD_DEVICE_HANDLER_DEMO == 1 + testTimeslotTask->startTask(); +#endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */ + + testTask->startTask(); + + Heap_Information_block block; + rtems_workspace_get_information(&block); + uint32_t failedAllocs = block.Stats.failed_allocs; + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Tasks started.." << std::endl; + sif::info << "Remaining RTEMS heap: " << block.Stats.free_size << " bytes" << std::endl; +#else + sif::printInfo("Tasks started..\n"); + sif::printInfo("Allocated RTEMS heap: %lu bytes\n", static_cast( + block.Stats.size)); + sif::printInfo("Remaining RTEMS heap: %lu bytes\n", static_cast( + block.Stats.free_size)); + if(failedAllocs > 0) { + sif::printWarning("%d allocations from RTEMS workspace failed!\n", failedAllocs); + } +#endif +} + + diff --git a/bsp_stm32h7_rtems/core/InitMission.h b/bsp_stm32h7_rtems/core/InitMission.h new file mode 100644 index 0000000..8c4788d --- /dev/null +++ b/bsp_stm32h7_rtems/core/InitMission.h @@ -0,0 +1,8 @@ +#ifndef MISSION_CORE_INITMISSION_H_ +#define MISSION_CORE_INITMISSION_H_ + +namespace InitMission { +void createTasks(); +}; + +#endif /* MISSION_CORE_INITMISSION_H_ */ diff --git a/bsp_stm32h7_rtems/core/ObjectFactory.cpp b/bsp_stm32h7_rtems/core/ObjectFactory.cpp new file mode 100644 index 0000000..88dcc7f --- /dev/null +++ b/bsp_stm32h7_rtems/core/ObjectFactory.cpp @@ -0,0 +1,58 @@ +#include "ObjectFactory.h" +#include +#include + +#include "example_common/stm32h7/networking/UdpTcLwIpPollingTask.h" +#include "example_common/stm32h7/networking/TmTcLwIpUdpBridge.h" +#include "example_common/stm32h7/STM32TestTask.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +void ObjectFactory::produce(void* args) { + /* Located inside GenericFactory source file */ + Factory::setStaticFrameworkObjectIds(); + +#if OBSW_ADD_CORE_COMPONENTS == 1 + { + LocalPool::LocalPoolConfig poolCfg = { + {15, 32}, {10, 64}, {5, 128}, {1, 1024} + }; + new PoolManager(objects::TC_STORE, poolCfg); + } + + { + LocalPool::LocalPoolConfig poolCfg = { + {15, 32}, {10, 64}, {5, 128}, {1, 1024} + }; + new PoolManager(objects::TM_STORE, poolCfg); + } + + { + LocalPool::LocalPoolConfig poolCfg = { + {15, 32}, {10, 64}, {5, 128}, {1, 1024} + }; + new PoolManager(objects::IPC_STORE, poolCfg); + } + + +#if OBSW_ADD_LWIP_NETWORKING == 1 + /* UDP Server */ + new TmTcLwIpUdpBridge(objects::UDP_BRIDGE, + objects::CCSDS_DISTRIBUTOR, objects::TM_STORE, objects::TC_STORE); + new UdpTcLwIpPollingTask(objects::UDP_POLLING_TASK, objects::UDP_BRIDGE); +#endif /* OBSW_ADD_LWIP_NETWORKING == 1 */ + +#endif /* OBSW_ADD_CORE_COMPONENTS == 1 */ + + ObjectFactory::produceGenericObjects(); + + new STM32TestTask(objects::TEST_TASK, false); +} diff --git a/bsp_stm32h7_rtems/core/ObjectFactory.h b/bsp_stm32h7_rtems/core/ObjectFactory.h new file mode 100644 index 0000000..6a6d657 --- /dev/null +++ b/bsp_stm32h7_rtems/core/ObjectFactory.h @@ -0,0 +1,9 @@ +#ifndef MISSION_CORE_OBJECTFACTORY_H_ +#define MISSION_CORE_OBJECTFACTORY_H_ + + +namespace ObjectFactory { + void produce(void* args); +}; + +#endif /* MISSION_CORE_OBJECTFACTORY_H_ */ diff --git a/bsp_stm32h7_rtems/core/printChar.c b/bsp_stm32h7_rtems/core/printChar.c new file mode 100644 index 0000000..b727e83 --- /dev/null +++ b/bsp_stm32h7_rtems/core/printChar.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +#include + +void printChar(const char* character, bool errStream) { + HAL_UART_Transmit(&stm32h7_usart3_instance.uart, (uint8_t*) character, 1, + DEBUG_UART_MS_TIMEOUT); + /* Does not work for some reason */ + //stm32h7_uart_polled_write(&stm32h7_usart3_instance.device, (int) character); +} + + + diff --git a/bsp_stm32h7_rtems/fsfwconfig/OBSWConfig.h.in b/bsp_stm32h7_rtems/fsfwconfig/OBSWConfig.h.in index 7e1dfcc..7ec9b9f 100644 --- a/bsp_stm32h7_rtems/fsfwconfig/OBSWConfig.h.in +++ b/bsp_stm32h7_rtems/fsfwconfig/OBSWConfig.h.in @@ -6,6 +6,7 @@ #ifndef FSFWCONFIG_OBSWCONFIG_H_ #define FSFWCONFIG_OBSWCONFIG_H_ +#define DEBUG_UART_MS_TIMEOUT 10 #define STM_USE_PERIPHERAL_TX_BUFFER_MPU_PROTECTION 1 //! Specify whether lwIP components are added. These are necessary for TMTC commanding diff --git a/bsp_stm32h7_rtems/init.c b/bsp_stm32h7_rtems/init.c new file mode 100644 index 0000000..fcc988d --- /dev/null +++ b/bsp_stm32h7_rtems/init.c @@ -0,0 +1,14 @@ +#include "RTEMSConfig.h" + +extern int main(); + +/** + * Entry point for the RTEMS BSP after low level and RTEMS executive initialization. + * @param argument + * @return + */ +rtems_task Init(rtems_task_argument argument) { + main(); + return (void) rtems_task_delete( RTEMS_SELF ); +} + diff --git a/bsp_stm32h7_rtems/main.cpp b/bsp_stm32h7_rtems/main.cpp new file mode 100644 index 0000000..19fabd7 --- /dev/null +++ b/bsp_stm32h7_rtems/main.cpp @@ -0,0 +1,52 @@ +#include "core/ObjectFactory.h" +#include "core/InitMission.h" +#include "stm32h7xx_nucleo.h" +#include "hardware_init.h" + +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serviceinterface/ServiceInterface.h" +#include "fsfw/timemanager/Clock.h" + +#include +#include +#include +#include + +#define BOARD_NAME "stm32h743zi-nucleo" + +ObjectManagerIF *objectManager = nullptr; + +#if FSFW_CPP_OSTREAM_ENABLED == 1 +ServiceInterfaceStream sif::debug("DEBUG", true); +ServiceInterfaceStream sif::info("INFO", true); +ServiceInterfaceStream sif::warning("WARNING", true); +ServiceInterfaceStream sif::error("ERROR", true); +#endif + +/** + * @brief Core function for the RTEMS BSP, called in Init function. + * @return + * @author R. Mueller + */ +int main() { + hardware_init(); + + printf("\n\r%s-- FSFW Example (RTEMS) --\n", sif::ANSI_COLOR_RESET); + printf("-- Compiled for %s --\n", BOARD_NAME); + printf("-- Compiled on %s %s --\n\r",__DATE__, __TIME__); + + timeval timeToSet; + timeToSet.tv_sec = UNIX_TIMESTAMP; + timeToSet.tv_usec = 0; + ReturnValue_t clockStatus = Clock::setClock(&timeToSet); + if(clockStatus != HasReturnvaluesIF::RETURN_OK) { + sif::printError("Clock configuration failed!\n"); + } + else { + sif::printInfo("Clock configured successfully.\n"); + } + ObjectManager::instance()->setObjectFactoryFunction(ObjectFactory::produce, nullptr); + ObjectManager::instance()->initialize(); + + InitMission::createTasks(); +} diff --git a/cmake/PreProjectConfig.cmake b/cmake/PreProjectConfig.cmake index 4c833d5..42702e1 100644 --- a/cmake/PreProjectConfig.cmake +++ b/cmake/PreProjectConfig.cmake @@ -21,14 +21,13 @@ if(NOT DEFINED RTEMS_PREFIX) endif() endif() -if(${TGT_BSP} MATCHES "arm/stm32h743zi-nucleo") +if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo") set(RTEMS_BSP "arm/nucleo-h743zi") else() if(NOT DEFINED RTEMS_BSP) if(NOT DEFINED ENV{RTEMS_BSP}) message(FATAL_ERROR - "RTEMS_BSP must be set either manually or as an environment" - "variable!" + "RTEMS_BSP must be set either manually or as an environment variable!" ) else() set(RTEMS_BSP $ENV{RTEMS_BSP}) @@ -38,10 +37,7 @@ endif() rtems_pre_project_config(${RTEMS_PREFIX} ${RTEMS_BSP}) -set(CMAKE_TOOLCHAIN_FILE - ${RTEMS_CONFIG_DIR}/RTEMSToolchain.cmake - PARENT_SCOPE -) +set(CMAKE_TOOLCHAIN_FILE ${RTEMS_CONFIG_DIR}/RTEMSToolchain.cmake) set(RTEMS_BSP ${RTEMS_BSP} CACHE STRING "RTEMS BSP") set(RTEMS_PREFIX ${RTEMS_PREFIX} CACHE STRING "RTEMS Prefix") diff --git a/example_common b/example_common index e487913..27215b6 160000 --- a/example_common +++ b/example_common @@ -1 +1 @@ -Subproject commit e4879130b09c76dac75265768fc757759e9aedcd +Subproject commit 27215b67aaa0a3e540ff4e369781ccac332a4662 diff --git a/fsfw b/fsfw index aafccd1..a65a184 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit aafccd191e3a592e19c09b01b95dea89c8936e54 +Subproject commit a65a1840838435f8ce3cfed8bc7a2adf74eac2ac