1192 lines
32 KiB
C
1192 lines
32 KiB
C
/**
|
|
******************************************************************************
|
|
* @file stm32wbxx_nucleo.c
|
|
* @author MCD Application Team
|
|
* @brief This file provides set of firmware functions to manage:
|
|
* - LEDs and push-button available on STM32WBXX-Nucleo Kit
|
|
* from STMicroelectronics
|
|
* - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD
|
|
* shield (reference ID 802)
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2019-2021 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.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "stm32wbxx_nucleo.h"
|
|
#include "stm32wbxx_nucleo_errno.h"
|
|
|
|
#if defined(__ICCARM__)
|
|
#include <LowLevelIOInterface.h>
|
|
#endif /* __ICCARM__ */
|
|
|
|
/** @addtogroup BSP
|
|
* @{
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO STM32WBxx-Nucleo
|
|
* @brief This file provides set of firmware functions to manage Leds and push-button
|
|
* available on STM32WBxx-Nucleo Kit from STMicroelectronics.
|
|
* It provides also LCD, joystick and uSD functions to communicate with
|
|
* Adafruit 1.8" TFT LCD shield (reference ID 802)
|
|
* @{
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_Private_Defines Private Defines
|
|
* @{
|
|
*/
|
|
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Variables
|
|
* @{
|
|
*/
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
UART_HandleTypeDef hcom_uart[COMn];
|
|
#endif /* (USE_BSP_COM_FEATURE > 0) */
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_LOW_LEVEL_Private_Defines LOW LEVEL Private Defines
|
|
* @{
|
|
*/
|
|
#if (USE_COM_LOG == 1)
|
|
/**
|
|
* @brief Redirect console output to COM
|
|
*/
|
|
#if defined(__ICCARM__)
|
|
/* New definition from EWARM V9, compatible with EWARM8 */
|
|
int iar_fputc(int ch);
|
|
#define PUTCHAR_PROTOTYPE int iar_fputc(int ch)
|
|
#elif defined (__CC_ARM) || defined(__ARMCC_VERSION)
|
|
/* ARM Compiler 5/6 */
|
|
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
|
|
#elif defined(__GNUC__)
|
|
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
|
#endif /* __ICCARM__ */
|
|
|
|
#endif /* USE_COM_LOG */
|
|
|
|
/**
|
|
* @brief STM32WBxx NUCLEO BSP Driver
|
|
*/
|
|
#define __STM32WBxx_NUCLEO_BSP_VERSION_MAIN (0x01U) /*!< [31:24] main version */
|
|
#define __STM32WBxx_NUCLEO_BSP_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */
|
|
#define __STM32WBxx_NUCLEO_BSP_VERSION_SUB2 (0x08U) /*!< [15:8] sub2 version */
|
|
#define __STM32WBxx_NUCLEO_BSP_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
|
#define __STM32WBxx_NUCLEO_BSP_VERSION ((__STM32WBxx_NUCLEO_BSP_VERSION_MAIN << 24)\
|
|
|(__STM32WBxx_NUCLEO_BSP_VERSION_SUB1 << 16)\
|
|
|(__STM32WBxx_NUCLEO_BSP_VERSION_SUB2 << 8 )\
|
|
|(__STM32WBxx_NUCLEO_BSP_VERSION_RC))
|
|
|
|
/**
|
|
* @brief LINK SD Card
|
|
*/
|
|
#define SD_DUMMY_BYTE 0xFF
|
|
#define SD_NO_RESPONSE_EXPECTED 0x80
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_LOW_LEVEL_Private_Variables Private Variables
|
|
* @{
|
|
*/
|
|
GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT};
|
|
const uint16_t GPIO_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN};
|
|
|
|
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {BUTTON_SW1_GPIO_PORT, BUTTON_SW2_GPIO_PORT, BUTTON_SW3_GPIO_PORT};
|
|
const uint16_t BUTTON_PIN[BUTTONn] = {BUTTON_SW1_PIN, BUTTON_SW2_PIN, BUTTON_SW3_PIN};
|
|
const uint8_t BUTTON_IRQn[BUTTONn] = {BUTTON_SW1_EXTI_IRQn, BUTTON_SW2_EXTI_IRQn, BUTTON_SW3_EXTI_IRQn};
|
|
|
|
/**
|
|
* @brief BUS variables
|
|
*/
|
|
|
|
#ifdef HAL_SPI_MODULE_ENABLED
|
|
uint32_t hnucleo_SpixTimeout = NUCLEO_SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
|
|
static SPI_HandleTypeDef hnucleo_Spi;
|
|
#endif /* HAL_SPI_MODULE_ENABLED */
|
|
|
|
#ifdef HAL_ADC_MODULE_ENABLED
|
|
static ADC_HandleTypeDef hnucleo_Adc;
|
|
/* ADC channel configuration structure declaration */
|
|
static ADC_ChannelConfTypeDef hnucleo_AdcChannelConfig;
|
|
#endif /* HAL_ADC_MODULE_ENABLED */
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
static USART_TypeDef* COM_USART[COMn] = {COM1_UART};
|
|
|
|
#if (USE_COM_LOG > 0)
|
|
static COM_TypeDef COM_ActiveLogPort = COM1;
|
|
#endif /* USE_COM_LOG */
|
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
|
|
static uint32_t IsComMspCbValid[COMn] = {0};
|
|
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
|
|
#endif /* (USE_BSP_COM_FEATURE > 0) */
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_Private_Functions Private Functions
|
|
* @{
|
|
*/
|
|
#ifdef HAL_SPI_MODULE_ENABLED
|
|
static void SPIx_Init(void);
|
|
static void SPIx_Write(uint8_t Value);
|
|
static void SPIx_Error (void);
|
|
static void SPIx_MspInit(void);
|
|
#endif /* HAL_SPI_MODULE_ENABLED */
|
|
|
|
#ifdef HAL_ADC_MODULE_ENABLED
|
|
static HAL_StatusTypeDef ADCx_Init(void);
|
|
static void ADCx_MspInit(ADC_HandleTypeDef *hadc);
|
|
#endif /* HAL_ADC_MODULE_ENABLED */
|
|
|
|
#ifdef HAL_SPI_MODULE_ENABLED
|
|
/* SD IO functions */
|
|
void SD_IO_Init(void);
|
|
void SD_IO_CSState(uint8_t state);
|
|
void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength);
|
|
uint8_t SD_IO_WriteByte(uint8_t Data);
|
|
|
|
/* LCD IO functions */
|
|
void LCD_IO_Init(void);
|
|
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size);
|
|
void LCD_IO_WriteReg(uint8_t LCDReg);
|
|
void LCD_Delay(uint32_t delay);
|
|
#endif /* HAL_SPI_MODULE_ENABLED */
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
static void COM1_MspInit(UART_HandleTypeDef *huart);
|
|
static void COM1_MspDeInit(UART_HandleTypeDef *huart);
|
|
#endif /* (USE_BSP_COM_FEATURE > 0) */
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_Exported_Functions Exported Functions
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief This method returns the STM32WBxx NUCLEO BSP Driver revision
|
|
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
|
|
*/
|
|
uint32_t BSP_GetVersion(void)
|
|
{
|
|
return __STM32WBxx_NUCLEO_BSP_VERSION;
|
|
}
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_LED_Functions LED Functions
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Configures LED GPIO.
|
|
* @param Led: LED to be configured.
|
|
* This parameter can be one of the following values:
|
|
* @arg LED1
|
|
* @arg LED2
|
|
* @arg LED3
|
|
* @retval None
|
|
*/
|
|
void BSP_LED_Init(Led_TypeDef Led)
|
|
{
|
|
GPIO_InitTypeDef gpioinitstruct = {0};
|
|
|
|
/* Enable the GPIO_LED Clock */
|
|
LEDx_GPIO_CLK_ENABLE(Led);
|
|
|
|
/* Configure the GPIO_LED pin */
|
|
gpioinitstruct.Pin = GPIO_PIN[Led];
|
|
gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
gpioinitstruct.Pull = GPIO_NOPULL;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
HAL_GPIO_Init(GPIO_PORT[Led], &gpioinitstruct);
|
|
|
|
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
|
}
|
|
|
|
/**
|
|
* @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 None
|
|
*/
|
|
void BSP_LED_DeInit(Led_TypeDef Led)
|
|
{
|
|
GPIO_InitTypeDef gpio_init_structure;
|
|
|
|
/* Turn off LED */
|
|
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
|
/* DeInit the GPIO_LED pin */
|
|
gpio_init_structure.Pin = GPIO_PIN[Led];
|
|
HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
|
|
}
|
|
|
|
/**
|
|
* @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 None
|
|
*/
|
|
void BSP_LED_On(Led_TypeDef Led)
|
|
{
|
|
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
|
|
}
|
|
|
|
/**
|
|
* @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 None
|
|
*/
|
|
void BSP_LED_Off(Led_TypeDef Led)
|
|
{
|
|
HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
|
|
}
|
|
|
|
/**
|
|
* @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 None
|
|
*/
|
|
void BSP_LED_Toggle(Led_TypeDef Led)
|
|
{
|
|
HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
|
|
}
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_BUTTON_Functions BUTTON Functions
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Configures Button GPIO and EXTI Line.
|
|
* @param Button: Specifies the Button to be configured.
|
|
* This parameter can be one of following parameters:
|
|
* @arg BUTTON_SW1
|
|
* @arg BUTTON_SW2
|
|
* @arg BUTTON_SW3
|
|
* @param ButtonMode: Specifies Button mode.
|
|
* This parameter can be one of following parameters:
|
|
* @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
|
|
* @retval None
|
|
*/
|
|
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
|
|
{
|
|
GPIO_InitTypeDef gpioinitstruct = {0};
|
|
|
|
/* Enable the BUTTON Clock */
|
|
BUTTONx_GPIO_CLK_ENABLE(Button);
|
|
|
|
if(ButtonMode == BUTTON_MODE_GPIO)
|
|
{
|
|
/* Configure Button pin as input */
|
|
gpioinitstruct.Pin = BUTTON_PIN[Button];
|
|
gpioinitstruct.Mode = GPIO_MODE_INPUT;
|
|
gpioinitstruct.Pull = GPIO_PULLUP;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
|
|
|
/* Wait Button pin startup stability */
|
|
HAL_Delay(1);
|
|
}
|
|
|
|
if(ButtonMode == BUTTON_MODE_EXTI)
|
|
{
|
|
/* Configure Button pin as input with External interrupt */
|
|
gpioinitstruct.Pin = BUTTON_PIN[Button];
|
|
gpioinitstruct.Pull = GPIO_PULLUP;
|
|
gpioinitstruct.Mode = GPIO_MODE_IT_FALLING;
|
|
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
|
|
|
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
|
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
|
|
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Push Button DeInit.
|
|
* @param Button: Button to be configured
|
|
* This parameter can be one of following parameters:
|
|
* @arg BUTTON_SW1
|
|
* @arg BUTTON_SW2
|
|
* @arg BUTTON_SW3
|
|
* @note PB DeInit does not disable the GPIO clock
|
|
* @retval None
|
|
*/
|
|
void 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);
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the selected Button state.
|
|
* @param Button: Specifies the Button to be checked.
|
|
* This parameter can be one of following parameters:
|
|
* @arg BUTTON_SW1
|
|
* @arg BUTTON_SW2
|
|
* @arg BUTTON_SW3
|
|
* @retval The Button GPIO pin value.
|
|
*/
|
|
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
|
{
|
|
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
|
}
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#ifdef HAL_ADC_MODULE_ENABLED
|
|
|
|
/** @defgroup STM32WBXX_NUCLEO_BUTTON_Functions BUTTON Functions
|
|
* @{
|
|
*/
|
|
|
|
/**
|
|
* @brief Configures joystick available on adafruit 1.8" TFT shield
|
|
* managed through ADC to detect motion.
|
|
* @retval Joystickstatus (0=> success, 1=> fail)
|
|
*/
|
|
uint8_t BSP_JOY_Init(void)
|
|
{
|
|
if (ADCx_Init() != HAL_OK)
|
|
{
|
|
return (uint8_t) HAL_ERROR;
|
|
}
|
|
|
|
/* Select Channel 15 to be converted */
|
|
hnucleo_AdcChannelConfig.Channel = ADC_CHANNEL_5;
|
|
hnucleo_AdcChannelConfig.SamplingTime = ADC_SAMPLETIME_24CYCLES_5;
|
|
hnucleo_AdcChannelConfig.Rank = ADC_REGULAR_RANK_1;
|
|
hnucleo_AdcChannelConfig.SingleDiff = ADC_SINGLE_ENDED;
|
|
hnucleo_AdcChannelConfig.OffsetNumber = ADC_OFFSET_NONE;
|
|
|
|
/* Return Joystick initialization status */
|
|
return (uint8_t) HAL_ADC_ConfigChannel(&hnucleo_Adc, &hnucleo_AdcChannelConfig);
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the Joystick key pressed.
|
|
* @note To know which Joystick key is pressed we need to detect the voltage
|
|
* level on each key output
|
|
* - None : 3.3 V / 4095
|
|
* - SEL : 1.055 V / 1308
|
|
* - DOWN : 0.71 V / 88
|
|
* - LEFT : 3.0 V / 3720
|
|
* - RIGHT : 0.595 V / 737
|
|
* - UP : 1.65 V / 2046
|
|
* @retval JOYState_TypeDef: Code of the Joystick key pressed.
|
|
*/
|
|
JOYState_TypeDef BSP_JOY_GetState(void)
|
|
{
|
|
JOYState_TypeDef state = JOY_NONE;
|
|
uint16_t keyconvertedvalue = 0;
|
|
|
|
/* Start the conversion process */
|
|
HAL_ADC_Start(&hnucleo_Adc);
|
|
|
|
/* Wait for the end of conversion */
|
|
HAL_ADC_PollForConversion(&hnucleo_Adc, 10);
|
|
|
|
/* Check if the continuous conversion of regular channel is finished */
|
|
if(HAL_ADC_GetState(&hnucleo_Adc) & HAL_ADC_STATE_REG_EOC)
|
|
{
|
|
/* Get the converted value of regular channel */
|
|
keyconvertedvalue = HAL_ADC_GetValue(&hnucleo_Adc);
|
|
}
|
|
|
|
if((keyconvertedvalue > 1980) && (keyconvertedvalue < 2120))
|
|
{
|
|
state = JOY_UP;
|
|
}
|
|
else if((keyconvertedvalue > 630) && (keyconvertedvalue < 830))
|
|
{
|
|
state = JOY_RIGHT;
|
|
}
|
|
else if((keyconvertedvalue > 1210) && (keyconvertedvalue < 1410))
|
|
{
|
|
state = JOY_SEL;
|
|
}
|
|
else if((keyconvertedvalue > 20) && (keyconvertedvalue < 160))
|
|
{
|
|
state = JOY_DOWN;
|
|
}
|
|
else if((keyconvertedvalue > 3620) && (keyconvertedvalue < 3820))
|
|
{
|
|
state = JOY_LEFT;
|
|
}
|
|
else
|
|
{
|
|
state = JOY_NONE;
|
|
}
|
|
|
|
/* Return the code of the Joystick key pressed*/
|
|
return state;
|
|
}
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#endif /* HAL_ADC_MODULE_ENABLED */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/** @addtogroup STM32WBXX_NUCLEO_Private_Functions
|
|
* @{
|
|
*/
|
|
#if defined(HAL_SPI_MODULE_ENABLED)
|
|
/**
|
|
* @brief Initialize SPI MSP.
|
|
* @retval None
|
|
*/
|
|
static void SPIx_MspInit(void)
|
|
{
|
|
GPIO_InitTypeDef gpioinitstruct = {0};
|
|
|
|
/*** Configure the GPIOs ***/
|
|
/* Enable GPIO clock */
|
|
NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE();
|
|
NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE();
|
|
|
|
/* Configure SPI SCK */
|
|
gpioinitstruct.Pin = NUCLEO_SPIx_SCK_PIN;
|
|
gpioinitstruct.Mode = GPIO_MODE_AF_PP;
|
|
gpioinitstruct.Pull = GPIO_PULLUP;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
gpioinitstruct.Alternate = NUCLEO_SPIx_SCK_AF;
|
|
HAL_GPIO_Init(NUCLEO_SPIx_SCK_GPIO_PORT, &gpioinitstruct);
|
|
|
|
/* Configure SPI MISO and MOSI */
|
|
gpioinitstruct.Pin = NUCLEO_SPIx_MOSI_PIN;
|
|
gpioinitstruct.Alternate = NUCLEO_SPIx_MISO_MOSI_AF;
|
|
gpioinitstruct.Pull = GPIO_PULLDOWN;
|
|
HAL_GPIO_Init(NUCLEO_SPIx_MISO_MOSI_GPIO_PORT, &gpioinitstruct);
|
|
|
|
gpioinitstruct.Pin = NUCLEO_SPIx_MISO_PIN;
|
|
HAL_GPIO_Init(NUCLEO_SPIx_MISO_MOSI_GPIO_PORT, &gpioinitstruct);
|
|
|
|
/*** Configure the SPI peripheral ***/
|
|
/* Enable SPI clock */
|
|
NUCLEO_SPIx_CLK_ENABLE();
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize SPI HAL.
|
|
* @retval None
|
|
*/
|
|
static void SPIx_Init(void)
|
|
{
|
|
if(HAL_SPI_GetState(&hnucleo_Spi) == HAL_SPI_STATE_RESET)
|
|
{
|
|
/* SPI Config */
|
|
hnucleo_Spi.Instance = NUCLEO_SPIx;
|
|
/* SPI baudrate is set to 8 MHz maximum (PCLK2/SPI_BaudRatePrescaler = 32/4 = 8 MHz)
|
|
to verify these constraints:
|
|
- ST7735 LCD SPI interface max baudrate is 15MHz for write and 6.66MHz for read
|
|
Since the provided driver doesn't use read capability from LCD, only constraint
|
|
on write baudrate is considered.
|
|
- SD card SPI interface max baudrate is 25MHz for write/read
|
|
- PCLK2 max frequency is 32 MHz
|
|
*/
|
|
hnucleo_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
|
hnucleo_Spi.Init.Direction = SPI_DIRECTION_2LINES;
|
|
hnucleo_Spi.Init.CLKPhase = SPI_PHASE_2EDGE;
|
|
hnucleo_Spi.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
|
hnucleo_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
hnucleo_Spi.Init.CRCPolynomial = 7;
|
|
hnucleo_Spi.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
|
hnucleo_Spi.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
hnucleo_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
hnucleo_Spi.Init.NSS = SPI_NSS_SOFT;
|
|
hnucleo_Spi.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
|
hnucleo_Spi.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
hnucleo_Spi.Init.Mode = SPI_MODE_MASTER;
|
|
|
|
SPIx_MspInit();
|
|
HAL_SPI_Init(&hnucleo_Spi);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief SPI Write byte(s) to device
|
|
* @param DataIn: Pointer to data buffer to write
|
|
* @param DataOut: Pointer to data buffer for read data
|
|
* @param DataLength: number of bytes to write
|
|
* @retval None
|
|
*/
|
|
static void SPIx_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength)
|
|
{
|
|
HAL_StatusTypeDef status = HAL_OK;
|
|
status = HAL_SPI_TransmitReceive(&hnucleo_Spi, (uint8_t*) DataIn, DataOut, DataLength, hnucleo_SpixTimeout);
|
|
|
|
/* Check the communication status */
|
|
if(status != HAL_OK)
|
|
{
|
|
/* Execute user timeout callback */
|
|
SPIx_Error();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief SPI Write a byte to device
|
|
* @param Value: value to be written
|
|
* @retval None
|
|
*/
|
|
static void SPIx_Write(uint8_t Value)
|
|
{
|
|
HAL_StatusTypeDef status = HAL_OK;
|
|
uint8_t data;
|
|
|
|
status = HAL_SPI_TransmitReceive(&hnucleo_Spi, (uint8_t*) &Value, &data, 1, hnucleo_SpixTimeout);
|
|
|
|
/* Check the communication status */
|
|
if(status != HAL_OK)
|
|
{
|
|
/* Execute user timeout callback */
|
|
SPIx_Error();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief SPI error treatment function
|
|
* @retval None
|
|
*/
|
|
static void SPIx_Error (void)
|
|
{
|
|
/* De-initialize the SPI communication BUS */
|
|
HAL_SPI_DeInit(&hnucleo_Spi);
|
|
|
|
/* Re-Initiaize the SPI communication BUS */
|
|
SPIx_Init();
|
|
}
|
|
|
|
/******************************************************************************
|
|
LINK OPERATIONS
|
|
*******************************************************************************/
|
|
|
|
/********************************* LINK SD ************************************/
|
|
/**
|
|
* @brief Initialize the SD Card and put it into StandBy State (Ready for
|
|
* data transfer).
|
|
* @retval None
|
|
*/
|
|
void SD_IO_Init(void)
|
|
{
|
|
GPIO_InitTypeDef gpioinitstruct = {0};
|
|
uint8_t counter = 0;
|
|
|
|
/* SD_CS_GPIO Periph clock enable */
|
|
SD_CS_GPIO_CLK_ENABLE();
|
|
|
|
/* Configure SD_CS_PIN pin: SD Card CS pin */
|
|
gpioinitstruct.Pin = SD_CS_PIN;
|
|
gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
gpioinitstruct.Pull = GPIO_PULLUP;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
HAL_GPIO_Init(SD_CS_GPIO_PORT, &gpioinitstruct);
|
|
|
|
/* Configure LCD_CS_PIN pin: LCD Card CS pin */
|
|
gpioinitstruct.Pin = LCD_CS_PIN;
|
|
gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
gpioinitstruct.Pull = GPIO_NOPULL;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
HAL_GPIO_Init(LCD_CS_GPIO_PORT, &gpioinitstruct);
|
|
LCD_CS_HIGH();
|
|
|
|
/*------------Put SD in SPI mode--------------*/
|
|
/* SD SPI Config */
|
|
SPIx_Init();
|
|
|
|
/* SD chip select high */
|
|
SD_CS_HIGH();
|
|
|
|
/* Send dummy byte 0xFF, 10 times with CS high */
|
|
/* Rise CS and MOSI for 80 clocks cycles */
|
|
for (counter = 0; counter <= 9; counter++)
|
|
{
|
|
/* Send dummy byte 0xFF */
|
|
SD_IO_WriteByte(SD_DUMMY_BYTE);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Set SD interface Chip Select state
|
|
* @param val: 0 (low) or 1 (high) state
|
|
* @retval None
|
|
*/
|
|
void SD_IO_CSState(uint8_t val)
|
|
{
|
|
if(val == 1)
|
|
{
|
|
SD_CS_HIGH();
|
|
}
|
|
else
|
|
{
|
|
SD_CS_LOW();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Write byte(s) on the SD
|
|
* @param DataIn: Pointer to data buffer to write
|
|
* @param DataOut: Pointer to data buffer for read data
|
|
* @param DataLength: number of bytes to write
|
|
* @retval None
|
|
*/
|
|
void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength)
|
|
{
|
|
/* Send the byte */
|
|
SPIx_WriteReadData(DataIn, DataOut, DataLength);
|
|
}
|
|
|
|
/**
|
|
* @brief Write a byte on the SD.
|
|
* @param Data: byte to send.
|
|
* @retval Data written
|
|
*/
|
|
uint8_t SD_IO_WriteByte(uint8_t Data)
|
|
{
|
|
uint8_t tmp;
|
|
|
|
/* Send the byte */
|
|
SPIx_WriteReadData(&Data,&tmp,1);
|
|
return tmp;
|
|
}
|
|
|
|
/********************************* LINK LCD ***********************************/
|
|
/**
|
|
* @brief Initialize the LCD
|
|
* @retval None
|
|
*/
|
|
void LCD_IO_Init(void)
|
|
{
|
|
GPIO_InitTypeDef gpioinitstruct = {0};
|
|
|
|
/* LCD_CS_GPIO and LCD_DC_GPIO Periph clock enable */
|
|
LCD_CS_GPIO_CLK_ENABLE();
|
|
LCD_DC_GPIO_CLK_ENABLE();
|
|
|
|
/* Configure LCD_CS_PIN pin: LCD Card CS pin */
|
|
gpioinitstruct.Pin = LCD_CS_PIN;
|
|
gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
gpioinitstruct.Pull = GPIO_NOPULL;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
HAL_GPIO_Init(LCD_CS_GPIO_PORT, &gpioinitstruct);
|
|
|
|
/* Configure LCD_DC_PIN pin: LCD Card DC pin */
|
|
gpioinitstruct.Pin = LCD_DC_PIN;
|
|
HAL_GPIO_Init(LCD_DC_GPIO_PORT, &gpioinitstruct);
|
|
|
|
/* LCD chip select high */
|
|
LCD_CS_HIGH();
|
|
|
|
/* LCD SPI Config */
|
|
SPIx_Init();
|
|
}
|
|
|
|
/**
|
|
* @brief Write command to select the LCD register.
|
|
* @param LCDReg: Address of the selected register.
|
|
* @retval None
|
|
*/
|
|
void LCD_IO_WriteReg(uint8_t LCDReg)
|
|
{
|
|
/* Reset LCD control line CS */
|
|
LCD_CS_LOW();
|
|
|
|
/* Set LCD data/command line DC to Low */
|
|
LCD_DC_LOW();
|
|
|
|
/* Send Command */
|
|
SPIx_Write(LCDReg);
|
|
|
|
/* Deselect : Chip Select high */
|
|
LCD_CS_HIGH();
|
|
}
|
|
|
|
/**
|
|
* @brief Write register value.
|
|
* @param pData Pointer on the register value
|
|
* @param Size Size of byte to transmit to the register
|
|
* @retval None
|
|
*/
|
|
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size)
|
|
{
|
|
uint32_t counter = 0;
|
|
__IO uint32_t data = 0;
|
|
|
|
/* Reset LCD control line CS */
|
|
LCD_CS_LOW();
|
|
|
|
/* Set LCD data/command line DC to High */
|
|
LCD_DC_HIGH();
|
|
|
|
if (Size == 1)
|
|
{
|
|
/* Only 1 byte to be sent to LCD - general interface can be used */
|
|
/* Send Data */
|
|
SPIx_Write(*pData);
|
|
}
|
|
else
|
|
{
|
|
/* Several data should be sent in a raw */
|
|
/* Direct SPI accesses for optimization */
|
|
for (counter = Size; counter != 0; counter--)
|
|
{
|
|
while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE)
|
|
{
|
|
}
|
|
/* Need to invert bytes for LCD*/
|
|
*((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *(pData+1);
|
|
|
|
while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE)
|
|
{
|
|
}
|
|
*((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *pData;
|
|
counter--;
|
|
pData += 2;
|
|
}
|
|
|
|
/* Wait until the bus is ready before releasing Chip select */
|
|
while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_BSY) != RESET)
|
|
{
|
|
}
|
|
}
|
|
|
|
/* Empty the Rx fifo */
|
|
data = *(&hnucleo_Spi.Instance->DR);
|
|
UNUSED(data); /* Remove GNU warning */
|
|
|
|
/* Deselect : Chip Select high */
|
|
LCD_CS_HIGH();
|
|
}
|
|
|
|
/**
|
|
* @brief Wait for loop in ms.
|
|
* @param Delay in ms.
|
|
* @retval None
|
|
*/
|
|
void LCD_Delay(uint32_t Delay)
|
|
{
|
|
HAL_Delay(Delay);
|
|
}
|
|
|
|
#endif /* HAL_SPI_MODULE_ENABLED */
|
|
|
|
#ifdef HAL_ADC_MODULE_ENABLED
|
|
/******************************* LINK JOYSTICK ********************************/
|
|
/**
|
|
* @brief Initialize ADC MSP.
|
|
* @retval None
|
|
*/
|
|
static void ADCx_MspInit(ADC_HandleTypeDef *hadc)
|
|
{
|
|
GPIO_InitTypeDef gpioinitstruct = {0};
|
|
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct;
|
|
|
|
/*** Configure the GPIOs ***/
|
|
/* Enable GPIO clock */
|
|
NUCLEO_ADCx_GPIO_CLK_ENABLE();
|
|
|
|
/* Configure ADC1 Channel8 as analog input */
|
|
gpioinitstruct.Pin = NUCLEO_ADCx_GPIO_PIN ;
|
|
gpioinitstruct.Mode = GPIO_MODE_ANALOG;
|
|
gpioinitstruct.Pull = GPIO_NOPULL;
|
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
HAL_GPIO_Init(NUCLEO_ADCx_GPIO_PORT, &gpioinitstruct);
|
|
|
|
/*** Configure the ADC peripheral ***/
|
|
/* Enable ADC clock */
|
|
NUCLEO_ADCx_CLK_ENABLE();
|
|
|
|
/* Configure SYSCLK as source clock for ADC */
|
|
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
|
RCC_PeriphCLKInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
|
|
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
|
|
}
|
|
|
|
/**
|
|
* @brief Initializes ADC HAL.
|
|
* @retval None
|
|
*/
|
|
static HAL_StatusTypeDef ADCx_Init(void)
|
|
{
|
|
if(HAL_ADC_GetState(&hnucleo_Adc) == HAL_ADC_STATE_RESET)
|
|
{
|
|
/* ADC Config */
|
|
hnucleo_Adc.Instance = NUCLEO_ADCx;
|
|
hnucleo_Adc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
|
|
hnucleo_Adc.Init.Resolution = ADC_RESOLUTION_12B;
|
|
hnucleo_Adc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
|
hnucleo_Adc.Init.ScanConvMode = DISABLE;
|
|
hnucleo_Adc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
|
hnucleo_Adc.Init.LowPowerAutoWait = DISABLE;
|
|
hnucleo_Adc.Init.ContinuousConvMode = DISABLE;
|
|
hnucleo_Adc.Init.NbrOfConversion = 1;
|
|
hnucleo_Adc.Init.DiscontinuousConvMode = DISABLE;
|
|
hnucleo_Adc.Init.NbrOfDiscConversion = 1;
|
|
hnucleo_Adc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
|
hnucleo_Adc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
|
hnucleo_Adc.Init.DMAContinuousRequests = DISABLE;
|
|
hnucleo_Adc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
|
hnucleo_Adc.Init.OversamplingMode = DISABLE;
|
|
|
|
ADCx_MspInit(&hnucleo_Adc);
|
|
if (HAL_ADC_Init(&hnucleo_Adc) != HAL_OK)
|
|
{
|
|
return HAL_ERROR;
|
|
}
|
|
|
|
if (HAL_ADCEx_Calibration_Start(&hnucleo_Adc,ADC_SINGLE_ENDED) != HAL_OK)
|
|
{
|
|
return HAL_ERROR;
|
|
}
|
|
}
|
|
|
|
return HAL_OK;
|
|
}
|
|
|
|
#endif /* HAL_ADC_MODULE_ENABLED */
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
/** @addtogroup STM32WBXX_NUCLEO_LOW_LEVEL_COM_Functions
|
|
* @{
|
|
*/
|
|
/**
|
|
* @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 == 0U)
|
|
{
|
|
if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
|
|
{
|
|
return BSP_ERROR_MSP_FAILURE;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if(MX_LPUART1_Init(&hcom_uart[COM], COM_Init) != HAL_OK)
|
|
{
|
|
return 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)
|
|
{
|
|
return 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_LPUART1_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 = 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;
|
|
}
|
|
|
|
#if defined(__ICCARM__)
|
|
/**
|
|
* @brief Retargets the C library __write function to the IAR function iar_fputc.
|
|
* @param file: file descriptor.
|
|
* @param ptr: pointer to the buffer where the data is stored.
|
|
* @param len: length of the data to write in bytes.
|
|
* @retval length of the written data in bytes.
|
|
*/
|
|
size_t __write(int file, unsigned char const *ptr, size_t len)
|
|
{
|
|
size_t idx;
|
|
unsigned char const *pdata = ptr;
|
|
|
|
for (idx = 0; idx < len; idx++)
|
|
{
|
|
iar_fputc((int)*pdata);
|
|
pdata++;
|
|
}
|
|
return len;
|
|
}
|
|
#endif /* __ICCARM__ */
|
|
|
|
/**
|
|
* @brief Redirect console output to COM
|
|
*/
|
|
PUTCHAR_PROTOTYPE
|
|
{
|
|
(void) 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 > 0) */
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
/**
|
|
* @brief Initializes COM1 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 DeInitialize COM1 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 > 0) */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|