---vl6180dr
This commit is contained in:
2
.idea/runConfigurations/OCD_Boot.xml
generated
2
.idea/runConfigurations/OCD_Boot.xml
generated
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="OCD Boot" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="myProject" TARGET_NAME="boot.elf" CONFIG_NAME="BOOT" version="1" RUN_TARGET_PROJECT_NAME="myProject" RUN_TARGET_NAME="boot.elf">
|
<configuration default="false" name="OCD Boot" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="myProject" TARGET_NAME="boot.elf" CONFIG_NAME="BOOT_DEBUG" version="1" RUN_TARGET_PROJECT_NAME="myProject" RUN_TARGET_NAME="boot.elf">
|
||||||
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="RUN" download-type="UPDATED_ONLY">
|
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="RUN" download-type="UPDATED_ONLY">
|
||||||
<debugger kind="GDB" isBundled="true" />
|
<debugger kind="GDB" isBundled="true" />
|
||||||
</openocd>
|
</openocd>
|
||||||
|
|||||||
10
.idea/runConfigurations/OCD_mainprog.xml
generated
10
.idea/runConfigurations/OCD_mainprog.xml
generated
@@ -1,10 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="OCD mainprog" type="com.jetbrains.cidr.embedded.openocd.conf.type" factoryName="com.jetbrains.cidr.embedded.openocd.conf.factory" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="myProject" TARGET_NAME="main_prog.elf" CONFIG_NAME="Debug" version="1" RUN_PATH="$PROJECT_DIR$/cmake-build-release/main_prog/main_prog_SRECORD.hex">
|
|
||||||
<openocd version="1" gdb-port="3333" telnet-port="4444" board-config="board/st_nucleo_g0.cfg" reset-type="INIT" download-type="NONE">
|
|
||||||
<debugger kind="GDB" isBundled="true" />
|
|
||||||
</openocd>
|
|
||||||
<method v="2">
|
|
||||||
<option name="CLION.COMPOUND.BUILD" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
****************************************************************************************/
|
****************************************************************************************/
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "header.h" /* generic header */
|
#include "header.h" /* generic header */
|
||||||
|
#include "vl6180_app.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "uart_bridge.hpp"
|
#include "uart_bridge.hpp"
|
||||||
@@ -51,6 +52,7 @@ void AppInit(void)
|
|||||||
{
|
{
|
||||||
/* Initialize the timer driver. */
|
/* Initialize the timer driver. */
|
||||||
TimerInit();
|
TimerInit();
|
||||||
|
vl6180_init();
|
||||||
/* Initialize the led driver. */
|
/* Initialize the led driver. */
|
||||||
LedInit();
|
LedInit();
|
||||||
/* initialize the bootloader interface */
|
/* initialize the bootloader interface */
|
||||||
|
|||||||
@@ -60,10 +60,13 @@ void Error_Handler(void);
|
|||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
#define GPIO_RESET_Pin GPIO_PIN_1
|
#define GPIO_RESET_Pin GPIO_PIN_1
|
||||||
#define GPIO_RESET_GPIO_Port GPIOA
|
#define GPIO_RESET_GPIO_Port GPIOA
|
||||||
|
#define GPIO_RESET_EXTI_IRQn EXTI0_1_IRQn
|
||||||
#define LIGHTING_EN_Pin GPIO_PIN_4
|
#define LIGHTING_EN_Pin GPIO_PIN_4
|
||||||
#define LIGHTING_EN_GPIO_Port GPIOA
|
#define LIGHTING_EN_GPIO_Port GPIOA
|
||||||
#define READER_EN_Pin GPIO_PIN_5
|
#define READER_EN_Pin GPIO_PIN_5
|
||||||
#define READER_EN_GPIO_Port GPIOA
|
#define READER_EN_GPIO_Port GPIOA
|
||||||
|
#define CS_PROXIMITY_Pin GPIO_PIN_8
|
||||||
|
#define CS_PROXIMITY_GPIO_Port GPIOA
|
||||||
#define CONTROL_PIN_Pin GPIO_PIN_4
|
#define CONTROL_PIN_Pin GPIO_PIN_4
|
||||||
#define CONTROL_PIN_GPIO_Port GPIOB
|
#define CONTROL_PIN_GPIO_Port GPIOB
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ void HardFault_Handler(void);
|
|||||||
void SVC_Handler(void);
|
void SVC_Handler(void);
|
||||||
void PendSV_Handler(void);
|
void PendSV_Handler(void);
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
|
void EXTI0_1_IRQHandler(void);
|
||||||
void USART1_IRQHandler(void);
|
void USART1_IRQHandler(void);
|
||||||
void USART2_IRQHandler(void);
|
void USART2_IRQHandler(void);
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|||||||
@@ -50,16 +50,22 @@ void MX_GPIO_Init(void)
|
|||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOA, LIGHTING_EN_Pin|READER_EN_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOA, LIGHTING_EN_Pin|READER_EN_Pin|CS_PROXIMITY_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pins : PA0 PAPin */
|
/*Configure GPIO pin : PA0 */
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_RESET_Pin;
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pins : PAPin PAPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = LIGHTING_EN_Pin|READER_EN_Pin;
|
GPIO_InitStruct.Pin = GPIO_RESET_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
HAL_GPIO_Init(GPIO_RESET_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : PAPin PAPin PAPin */
|
||||||
|
GPIO_InitStruct.Pin = LIGHTING_EN_Pin|READER_EN_Pin|CS_PROXIMITY_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
@@ -68,9 +74,13 @@ void MX_GPIO_Init(void)
|
|||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = CONTROL_PIN_Pin;
|
GPIO_InitStruct.Pin = CONTROL_PIN_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(CONTROL_PIN_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(CONTROL_PIN_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* EXTI interrupt init*/
|
||||||
|
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ int main(void) {
|
|||||||
MX_I2C2_Init();
|
MX_I2C2_Init();
|
||||||
MX_TIM3_Init();
|
MX_TIM3_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
HAL_GPIO_TogglePin(LIGHTING_EN_GPIO_Port, LIGHTING_EN_Pin);
|
|
||||||
/* Initialize the user program application. */
|
/* Initialize the user program application. */
|
||||||
AppInit();
|
AppInit();
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|||||||
@@ -139,6 +139,21 @@ void SysTick_Handler(void)
|
|||||||
/* please refer to the startup file (startup_stm32g0xx.s). */
|
/* please refer to the startup file (startup_stm32g0xx.s). */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles EXTI line 0 and line 1 interrupts.
|
||||||
|
*/
|
||||||
|
void EXTI0_1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN EXTI0_1_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END EXTI0_1_IRQn 0 */
|
||||||
|
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
|
||||||
|
HAL_GPIO_EXTI_IRQHandler(GPIO_RESET_Pin);
|
||||||
|
/* USER CODE BEGIN EXTI0_1_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END EXTI0_1_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
|
* @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ void MX_TIM3_Init(void)
|
|||||||
}
|
}
|
||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
sConfigOC.Pulse = 10616;
|
sConfigOC.Pulse = 10616;
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,556 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : custom.c
|
|
||||||
* @brief : Source file for the BSP Common driver
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2022 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 "custom.h"
|
|
||||||
|
|
||||||
/** @defgroup BSP BSP
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM CUSTOM
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL CUSTOM LOW LEVEL
|
|
||||||
* @brief This file provides set of firmware functions to manage Leds and push-button
|
|
||||||
* available on STM32WBxx-Nucleo Kit from STMicroelectronics.
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Private_Defines CUSTOM LOW LEVEL Private Defines
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_FunctionPrototypes CUSTOM LOW LEVEL Private Function Prototypes
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Private_Variables CUSTOM LOW LEVEL Private Variables
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
typedef void (* BSP_LED_GPIO_Init) (void);
|
|
||||||
static GPIO_TypeDef* LED_PORT[LEDn] = {LED2_GPIO_PORT};
|
|
||||||
static const uint16_t LED_PIN[LEDn] = {LED2_PIN};
|
|
||||||
static void LED_USER_GPIO_Init(void);
|
|
||||||
|
|
||||||
USART_TypeDef* COM_USART[COMn] = {COM1_UART};
|
|
||||||
UART_HandleTypeDef hcom_uart[COMn];
|
|
||||||
#if (USE_COM_LOG > 0)
|
|
||||||
static COM_TypeDef COM_ActiveLogPort;
|
|
||||||
#endif
|
|
||||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
|
||||||
static uint32_t IslpUart1MspCbValid = 0;
|
|
||||||
#endif
|
|
||||||
__weak HAL_StatusTypeDef MX_LPUART1_UART_Init(UART_HandleTypeDef* huart);
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Private_Functions CUSTOM LOW LEVEL Private Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
#if (USE_BSP_COM_FEATURE > 0)
|
|
||||||
static void LPUART1_MspInit(UART_HandleTypeDef *huart);
|
|
||||||
static void LPUART1_MspDeInit(UART_HandleTypeDef *huart);
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @brief This method returns the STM32WBxx NUCLEO BSP Driver revision
|
|
||||||
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
|
|
||||||
*/
|
|
||||||
int32_t BSP_GetVersion(void)
|
|
||||||
{
|
|
||||||
return (int32_t)__CUSTOM_BSP_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configures LED on GPIO and/or on MFX.
|
|
||||||
* @param Led: LED to be configured.
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED2, LED4, ...
|
|
||||||
* @retval HAL status
|
|
||||||
*/
|
|
||||||
int32_t BSP_LED_Init(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
static const BSP_LED_GPIO_Init LedGpioInit[LEDn] = {LED_USER_GPIO_Init};
|
|
||||||
LedGpioInit[Led]();
|
|
||||||
return BSP_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DeInit LEDs.
|
|
||||||
* @param Led: LED to be configured.
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED2, LED4, ...
|
|
||||||
* @note Led DeInit does not disable the GPIO clock nor disable the Mfx
|
|
||||||
* @retval HAL status
|
|
||||||
*/
|
|
||||||
int32_t BSP_LED_DeInit(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef gpio_init_structure;
|
|
||||||
|
|
||||||
/* 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 BSP_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Turns selected LED On.
|
|
||||||
* @param Led: LED to be set on
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED1
|
|
||||||
* @arg LED2
|
|
||||||
* @arg LED3
|
|
||||||
* @arg LED4
|
|
||||||
* @retval HAL status
|
|
||||||
*/
|
|
||||||
int32_t BSP_LED_On(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(LED_PORT [Led], LED_PIN [Led], GPIO_PIN_SET);
|
|
||||||
|
|
||||||
return BSP_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Turns selected LED Off.
|
|
||||||
* @param Led: LED to be set off
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED1
|
|
||||||
* @arg LED2
|
|
||||||
* @arg LED3
|
|
||||||
* @arg LED4
|
|
||||||
* @retval HAL status
|
|
||||||
*/
|
|
||||||
int32_t BSP_LED_Off(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(LED_PORT [Led], LED_PIN [Led], GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
return BSP_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Toggles the selected LED.
|
|
||||||
* @param Led: LED to be toggled
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED1
|
|
||||||
* @arg LED2
|
|
||||||
* @arg LED3
|
|
||||||
* @arg LED4
|
|
||||||
* @retval HAL status
|
|
||||||
*/
|
|
||||||
int32_t BSP_LED_Toggle(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
|
|
||||||
return BSP_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the status of the LED.
|
|
||||||
* @param Led: LED for which get the status
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED1
|
|
||||||
* @arg LED2
|
|
||||||
* @arg LED3
|
|
||||||
* @arg LED4
|
|
||||||
* @retval HAL status (1=high, 0=low)
|
|
||||||
*/
|
|
||||||
int32_t BSP_LED_GetState(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
return (int32_t)(HAL_GPIO_ReadPin (LED_PORT [Led], LED_PIN [Led]) == GPIO_PIN_RESET);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
static void LED_USER_GPIO_Init(void) {
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(BUS_BSP_LED_GPIO_PORT, BUS_BSP_LED_GPIO_PIN, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : PTPIN */
|
|
||||||
GPIO_InitStruct.Pin = BUS_BSP_LED_GPIO_PIN;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(BUS_BSP_LED_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (USE_BSP_COM_FEATURE > 0)
|
|
||||||
/**
|
|
||||||
* @brief Configures COM port.
|
|
||||||
* @param COM: COM port to be configured.
|
|
||||||
* This parameter can be COM1
|
|
||||||
* @param UART_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)
|
|
||||||
{
|
|
||||||
int32_t ret = BSP_ERROR_NONE;
|
|
||||||
|
|
||||||
if(COM > COMn)
|
|
||||||
{
|
|
||||||
ret = BSP_ERROR_WRONG_PARAM;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hcom_uart[COM].Instance = COM_USART[COM];
|
|
||||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0U)
|
|
||||||
/* Init the UART Msp */
|
|
||||||
LPUART1_MspInit(&hcom_uart[COM]);
|
|
||||||
#else
|
|
||||||
if(IslpUart1MspCbValid == 0U)
|
|
||||||
{
|
|
||||||
if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
|
|
||||||
{
|
|
||||||
return BSP_ERROR_MSP_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (MX_LPUART1_UART_Init(&hcom_uart[COM]))
|
|
||||||
{
|
|
||||||
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 == 0U)
|
|
||||||
LPUART1_MspDeInit(&hcom_uart[COM]);
|
|
||||||
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0U) */
|
|
||||||
|
|
||||||
if(HAL_UART_DeInit(&hcom_uart[COM]) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configures COM port.
|
|
||||||
* @param huart USART handle
|
|
||||||
* 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 HAL error code
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* LPUART1 init function */
|
|
||||||
|
|
||||||
__weak HAL_StatusTypeDef MX_LPUART1_UART_Init(UART_HandleTypeDef* hlpuart)
|
|
||||||
{
|
|
||||||
HAL_StatusTypeDef ret = HAL_OK;
|
|
||||||
|
|
||||||
hlpuart->Instance = LPUART1;
|
|
||||||
hlpuart->Init.BaudRate = 209700;
|
|
||||||
hlpuart->Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
hlpuart->Init.StopBits = UART_STOPBITS_1;
|
|
||||||
hlpuart->Init.Parity = UART_PARITY_NONE;
|
|
||||||
hlpuart->Init.Mode = UART_MODE_TX_RX;
|
|
||||||
hlpuart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
hlpuart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
||||||
hlpuart->Init.ClockPrescaler = UART_PRESCALER_DIV1;
|
|
||||||
hlpuart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
||||||
hlpuart->FifoMode = UART_FIFOMODE_DISABLE;
|
|
||||||
if (HAL_UART_Init(hlpuart) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = HAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_UARTEx_SetTxFifoThreshold(hlpuart, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = HAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_UARTEx_SetRxFifoThreshold(hlpuart, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = HAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_UARTEx_DisableFifoMode(hlpuart) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = HAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
|
||||||
/**
|
|
||||||
* @brief Register Default LPUART1 Bus Msp Callbacks
|
|
||||||
* @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, LPUART1_MspInit) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
|
||||||
}
|
|
||||||
else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, LPUART1_MspDeInit) != HAL_OK)
|
|
||||||
{
|
|
||||||
ret = BSP_ERROR_PERIPH_FAILURE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IslpUart1MspCbValid = 1U;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* BSP status */
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Register LPUART1 Bus Msp Callback registering
|
|
||||||
* @param Callbacks pointer to LPUART1 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
|
|
||||||
{
|
|
||||||
IslpUart1MspCbValid = 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(__CC_ARM) /* For arm compiler 5 */
|
|
||||||
#if !defined(__MICROLIB) /* If not Microlib */
|
|
||||||
|
|
||||||
struct __FILE
|
|
||||||
{
|
|
||||||
int dummyVar; //Just for the sake of redefining __FILE, we won't we using it anyways ;)
|
|
||||||
};
|
|
||||||
|
|
||||||
FILE __stdout;
|
|
||||||
|
|
||||||
#endif /* If not Microlib */
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /* For arm compiler 6 */
|
|
||||||
#if !defined(__MICROLIB) /* If not Microlib */
|
|
||||||
|
|
||||||
FILE __stdout;
|
|
||||||
|
|
||||||
#endif /* If not Microlib */
|
|
||||||
#endif /* For arm compiler 5 */
|
|
||||||
#if defined(__ICCARM__) /* For IAR */
|
|
||||||
size_t __write(int Handle, const unsigned char *Buf, size_t Bufsize)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i=0; i<Bufsize; i++)
|
|
||||||
{
|
|
||||||
(void)HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&Buf[i], 1, COM_POLL_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Bufsize;
|
|
||||||
}
|
|
||||||
#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) /* For ARM Compiler 5 and 6 */
|
|
||||||
int fputc (int ch, FILE *f)
|
|
||||||
{
|
|
||||||
(void)HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&ch, 1, COM_POLL_TIMEOUT);
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
#else /* For GCC Toolchains */
|
|
||||||
int __io_putchar (int ch)
|
|
||||||
{
|
|
||||||
(void)HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&ch, 1, COM_POLL_TIMEOUT);
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
#endif /* For IAR */
|
|
||||||
#endif /* USE_COM_LOG */
|
|
||||||
/**
|
|
||||||
* @brief Initializes LPUART1 MSP.
|
|
||||||
* @param huart LPUART1 handle
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void LPUART1_MspInit(UART_HandleTypeDef* uartHandle)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
|
||||||
/* USER CODE BEGIN LPUART1_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LPUART1_MspInit 0 */
|
|
||||||
|
|
||||||
/** Initializes the peripherals clock
|
|
||||||
*/
|
|
||||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
|
|
||||||
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
|
|
||||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
|
||||||
|
|
||||||
/* Enable Peripheral clock */
|
|
||||||
__HAL_RCC_LPUART1_CLK_ENABLE();
|
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
/**LPUART1 GPIO Configuration
|
|
||||||
PA2 ------> LPUART1_TX
|
|
||||||
PA3 ------> LPUART1_RX
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = BUS_LPUART1_TX_GPIO_PIN;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.Alternate = BUS_LPUART1_TX_GPIO_AF;
|
|
||||||
HAL_GPIO_Init(BUS_LPUART1_TX_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = BUS_LPUART1_RX_GPIO_PIN;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.Alternate = BUS_LPUART1_RX_GPIO_AF;
|
|
||||||
HAL_GPIO_Init(BUS_LPUART1_RX_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LPUART1_MspInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LPUART1_MspInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void LPUART1_MspDeInit(UART_HandleTypeDef* uartHandle)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN LPUART1_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END LPUART1_MspDeInit 0 */
|
|
||||||
/* Peripheral clock disable */
|
|
||||||
__HAL_RCC_LPUART1_CLK_DISABLE();
|
|
||||||
|
|
||||||
/**LPUART1 GPIO Configuration
|
|
||||||
PA2 ------> LPUART1_TX
|
|
||||||
PA3 ------> LPUART1_RX
|
|
||||||
*/
|
|
||||||
HAL_GPIO_DeInit(BUS_LPUART1_TX_GPIO_PORT, BUS_LPUART1_TX_GPIO_PIN);
|
|
||||||
|
|
||||||
HAL_GPIO_DeInit(BUS_LPUART1_RX_GPIO_PORT, BUS_LPUART1_RX_GPIO_PIN);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN LPUART1_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END LPUART1_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
/* USER CODE BEGIN Header */
|
|
||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file : custom.h
|
|
||||||
* @brief : header file for the BSP Common driver
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* Copyright (c) 2022 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 */
|
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
||||||
#ifndef __CUSTOM_H
|
|
||||||
#define __CUSTOM_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "custom_conf.h"
|
|
||||||
#include "custom_errno.h"
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#if (USE_BSP_COM_FEATURE > 0)
|
|
||||||
#if (USE_COM_LOG > 0)
|
|
||||||
#if defined(__ICCARM__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) /* For IAR and ARM Compiler 5 and 6*/
|
|
||||||
#include <stdio.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
/** @addtogroup BSP
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup STM32L4XX_NUCLEO_LOW_LEVEL_Exported_Constants LOW LEVEL Exported Constants
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief STM32WBXX NUCLEO BSP Driver version number V1.0.0
|
|
||||||
*/
|
|
||||||
#define __CUSTOM_BSP_VERSION_MAIN (uint32_t)(0x01) /*!< [31:24] main version */
|
|
||||||
#define __CUSTOM_BSP_VERSION_SUB1 (uint32_t)(0x00) /*!< [23:16] sub1 version */
|
|
||||||
#define __CUSTOM_BSP_VERSION_SUB2 (uint32_t)(0x00) /*!< [15:8] sub2 version */
|
|
||||||
#define __CUSTOM_BSP_VERSION_RC (uint32_t)(0x00) /*!< [7:0] release candidate */
|
|
||||||
#define __CUSTOM_BSP_VERSION ((__CUSTOM_BSP_VERSION_MAIN << 24)\
|
|
||||||
|(__CUSTOM_BSP_VERSION_SUB1 << 16)\
|
|
||||||
|(__CUSTOM_BSP_VERSION_SUB2 << 8 )\
|
|
||||||
|(__CUSTOM_BSP_VERSION_RC))
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Types CUSTOM LOW LEVEL Exported Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Define for CUSTOM board
|
|
||||||
*/
|
|
||||||
#if !defined (USE_CUSTOM)
|
|
||||||
#define USE_CUSTOM
|
|
||||||
#endif
|
|
||||||
#ifndef USE_BSP_COM_FEATURE
|
|
||||||
#define USE_BSP_COM_FEATURE 0U
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_LED CUSTOM LOW LEVEL LED
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/** Define number of LED **/
|
|
||||||
#define LEDn 1U
|
|
||||||
/** Definition for BSP USER LED 2 **/
|
|
||||||
#define LED2_PIN GPIO_PIN_0
|
|
||||||
#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()
|
|
||||||
|
|
||||||
#define BUS_GPIO_INSTANCE GPIO
|
|
||||||
#define BUS_BSP_LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
|
||||||
#define BUS_BSP_LED_GPIO_PORT GPIOB
|
|
||||||
#define BUS_BSP_LED_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
|
||||||
#define BUS_BSP_LED_GPIO_PIN GPIO_PIN_0
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_COM CUSTOM LOW LEVEL COM
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief Definition for COM portx, connected to LPUART1
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define BUS_LPUART1_INSTANCE LPUART1
|
|
||||||
#define BUS_LPUART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
|
||||||
#define BUS_LPUART1_TX_GPIO_AF GPIO_AF8_LPUART1
|
|
||||||
#define BUS_LPUART1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
|
||||||
#define BUS_LPUART1_TX_GPIO_PIN GPIO_PIN_2
|
|
||||||
#define BUS_LPUART1_TX_GPIO_PORT GPIOA
|
|
||||||
#define BUS_LPUART1_RX_GPIO_AF GPIO_AF8_LPUART1
|
|
||||||
#define BUS_LPUART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
|
||||||
#define BUS_LPUART1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
|
||||||
#define BUS_LPUART1_RX_GPIO_PIN GPIO_PIN_3
|
|
||||||
#define BUS_LPUART1_RX_GPIO_PORT GPIOA
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Types LOW LEVEL Exported Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
#ifndef USE_BSP_COM
|
|
||||||
#define USE_BSP_COM 0U
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef USE_COM_LOG
|
|
||||||
#define USE_COM_LOG 1U
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LED2 = 0,
|
|
||||||
LED_GREEN = LED2,
|
|
||||||
}Led_TypeDef;
|
|
||||||
|
|
||||||
#if (USE_BSP_COM_FEATURE > 0)
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
COM1 = 0U,
|
|
||||||
COMn
|
|
||||||
}COM_TypeDef;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
COM_WORDLENGTH_8B = UART_WORDLENGTH_8B,
|
|
||||||
COM_WORDLENGTH_9B = UART_WORDLENGTH_9B,
|
|
||||||
}COM_WordLengthTypeDef;
|
|
||||||
|
|
||||||
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 struct
|
|
||||||
{
|
|
||||||
uint32_t BaudRate;
|
|
||||||
COM_WordLengthTypeDef WordLength;
|
|
||||||
COM_StopBitsTypeDef StopBits;
|
|
||||||
COM_ParityTypeDef Parity;
|
|
||||||
COM_HwFlowCtlTypeDef HwFlowCtl;
|
|
||||||
}COM_InitTypeDef;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MX_UART_InitTypeDef COM_InitTypeDef
|
|
||||||
#define MX_UART_StopBitsTypeDef COM_StopBitsTypeDef
|
|
||||||
#define MX_UART_ParityTypeDef COM_ParityTypeDef
|
|
||||||
#define MX_UART_HwFlowCtlTypeDef COM_HwFlowCtlTypeDef
|
|
||||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
void (* pMspInitCb)(UART_HandleTypeDef *);
|
|
||||||
void (* pMspDeInitCb)(UART_HandleTypeDef *);
|
|
||||||
} BSP_COM_Cb_t;
|
|
||||||
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 1U) */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define COMn 1U
|
|
||||||
#define COM1_UART LPUART1
|
|
||||||
|
|
||||||
#define COM_POLL_TIMEOUT 1000
|
|
||||||
extern UART_HandleTypeDef hcom_uart[COMn];
|
|
||||||
#define hlpuart1 hcom_uart[COM1]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Constants
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup CUSTOM_LOW_LEVEL_Exported_Functions CUSTOM LOW LEVEL Exported Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
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);
|
|
||||||
#if (USE_BSP_COM_FEATURE > 0)
|
|
||||||
int32_t BSP_COM_Init(COM_TypeDef COM);
|
|
||||||
int32_t BSP_COM_DeInit(COM_TypeDef COM);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (USE_COM_LOG > 0)
|
|
||||||
int32_t BSP_COM_SelectLogPort(COM_TypeDef COM);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U)
|
|
||||||
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 */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __CUSTOM__H */
|
|
||||||
|
|
||||||
@@ -21,29 +21,31 @@ Mcu.Name=STM32G070CBTx
|
|||||||
Mcu.Package=LQFP48
|
Mcu.Package=LQFP48
|
||||||
Mcu.Pin0=PF0-OSC_IN (PF0)
|
Mcu.Pin0=PF0-OSC_IN (PF0)
|
||||||
Mcu.Pin1=PF1-OSC_OUT (PF1)
|
Mcu.Pin1=PF1-OSC_OUT (PF1)
|
||||||
Mcu.Pin10=PA13
|
Mcu.Pin10=PA12 [PA10]
|
||||||
Mcu.Pin11=PA14-BOOT0
|
Mcu.Pin11=PA13
|
||||||
Mcu.Pin12=PB4
|
Mcu.Pin12=PA14-BOOT0
|
||||||
Mcu.Pin13=PB5
|
Mcu.Pin13=PB4
|
||||||
Mcu.Pin14=PB6
|
Mcu.Pin14=PB5
|
||||||
Mcu.Pin15=PB7
|
Mcu.Pin15=PB6
|
||||||
Mcu.Pin16=VP_SYS_VS_Systick
|
Mcu.Pin16=PB7
|
||||||
Mcu.Pin17=VP_SYS_VS_DBSignals
|
Mcu.Pin17=VP_SYS_VS_Systick
|
||||||
Mcu.Pin18=VP_TIM3_VS_ClockSourceINT
|
Mcu.Pin18=VP_SYS_VS_DBSignals
|
||||||
|
Mcu.Pin19=VP_TIM3_VS_ClockSourceINT
|
||||||
Mcu.Pin2=PA0
|
Mcu.Pin2=PA0
|
||||||
Mcu.Pin3=PA1
|
Mcu.Pin3=PA1
|
||||||
Mcu.Pin4=PA2
|
Mcu.Pin4=PA2
|
||||||
Mcu.Pin5=PA3
|
Mcu.Pin5=PA3
|
||||||
Mcu.Pin6=PA4
|
Mcu.Pin6=PA4
|
||||||
Mcu.Pin7=PA5
|
Mcu.Pin7=PA5
|
||||||
Mcu.Pin8=PA11 [PA9]
|
Mcu.Pin8=PA8
|
||||||
Mcu.Pin9=PA12 [PA10]
|
Mcu.Pin9=PA11 [PA9]
|
||||||
Mcu.PinsNb=19
|
Mcu.PinsNb=20
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32G070CBTx
|
Mcu.UserName=STM32G070CBTx
|
||||||
MxCube.Version=6.8.0
|
MxCube.Version=6.8.0
|
||||||
MxDb.Version=DB.6.0.80
|
MxDb.Version=DB.6.0.80
|
||||||
|
NVIC.EXTI0_1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.ForceEnableDMAVector=true
|
NVIC.ForceEnableDMAVector=true
|
||||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
@@ -54,8 +56,10 @@ NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
|||||||
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
PA0.Locked=true
|
PA0.Locked=true
|
||||||
PA0.Signal=GPXTI0
|
PA0.Signal=GPXTI0
|
||||||
PA1.GPIOParameters=GPIO_Label
|
PA1.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
|
||||||
PA1.GPIO_Label=GPIO_RESET
|
PA1.GPIO_Label=GPIO_RESET
|
||||||
|
PA1.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING_FALLING
|
||||||
|
PA1.GPIO_PuPd=GPIO_PULLUP
|
||||||
PA1.Locked=true
|
PA1.Locked=true
|
||||||
PA1.Signal=GPXTI1
|
PA1.Signal=GPXTI1
|
||||||
PA11\ [PA9].Locked=true
|
PA11\ [PA9].Locked=true
|
||||||
@@ -80,6 +84,10 @@ PA5.GPIOParameters=GPIO_Label
|
|||||||
PA5.GPIO_Label=READER_EN
|
PA5.GPIO_Label=READER_EN
|
||||||
PA5.Locked=true
|
PA5.Locked=true
|
||||||
PA5.Signal=GPIO_Output
|
PA5.Signal=GPIO_Output
|
||||||
|
PA8.GPIOParameters=GPIO_Label
|
||||||
|
PA8.GPIO_Label=CS_PROXIMITY
|
||||||
|
PA8.Locked=true
|
||||||
|
PA8.Signal=GPIO_Output
|
||||||
PB4.GPIOParameters=GPIO_Label
|
PB4.GPIOParameters=GPIO_Label
|
||||||
PB4.GPIO_Label=CONTROL_PIN
|
PB4.GPIO_Label=CONTROL_PIN
|
||||||
PB4.Locked=true
|
PB4.Locked=true
|
||||||
@@ -125,7 +133,7 @@ ProjectManager.StackSize=0x400
|
|||||||
ProjectManager.TargetToolchain=STM32CubeIDE
|
ProjectManager.TargetToolchain=STM32CubeIDE
|
||||||
ProjectManager.ToolChainLocation=
|
ProjectManager.ToolChainLocation=
|
||||||
ProjectManager.UnderRoot=true
|
ProjectManager.UnderRoot=true
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C2_Init-I2C2-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C2_Init-I2C2-false-HAL-true,4-MX_USART1_UART_Init-USART1-false-HAL-true,5-MX_USART2_UART_Init-USART2-false-HAL-true,6-MX_TIM3_Init-TIM3-false-HAL-true
|
||||||
RCC.ADCFreq_Value=64000000
|
RCC.ADCFreq_Value=64000000
|
||||||
RCC.AHBFreq_Value=64000000
|
RCC.AHBFreq_Value=64000000
|
||||||
RCC.APBFreq_Value=64000000
|
RCC.APBFreq_Value=64000000
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
||||||
#define max_scale 1
|
#define max_scale 3
|
||||||
uint8_t changeScale = 0;
|
uint8_t changeScale = 0;
|
||||||
#define ALLOW_DISABLE_WAF_FROM_BLUE_BUTTON 1
|
#define ALLOW_DISABLE_WAF_FROM_BLUE_BUTTON 1
|
||||||
#define theVL6180Dev 0x52 // what we use as "API device
|
#define theVL6180Dev 0x52 // what we use as "API device
|
||||||
@@ -94,13 +94,6 @@ void vl6180_init (void)
|
|||||||
HAL_Delay(200);
|
HAL_Delay(200);
|
||||||
VL6180_WaitDeviceBooted(theVL6180Dev);
|
VL6180_WaitDeviceBooted(theVL6180Dev);
|
||||||
VL6180_InitData(theVL6180Dev);
|
VL6180_InitData(theVL6180Dev);
|
||||||
allowIT = 1;
|
|
||||||
HAL_GPIO_WritePin(CS_PROXIMITY_GPIO_Port, CS_PROXIMITY_Pin, GPIO_PIN_RESET);
|
|
||||||
HAL_Delay(200);
|
|
||||||
HAL_GPIO_WritePin(CS_PROXIMITY_GPIO_Port, CS_PROXIMITY_Pin, GPIO_PIN_SET);
|
|
||||||
HAL_Delay(200);
|
|
||||||
VL6180_WaitDeviceBooted(theVL6180Dev);
|
|
||||||
VL6180_InitData(theVL6180Dev);
|
|
||||||
State.InitScale=VL6180_UpscaleGetScaling(theVL6180Dev);
|
State.InitScale=VL6180_UpscaleGetScaling(theVL6180Dev);
|
||||||
State.FilterEn=VL6180_FilterGetState(theVL6180Dev);
|
State.FilterEn=VL6180_FilterGetState(theVL6180Dev);
|
||||||
VL6180_Prepare(theVL6180Dev);
|
VL6180_Prepare(theVL6180Dev);
|
||||||
@@ -111,6 +104,7 @@ void vl6180_init (void)
|
|||||||
//VL6180_DMaxSetState(theVL6180Dev, DMaxDispTime>0);
|
//VL6180_DMaxSetState(theVL6180Dev, DMaxDispTime>0);
|
||||||
VL6180_ClearAllInterrupt(theVL6180Dev);
|
VL6180_ClearAllInterrupt(theVL6180Dev);
|
||||||
VL6180_RangeStartContinuousMode(theVL6180Dev);
|
VL6180_RangeStartContinuousMode(theVL6180Dev);
|
||||||
|
allowIT = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,7 +129,6 @@ int VL6180_I2CWrite(VL6180Dev_t addr, uint8_t *buff, uint8_t len){
|
|||||||
|
|
||||||
|
|
||||||
void RangeState(void) {
|
void RangeState(void) {
|
||||||
HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_Pin);
|
|
||||||
int status;
|
int status;
|
||||||
uint16_t hlimit;
|
uint16_t hlimit;
|
||||||
uint8_t scaling;
|
uint8_t scaling;
|
||||||
@@ -159,7 +152,6 @@ void RangeState(void) {
|
|||||||
if (State.OutofRAnge) {
|
if (State.OutofRAnge) {
|
||||||
#if VL6180_HAVE_DMAX_RANGING
|
#if VL6180_HAVE_DMAX_RANGING
|
||||||
if (g_TickCnt - TimeStarted >= ErrRangeDispTime && g_TickCnt - TimeStarted < ErrRangeDispTime + DMaxDispTime ){
|
if (g_TickCnt - TimeStarted >= ErrRangeDispTime && g_TickCnt - TimeStarted < ErrRangeDispTime + DMaxDispTime ){
|
||||||
sprintf(buffer, "d%3d", (int)Range.DMax);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
||||||
@@ -167,7 +159,6 @@ void RangeState(void) {
|
|||||||
if(g_TickCnt - TimeStarted < ErrRangeDispTime )
|
if(g_TickCnt - TimeStarted < ErrRangeDispTime )
|
||||||
{
|
{
|
||||||
|
|
||||||
sprintf(buffer, "rE%2d", (int) Range.errorStatus);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
State.OutofRAnge=0; /* back to out of range display */
|
State.OutofRAnge=0; /* back to out of range display */
|
||||||
@@ -190,7 +181,6 @@ void RangeState(void) {
|
|||||||
State.OutofRAnge = 0;
|
State.OutofRAnge = 0;
|
||||||
TimeStarted = g_TickCnt;
|
TimeStarted = g_TickCnt;
|
||||||
range = (range * alpha + Range.range_mm * ((1 << 16) - alpha)) >> 16;
|
range = (range * alpha + Range.range_mm * ((1 << 16) - alpha)) >> 16;
|
||||||
sprintf(buffer, "r%3d", (int) range);
|
|
||||||
if (State.AutoScale) {
|
if (State.AutoScale) {
|
||||||
if (scaling == 1) {
|
if (scaling == 1) {
|
||||||
buffer[0] = '_';
|
buffer[0] = '_';
|
||||||
@@ -237,9 +227,10 @@ void RangeState(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
uint32_t resetPressedMs = 0;
|
||||||
|
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
|
||||||
{
|
{
|
||||||
if (GPIO_Pin == GPIO_PIN_0)
|
if (GPIO_Pin == GPIO_PIN_0 && allowIT == 1)
|
||||||
{
|
{
|
||||||
RangeState();
|
RangeState();
|
||||||
if (Range.errorStatus == 0)
|
if (Range.errorStatus == 0)
|
||||||
@@ -248,10 +239,24 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||||||
}
|
}
|
||||||
VL6180_ClearAllInterrupt(theVL6180Dev);
|
VL6180_ClearAllInterrupt(theVL6180Dev);
|
||||||
}
|
}
|
||||||
else
|
else if (GPIO_Pin == GPIO_PIN_1)
|
||||||
{
|
{
|
||||||
|
uint32_t res = uwTick - resetPressedMs;
|
||||||
|
if (res > 2000 && resetPressedMs > 0 )
|
||||||
|
HAL_NVIC_SystemReset();
|
||||||
|
resetPressedMs = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (GPIO_Pin == GPIO_PIN_1)
|
||||||
|
{
|
||||||
|
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_RESET)
|
||||||
|
{
|
||||||
|
resetPressedMs = uwTick;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
Reference in New Issue
Block a user