From d55d7f67b65be2a0d4a3d776fc10b6d346524bac Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 15 Oct 2024 17:26:35 +0800 Subject: [PATCH 01/12] more source files --- Core/Inc/stm32wlxx_nucleo.h | 290 ++++++++++++++++ Core/Inc/stm32wlxx_nucleo_bus.h | 139 ++++++++ Core/Inc/stm32wlxx_nucleo_errno.h | 58 ++++ Core/Src/stm32wlxx_nucleo.c | 549 ++++++++++++++++++++++++++++++ Core/Src/stm32wlxx_nucleo_bus.c | 505 +++++++++++++++++++++++++++ STS/TOF/Target/53l8a1_conf.h | 54 +++ 6 files changed, 1595 insertions(+) create mode 100644 Core/Inc/stm32wlxx_nucleo.h create mode 100644 Core/Inc/stm32wlxx_nucleo_bus.h create mode 100644 Core/Inc/stm32wlxx_nucleo_errno.h create mode 100644 Core/Src/stm32wlxx_nucleo.c create mode 100644 Core/Src/stm32wlxx_nucleo_bus.c create mode 100644 STS/TOF/Target/53l8a1_conf.h diff --git a/Core/Inc/stm32wlxx_nucleo.h b/Core/Inc/stm32wlxx_nucleo.h new file mode 100644 index 0000000..5e8a9cc --- /dev/null +++ b/Core/Inc/stm32wlxx_nucleo.h @@ -0,0 +1,290 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : stm32wlxx_nucleo.h + * @brief : header file for the BSP Common driver + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** +*/ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32WLXX_NUCLEO_H +#define __STM32WLXX_NUCLEO_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32wlxx_nucleo_conf.h" +#include "stm32wlxx_nucleo_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 + #endif + #endif +#endif +/** @addtogroup BSP + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL + * @{ + */ + +/** @defgroup STM32L4XX_NUCLEO_LOW_LEVEL_Exported_Constants LOW LEVEL Exported Constants + * @{ + */ +/** + * @brief STM32WLXX NUCLEO BSP Driver version number V1.0.0 + */ +#define __STM32WLXX_NUCLEO_BSP_VERSION_MAIN (uint32_t)(0x01) /*!< [31:24] main version */ +#define __STM32WLXX_NUCLEO_BSP_VERSION_SUB1 (uint32_t)(0x00) /*!< [23:16] sub1 version */ +#define __STM32WLXX_NUCLEO_BSP_VERSION_SUB2 (uint32_t)(0x00) /*!< [15:8] sub2 version */ +#define __STM32WLXX_NUCLEO_BSP_VERSION_RC (uint32_t)(0x00) /*!< [7:0] release candidate */ +#define __STM32WLXX_NUCLEO_BSP_VERSION ((__STM32WLXX_NUCLEO_BSP_VERSION_MAIN << 24)\ + |(__STM32WLXX_NUCLEO_BSP_VERSION_SUB1 << 16)\ + |(__STM32WLXX_NUCLEO_BSP_VERSION_SUB2 << 8 )\ + |(__STM32WLXX_NUCLEO_BSP_VERSION_RC)) + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Exported_Types STM32WLXX_NUCLEO LOW LEVEL Exported Types + * @{ + */ + + /** + * @brief Define for STM32WLXX_NUCLEO board + */ +#if !defined (USE_STM32WLXX_NUCLEO) + #define USE_STM32WLXX_NUCLEO +#endif +#ifndef USE_BSP_COM_FEATURE + #define USE_BSP_COM_FEATURE 0U +#endif + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_BUTTON STM32WLXX_NUCLEO LOW LEVEL BUTTON + * @{ + */ +/* Button state */ +#define BUTTON_RELEASED 0U +#define BUTTON_PRESSED 1U +/** Define number of BUTTON **/ +#define BUTTONn 1U + +/** + * @brief User push-button + */ + /** Definition for BSP USER BUTTON **/ + +#define USER_BUTTON_PIN GPIO_PIN_0 +#define USER_BUTTON_GPIO_PORT GPIOA +#define USER_BUTTON_EXTI_IRQn EXTI0_IRQn +#define USER_BUTTON_EXTI_LINE EXTI_LINE_0 +#define H_EXTI_0 hpb_exti[BUTTON_USER] +/** + * @} + */ +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_COM STM32WLXX_NUCLEO LOW LEVEL COM + * @{ + */ +/** + * @brief Definition for COM portx, connected to USART1 + */ + +#define BUS_USART1_INSTANCE USART1 +#define BUS_USART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() +#define BUS_USART1_RX_GPIO_PORT GPIOB +#define BUS_USART1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() +#define BUS_USART1_RX_GPIO_PIN GPIO_PIN_7 +#define BUS_USART1_RX_GPIO_AF GPIO_AF7_USART1 +#define BUS_USART1_TX_GPIO_PIN GPIO_PIN_6 +#define BUS_USART1_TX_GPIO_PORT GPIOB +#define BUS_USART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() +#define BUS_USART1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE() +#define BUS_USART1_TX_GPIO_AF GPIO_AF7_USART1 + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_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 + +#ifndef BSP_BUTTON_USER_IT_PRIORITY + #define BSP_BUTTON_USER_IT_PRIORITY 15U +#endif + +typedef enum +{ + BUTTON_USER = 0U, +}Button_TypeDef; + +/* Keep compatibility with CMSIS Pack already delivered */ +#define BUTTON_KEY BUTTON_USER + +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_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 USART1 + +#define COM_POLL_TIMEOUT 1000 +extern UART_HandleTypeDef hcom_uart[COMn]; +#define huart1 hcom_uart[COM1] + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Constants + * @{ + */ +extern EXTI_HandleTypeDef hpb_exti[BUTTONn]; +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Exported_Functions STM32WLXX_NUCLEO LOW LEVEL Exported Functions + * @{ + */ + +int32_t BSP_GetVersion(void); +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_Callback(Button_TypeDef Button); +void BSP_PB_IRQHandler (Button_TypeDef Button); +#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 /* __STM32WLXX_NUCLEO__H */ + diff --git a/Core/Inc/stm32wlxx_nucleo_bus.h b/Core/Inc/stm32wlxx_nucleo_bus.h new file mode 100644 index 0000000..753ac45 --- /dev/null +++ b/Core/Inc/stm32wlxx_nucleo_bus.h @@ -0,0 +1,139 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : stm32wlxx_nucleo_bus.h + * @brief : header file for the BSP BUS IO driver + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** +*/ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32WLXX_NUCLEO_BUS_H +#define STM32WLXX_NUCLEO_BUS_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32wlxx_nucleo_conf.h" +#include "stm32wlxx_nucleo_errno.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup STM32WLXX_NUCLEO + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS STM32WLXX_NUCLEO BUS + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS_Exported_Constants STM32WLXX_NUCLEO BUS Exported Constants + * @{ + */ + +#define BUS_I2C2_INSTANCE I2C2 +#define BUS_I2C2_SCL_GPIO_AF GPIO_AF4_I2C2 +#define BUS_I2C2_SCL_GPIO_PORT GPIOA +#define BUS_I2C2_SCL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() +#define BUS_I2C2_SCL_GPIO_PIN GPIO_PIN_12 +#define BUS_I2C2_SCL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define BUS_I2C2_SDA_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE() +#define BUS_I2C2_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() +#define BUS_I2C2_SDA_GPIO_PORT GPIOA +#define BUS_I2C2_SDA_GPIO_PIN GPIO_PIN_11 +#define BUS_I2C2_SDA_GPIO_AF GPIO_AF4_I2C2 + +#ifndef BUS_I2C2_POLL_TIMEOUT + #define BUS_I2C2_POLL_TIMEOUT 0x1000U +#endif +/* I2C2 Frequeny in Hz */ +#ifndef BUS_I2C2_FREQUENCY + #define BUS_I2C2_FREQUENCY 1000000U /* Frequency of I2Cn = 100 KHz*/ +#endif + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS_Private_Types STM32WLXX_NUCLEO BUS Private types + * @{ + */ +#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) +typedef struct +{ + pI2C_CallbackTypeDef pMspInitCb; + pI2C_CallbackTypeDef pMspDeInitCb; +}BSP_I2C_Cb_t; +#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) */ +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Constants + * @{ + */ + +extern I2C_HandleTypeDef hi2c2; + +/** + * @} + */ + +/** @addtogroup STM32WLXX_NUCLEO_BUS_Exported_Functions + * @{ + */ + +/* BUS IO driver over I2C Peripheral */ +HAL_StatusTypeDef MX_I2C2_Init(I2C_HandleTypeDef* hi2c); +int32_t BSP_I2C2_Init(void); +int32_t BSP_I2C2_DeInit(void); +int32_t BSP_I2C2_IsReady(uint16_t DevAddr, uint32_t Trials); +int32_t BSP_I2C2_WriteReg(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length); +int32_t BSP_I2C2_ReadReg(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length); +int32_t BSP_I2C2_WriteReg16(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length); +int32_t BSP_I2C2_ReadReg16(uint16_t Addr, uint16_t Reg, uint8_t *pData, uint16_t Length); +int32_t BSP_I2C2_Send(uint16_t DevAddr, uint8_t *pData, uint16_t Length); +int32_t BSP_I2C2_Recv(uint16_t DevAddr, uint8_t *pData, uint16_t Length); +int32_t BSP_I2C2_SendRecv(uint16_t DevAddr, uint8_t *pTxdata, uint8_t *pRxdata, uint16_t Length); +#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) +int32_t BSP_I2C2_RegisterDefaultMspCallbacks (void); +int32_t BSP_I2C2_RegisterMspCallbacks (BSP_I2C_Cb_t *Callbacks); +#endif /* (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) */ + +int32_t BSP_GetTick(void); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif /* STM32WLXX_NUCLEO_BUS_H */ + diff --git a/Core/Inc/stm32wlxx_nucleo_errno.h b/Core/Inc/stm32wlxx_nucleo_errno.h new file mode 100644 index 0000000..d9ac416 --- /dev/null +++ b/Core/Inc/stm32wlxx_nucleo_errno.h @@ -0,0 +1,58 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : stm32wlxx_nucleo_errno.h + * @brief : Error Code + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** +*/ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32WLXX_NUCLEO_ERRNO_H +#define STM32WLXX_NUCLEO_ERRNO_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* BSP 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 + +/* BSP BUS error codes */ + +#define BSP_ERROR_BUS_TRANSACTION_FAILURE -100 +#define BSP_ERROR_BUS_ARBITRATION_LOSS -101 +#define BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE -102 +#define BSP_ERROR_BUS_PROTOCOL_FAILURE -103 + +#define BSP_ERROR_BUS_MODE_FAULT -104 +#define BSP_ERROR_BUS_FRAME_ERROR -105 +#define BSP_ERROR_BUS_CRC_ERROR -106 +#define BSP_ERROR_BUS_DMA_FAILURE -107 + +#ifdef __cplusplus +} +#endif +#endif /*STM32WLXX_NUCLEO_ERRNO_H */ + diff --git a/Core/Src/stm32wlxx_nucleo.c b/Core/Src/stm32wlxx_nucleo.c new file mode 100644 index 0000000..eb48886 --- /dev/null +++ b/Core/Src/stm32wlxx_nucleo.c @@ -0,0 +1,549 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : stm32wlxx_nucleo.c + * @brief : Source file for the BSP Common driver + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** +*/ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32wlxx_nucleo.h" +#include "stm32wlxx_hal_exti.h" + +/** @defgroup BSP BSP + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO STM32WLXX_NUCLEO + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL STM32WLXX_NUCLEO LOW LEVEL + * @brief This file provides set of firmware functions to manage Leds and push-button + * available on STM32WLxx-Nucleo Kit from STMicroelectronics. + * @{ + */ + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Private_Defines STM32WLXX_NUCLEO LOW LEVEL Private Defines + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_FunctionPrototypes STM32WLXX_NUCLEO LOW LEVEL Private Function Prototypes + * @{ + */ +typedef void (* BSP_EXTI_LineCallback) (void); +typedef void (* BSP_BUTTON_GPIO_Init) (void); + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Private_Variables STM32WLXX_NUCLEO LOW LEVEL Private Variables + * @{ + */ + +static GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT}; +static const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN}; +static const IRQn_Type BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn}; +EXTI_HandleTypeDef hpb_exti[BUTTONn] = {{.Line = EXTI_LINE_0}}; +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 IsUsart1MspCbValid = 0; +#endif +__weak HAL_StatusTypeDef MX_USART1_UART_Init(UART_HandleTypeDef* huart); +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Private_Functions STM32WLXX_NUCLEO LOW LEVEL Private Functions + * @{ + */ +static void BUTTON_USER_EXTI_Callback(void); +static void BUTTON_USER_GPIO_Init(void); +#if (USE_BSP_COM_FEATURE > 0) +static void USART1_MspInit(UART_HandleTypeDef *huart); +static void USART1_MspDeInit(UART_HandleTypeDef *huart); +#endif +/** + * @brief This method returns the STM32WLxx NUCLEO BSP Driver revision + * @retval version: 0xXYZR (8bits for each decimal, R for RC) + */ +int32_t BSP_GetVersion(void) +{ + return (int32_t)__STM32WLXX_NUCLEO_BSP_VERSION; +} + +/** + * @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: User 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 + * @retval BSP status + */ +int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) +{ + int32_t ret = BSP_ERROR_NONE; + + static const BSP_EXTI_LineCallback ButtonCallback[BUTTONn] ={BUTTON_USER_EXTI_Callback}; + static const uint32_t BSP_BUTTON_PRIO [BUTTONn] ={BSP_BUTTON_USER_IT_PRIORITY}; + static const uint32_t BUTTON_EXTI_LINE[BUTTONn] ={USER_BUTTON_EXTI_LINE}; + static const BSP_BUTTON_GPIO_Init ButtonGpioInit[BUTTONn] = {BUTTON_USER_GPIO_Init}; + + ButtonGpioInit[Button](); + + if (ButtonMode == BUTTON_MODE_EXTI) + { + if(HAL_EXTI_GetHandle(&hpb_exti[Button], BUTTON_EXTI_LINE[Button]) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else if (HAL_EXTI_RegisterCallback(&hpb_exti[Button], HAL_EXTI_COMMON_CB_ID, ButtonCallback[Button]) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else + { + /* 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 ret; +} + +/** + * @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 + * @retval BSP status + */ +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 addressed + * This parameter can be one of the following values: + * @arg BUTTON_USER + * @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]) == GPIO_PIN_RESET); +} + +/** + * @brief User EXTI line detection callbacks. + * @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. */ +} + +/** + * @brief User EXTI line detection callbacks. + * @retval None + */ +static void BUTTON_USER_EXTI_Callback(void) +{ + BSP_PB_Callback(BUTTON_USER); +} + +/** + * @brief + * @retval None + */ +static void BUTTON_USER_GPIO_Init(void) { +} + +#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 */ + USART1_MspInit(&hcom_uart[COM]); +#else + if(IsUsart1MspCbValid == 0U) + { + if(BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE) + { + return BSP_ERROR_MSP_FAILURE; + } + } +#endif + if (MX_USART1_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) + USART1_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 + */ + +/* USART1 init function */ + +__weak HAL_StatusTypeDef MX_USART1_UART_Init(UART_HandleTypeDef* huart) +{ + HAL_StatusTypeDef ret = HAL_OK; + + huart->Instance = USART1; + huart->Init.BaudRate = 115200; + huart->Init.WordLength = UART_WORDLENGTH_8B; + huart->Init.StopBits = UART_STOPBITS_1; + huart->Init.Parity = UART_PARITY_NONE; + huart->Init.Mode = UART_MODE_TX_RX; + huart->Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart->Init.OverSampling = UART_OVERSAMPLING_16; + huart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart->Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(huart) != HAL_OK) + { + ret = HAL_ERROR; + } + + if (HAL_UARTEx_SetTxFifoThreshold(huart, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + ret = HAL_ERROR; + } + + if (HAL_UARTEx_SetRxFifoThreshold(huart, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + ret = HAL_ERROR; + } + + if (HAL_UARTEx_DisableFifoMode(huart) != HAL_OK) + { + ret = HAL_ERROR; + } + + return ret; +} + +#endif +#if (USE_HAL_UART_REGISTER_CALLBACKS == 1U) +/** + * @brief Register Default USART1 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, USART1_MspInit) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else if(HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, USART1_MspDeInit) != HAL_OK) + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + else + { + IsUsart1MspCbValid = 1U; + } + } + + /* BSP status */ + return ret; +} + +/** + * @brief Register USART1 Bus Msp Callback registering + * @param Callbacks pointer to USART1 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 + { + IsUsart1MspCbValid = 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= 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 USART1 MSP. + * @param huart USART1 handle + * @retval None + */ + +static void USART1_MspInit(UART_HandleTypeDef* uartHandle) +{ + GPIO_InitTypeDef GPIO_InitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; + /* USER CODE BEGIN USART1_MspInit 0 */ + + /* USER CODE END USART1_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1; + PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + + /* Enable Peripheral clock */ + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**USART1 GPIO Configuration + PB7 ------> USART1_RX + PB6 ------> USART1_TX + */ + GPIO_InitStruct.Pin = BUS_USART1_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_USART1_RX_GPIO_AF; + HAL_GPIO_Init(BUS_USART1_RX_GPIO_PORT, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = BUS_USART1_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_USART1_TX_GPIO_AF; + HAL_GPIO_Init(BUS_USART1_TX_GPIO_PORT, &GPIO_InitStruct); + + /* USER CODE BEGIN USART1_MspInit 1 */ + + /* USER CODE END USART1_MspInit 1 */ +} + +static void USART1_MspDeInit(UART_HandleTypeDef* uartHandle) +{ + /* USER CODE BEGIN USART1_MspDeInit 0 */ + + /* USER CODE END USART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART1_CLK_DISABLE(); + + /**USART1 GPIO Configuration + PB7 ------> USART1_RX + PB6 ------> USART1_TX + */ + HAL_GPIO_DeInit(BUS_USART1_RX_GPIO_PORT, BUS_USART1_RX_GPIO_PIN); + + HAL_GPIO_DeInit(BUS_USART1_TX_GPIO_PORT, BUS_USART1_TX_GPIO_PIN); + + /* USER CODE BEGIN USART1_MspDeInit 1 */ + + /* USER CODE END USART1_MspDeInit 1 */ +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/Core/Src/stm32wlxx_nucleo_bus.c b/Core/Src/stm32wlxx_nucleo_bus.c new file mode 100644 index 0000000..751b22b --- /dev/null +++ b/Core/Src/stm32wlxx_nucleo_bus.c @@ -0,0 +1,505 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : stm32wlxx_nucleo_bus.c + * @brief : source file for the BSP BUS IO driver + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** +*/ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32wlxx_nucleo_bus.h" + +__weak HAL_StatusTypeDef MX_I2C2_Init(I2C_HandleTypeDef* hi2c); + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup STM32WLXX_NUCLEO + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS STM32WLXX_NUCLEO BUS + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS_Exported_Variables BUS Exported Variables + * @{ + */ + +extern I2C_HandleTypeDef hi2c2; +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS_Private_Variables BUS Private Variables + * @{ + */ + +#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) +static uint32_t IsI2C2MspCbValid = 0; +#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */ +static uint32_t I2C2InitCounter = 0; + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS_Private_FunctionPrototypes BUS Private Function + * @{ + */ + +static void I2C2_MspInit(I2C_HandleTypeDef* hI2c); +static void I2C2_MspDeInit(I2C_HandleTypeDef* hI2c); +#if (USE_CUBEMX_BSP_V2 == 1) +static uint32_t I2C_GetTiming(uint32_t clock_src_hz, uint32_t i2cfreq_hz); +static void Compute_PRESC_SCLDEL_SDADEL(uint32_t clock_src_freq, uint32_t I2C_Speed); +static uint32_t Compute_SCLL_SCLH (uint32_t clock_src_freq, uint32_t I2C_speed); +#endif + +/** + * @} + */ + +/** @defgroup STM32WLXX_NUCLEO_LOW_LEVEL_Private_Functions STM32WLXX_NUCLEO LOW LEVEL Private Functions + * @{ + */ + +/** @defgroup STM32WLXX_NUCLEO_BUS_Exported_Functions STM32WLXX_NUCLEO_BUS Exported Functions + * @{ + */ + +/* BUS IO driver over I2C Peripheral */ +/******************************************************************************* + BUS OPERATIONS OVER I2C +*******************************************************************************/ +/** + * @brief Initialize I2C HAL + * @retval BSP status + */ +int32_t BSP_I2C2_Init(void) +{ + + int32_t ret = BSP_ERROR_NONE; + + hi2c2.Instance = I2C2; + + if(I2C2InitCounter++ == 0) + { + if (HAL_I2C_GetState(&hi2c2) == HAL_I2C_STATE_RESET) + { + #if (USE_HAL_I2C_REGISTER_CALLBACKS == 0U) + /* Init the I2C Msp */ + I2C2_MspInit(&hi2c2); + #else + if(IsI2C2MspCbValid == 0U) + { + if(BSP_I2C2_RegisterDefaultMspCallbacks() != BSP_ERROR_NONE) + { + return BSP_ERROR_MSP_FAILURE; + } + } + #endif + if(ret == BSP_ERROR_NONE) + { + /* Init the I2C */ + if(MX_I2C2_Init(&hi2c2) != HAL_OK) + { + ret = BSP_ERROR_BUS_FAILURE; + } + else if(HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK) + { + ret = BSP_ERROR_BUS_FAILURE; + } + else + { + ret = BSP_ERROR_NONE; + } + } + } + } + return ret; +} + +/** + * @brief DeInitialize I2C HAL. + * @retval BSP status + */ +int32_t BSP_I2C2_DeInit(void) +{ + int32_t ret = BSP_ERROR_NONE; + + if (I2C2InitCounter > 0) + { + if (--I2C2InitCounter == 0) + { + #if (USE_HAL_I2C_REGISTER_CALLBACKS == 0U) + /* DeInit the I2C */ + I2C2_MspDeInit(&hi2c2); + #endif + /* DeInit the I2C */ + if (HAL_I2C_DeInit(&hi2c2) != HAL_OK) + { + ret = BSP_ERROR_BUS_FAILURE; + } + } + } + return ret; +} + +/** + * @brief Check whether the I2C bus is ready. + * @param DevAddr : I2C device address + * @param Trials : Check trials number + * @retval BSP status + */ +int32_t BSP_I2C2_IsReady(uint16_t DevAddr, uint32_t Trials) +{ + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_IsDeviceReady(&hi2c2, DevAddr, Trials, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + ret = BSP_ERROR_BUSY; + } + + return ret; +} + +/** + * @brief Write a value in a register of the device through BUS. + * @param DevAddr Device address on Bus. + * @param Reg The target register address to write + * @param pData Pointer to data buffer to write + * @param Length Data Length + * @retval BSP status + */ + +int32_t BSP_I2C2_WriteReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) +{ + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_Mem_Write(&hi2c2, DevAddr,Reg, I2C_MEMADD_SIZE_8BIT,pData, Length, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + if (HAL_I2C_GetError(&hi2c2) == HAL_I2C_ERROR_AF) + { + ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE; + } + else + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + return ret; +} + +/** + * @brief Read a register of the device through BUS + * @param DevAddr Device address on Bus. + * @param Reg The target register address to read + * @param pData Pointer to data buffer to read + * @param Length Data Length + * @retval BSP status + */ +int32_t BSP_I2C2_ReadReg(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) +{ + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_Mem_Read(&hi2c2, DevAddr, Reg, I2C_MEMADD_SIZE_8BIT, pData, Length, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + if (HAL_I2C_GetError(&hi2c2) == HAL_I2C_ERROR_AF) + { + ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE; + } + else + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + return ret; +} + +/** + + * @brief Write a value in a register of the device through BUS. + * @param DevAddr Device address on Bus. + * @param Reg The target register address to write + + * @param pData Pointer to data buffer to write + * @param Length Data Length + * @retval BSP statu + */ +int32_t BSP_I2C2_WriteReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) +{ + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_Mem_Write(&hi2c2, DevAddr, Reg, I2C_MEMADD_SIZE_16BIT, pData, Length, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + if (HAL_I2C_GetError(&hi2c2) == HAL_I2C_ERROR_AF) + { + ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE; + } + else + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + return ret; +} + +/** + * @brief Read registers through a bus (16 bits) + * @param DevAddr: Device address on BUS + * @param Reg: The target register address to read + * @param Length Data Length + * @retval BSP status + */ +int32_t BSP_I2C2_ReadReg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length) +{ + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_Mem_Read(&hi2c2, DevAddr, Reg, I2C_MEMADD_SIZE_16BIT, pData, Length, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + if (HAL_I2C_GetError(&hi2c2) != HAL_I2C_ERROR_AF) + { + ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE; + } + else + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + return ret; +} + +/** + * @brief Send an amount width data through bus (Simplex) + * @param DevAddr: Device address on Bus. + * @param pData: Data pointer + * @param Length: Data length + * @retval BSP status + */ +int32_t BSP_I2C2_Send(uint16_t DevAddr, uint8_t *pData, uint16_t Length) { + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_Master_Transmit(&hi2c2, DevAddr, pData, Length, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + if (HAL_I2C_GetError(&hi2c2) != HAL_I2C_ERROR_AF) + { + ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE; + } + else + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + + return ret; +} + +/** + * @brief Receive an amount of data through a bus (Simplex) + * @param DevAddr: Device address on Bus. + * @param pData: Data pointer + * @param Length: Data length + * @retval BSP status + */ +int32_t BSP_I2C2_Recv(uint16_t DevAddr, uint8_t *pData, uint16_t Length) { + int32_t ret = BSP_ERROR_NONE; + + if (HAL_I2C_Master_Receive(&hi2c2, DevAddr, pData, Length, BUS_I2C2_POLL_TIMEOUT) != HAL_OK) + { + if (HAL_I2C_GetError(&hi2c2) != HAL_I2C_ERROR_AF) + { + ret = BSP_ERROR_BUS_ACKNOWLEDGE_FAILURE; + } + else + { + ret = BSP_ERROR_PERIPH_FAILURE; + } + } + return ret; +} + +#if (USE_HAL_I2C_REGISTER_CALLBACKS == 1U) +/** + * @brief Register Default BSP I2C2 Bus Msp Callbacks + * @retval BSP status + */ +int32_t BSP_I2C2_RegisterDefaultMspCallbacks (void) +{ + + __HAL_I2C_RESET_HANDLE_STATE(&hi2c2); + + /* Register MspInit Callback */ + if (HAL_I2C_RegisterCallback(&hi2c2, HAL_I2C_MSPINIT_CB_ID, I2C2_MspInit) != HAL_OK) + { + return BSP_ERROR_PERIPH_FAILURE; + } + + /* Register MspDeInit Callback */ + if (HAL_I2C_RegisterCallback(&hi2c2, HAL_I2C_MSPDEINIT_CB_ID, I2C2_MspDeInit) != HAL_OK) + { + return BSP_ERROR_PERIPH_FAILURE; + } + IsI2C2MspCbValid = 1; + + return BSP_ERROR_NONE; +} + +/** + * @brief BSP I2C2 Bus Msp Callback registering + * @param Callbacks pointer to I2C2 MspInit/MspDeInit callback functions + * @retval BSP status + */ +int32_t BSP_I2C2_RegisterMspCallbacks (BSP_I2C_Cb_t *Callbacks) +{ + /* Prevent unused argument(s) compilation warning */ + __HAL_I2C_RESET_HANDLE_STATE(&hi2c2); + + /* Register MspInit Callback */ + if (HAL_I2C_RegisterCallback(&hi2c2, HAL_I2C_MSPINIT_CB_ID, Callbacks->pMspInitCb) != HAL_OK) + { + return BSP_ERROR_PERIPH_FAILURE; + } + + /* Register MspDeInit Callback */ + if (HAL_I2C_RegisterCallback(&hi2c2, HAL_I2C_MSPDEINIT_CB_ID, Callbacks->pMspDeInitCb) != HAL_OK) + { + return BSP_ERROR_PERIPH_FAILURE; + } + + IsI2C2MspCbValid = 1; + + return BSP_ERROR_NONE; +} +#endif /* USE_HAL_I2C_REGISTER_CALLBACKS */ + +/** + * @brief Return system tick in ms + * @retval Current HAL time base time stamp + */ +int32_t BSP_GetTick(void) { + return HAL_GetTick(); +} + +/* I2C2 init function */ + +__weak HAL_StatusTypeDef MX_I2C2_Init(I2C_HandleTypeDef* hi2c) +{ + HAL_StatusTypeDef ret = HAL_OK; + + hi2c->Instance = I2C2; + hi2c->Init.Timing = 0x20303E5D; + hi2c->Init.OwnAddress1 = 0; + hi2c->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + hi2c->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; + hi2c->Init.OwnAddress2 = 0; + hi2c->Init.OwnAddress2Masks = I2C_OA2_NOMASK; + hi2c->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; + hi2c->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; + if (HAL_I2C_Init(hi2c) != HAL_OK) + { + ret = HAL_ERROR; + } + + if (HAL_I2CEx_ConfigAnalogFilter(hi2c, I2C_ANALOGFILTER_ENABLE) != HAL_OK) + { + ret = HAL_ERROR; + } + + if (HAL_I2CEx_ConfigDigitalFilter(hi2c, 0) != HAL_OK) + { + ret = HAL_ERROR; + } + + return ret; +} + +static void I2C2_MspInit(I2C_HandleTypeDef* i2cHandle) +{ + GPIO_InitTypeDef GPIO_InitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; + /* USER CODE BEGIN I2C2_MspInit 0 */ + + /* USER CODE END I2C2_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C2; + PeriphClkInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**I2C2 GPIO Configuration + PA12 ------> I2C2_SCL + PA15 ------> I2C2_SDA + */ + GPIO_InitStruct.Pin = BUS_I2C2_SCL_GPIO_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = BUS_I2C2_SCL_GPIO_AF; + HAL_GPIO_Init(BUS_I2C2_SCL_GPIO_PORT, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = BUS_I2C2_SDA_GPIO_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = BUS_I2C2_SDA_GPIO_AF; + HAL_GPIO_Init(BUS_I2C2_SDA_GPIO_PORT, &GPIO_InitStruct); + + /* Peripheral clock enable */ + __HAL_RCC_I2C2_CLK_ENABLE(); + /* USER CODE BEGIN I2C2_MspInit 1 */ + + /* USER CODE END I2C2_MspInit 1 */ +} + +static void I2C2_MspDeInit(I2C_HandleTypeDef* i2cHandle) +{ + /* USER CODE BEGIN I2C2_MspDeInit 0 */ + + /* USER CODE END I2C2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_I2C2_CLK_DISABLE(); + + /**I2C2 GPIO Configuration + PA12 ------> I2C2_SCL + PA11 ------> I2C2_SDA + */ + HAL_GPIO_DeInit(BUS_I2C2_SCL_GPIO_PORT, BUS_I2C2_SCL_GPIO_PIN); + + HAL_GPIO_DeInit(BUS_I2C2_SDA_GPIO_PORT, BUS_I2C2_SDA_GPIO_PIN); + + /* USER CODE BEGIN I2C2_MspDeInit 1 */ + + /* USER CODE END I2C2_MspDeInit 1 */ +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/STS/TOF/Target/53l8a1_conf.h b/STS/TOF/Target/53l8a1_conf.h new file mode 100644 index 0000000..5aed1d5 --- /dev/null +++ b/STS/TOF/Target/53l8a1_conf.h @@ -0,0 +1,54 @@ +/** + ****************************************************************************** + * @file 53l8a1_conf.h + * @author IMG SW Application Team + * @brief This file contains definitions for the ToF components bus interfaces + * when using the X-NUCLEO-53L8A1 expansion board + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +#include "stm32wlxx_hal.h" +#include "stm32wlxx_nucleo_bus.h" +#include "stm32wlxx_nucleo.h" +#include "stm32wlxx_nucleo_errno.h" + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef VL53L8A1_CONF_H +#define VL53L8A1_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/* + * the 53L8A1 BSP driver uses this symbol to allocate a structure for each device + * if you are only using the on-board sensor without break-out boards + * change its to (1U) in order to save space in RAM memory + */ +#define RANGING_SENSOR_INSTANCES_NBR (3) //(3U) + +#define VL53L8A1_I2C_INIT BSP_I2C2_Init +#define VL53L8A1_I2C_DEINIT BSP_I2C2_DeInit +#define VL53L8A1_I2C_WRITEREG BSP_I2C2_WriteReg16 +#define VL53L8A1_I2C_READREG BSP_I2C2_ReadReg16 +#define VL53L8A1_GETTICK BSP_GetTick + +#ifdef __cplusplus +} +#endif + +#endif /* VL53L8A1_CONF_H*/ From 2af97fcb7d3d502ec4a959da1afa40261f36497b Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 15 Oct 2024 17:38:33 +0800 Subject: [PATCH 02/12] updated i2c timing for L8 --- Core/Inc/main.h | 19 ++++++++++++++++++- Core/Src/i2c.c | 2 +- STS/Core/Inc/yunhorn_sts_prd_conf.h | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 9bdeeec..d870785 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -213,18 +213,35 @@ void Error_Handler(void); #endif -#ifdef STM32WLE5xx + #define I2C2_SCL_PIN GPIO_PIN_12 #define I2C2_SDA_PIN GPIO_PIN_11 #define I2C2_SCL_PORT GPIOA #define I2C2_SDA_PORT GPIOA // FOR STM32WLE5CCU6 UFQFPN48 PA12 PA11 +#ifndef STM32WLE5xx #define I2C2_STANDARD_100K 0x00000E14 #define I2C2_FAST_400K 0x00000004 #define I2C2_FAST_PLUS_1M 0x00000000 #endif +/* + * FOR STM32WLE5CCU6 UFQFPN48 PA12 PA11 + * +#define I2C2_STANDARD_100K 0x00000E14 +#define I2C2_FAST_400K 0x00000004 +#define I2C2_FAST_PLUS_1M 0x00000000 +*/ + +/* + * FOR STM32WL55JCIX UFBGA73 PA12 PA11 + */ + +#define I2C2_STANDARD_100K 0x10805D88 +#define I2C2_FAST_400K 0x0090194B +#define I2C2_FAST_PLUS_1M 0x00700814 + #if defined(STS_R4) /* IF_SOAP_IN, MEMS_IF_3, PA10 */ #define SOAP_STATUS_Pin GPIO_PIN_10 diff --git a/Core/Src/i2c.c b/Core/Src/i2c.c index 679baa3..6d4c951 100644 --- a/Core/Src/i2c.c +++ b/Core/Src/i2c.c @@ -43,7 +43,7 @@ void MX_I2C2_Init(void) /* USER CODE END I2C2_Init 1 */ hi2c2.Instance = I2C2; - hi2c2.Init.Timing = I2C2_STANDARD_100K; //I2C2_FAST_400K; + hi2c2.Init.Timing = I2C2_FAST_PLUS_1M; hi2c2.Init.OwnAddress1 = 0; hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; diff --git a/STS/Core/Inc/yunhorn_sts_prd_conf.h b/STS/Core/Inc/yunhorn_sts_prd_conf.h index 3ab47c6..4d1b42e 100644 --- a/STS/Core/Inc/yunhorn_sts_prd_conf.h +++ b/STS/Core/Inc/yunhorn_sts_prd_conf.h @@ -39,8 +39,8 @@ * MODULE SELECTION */ //#define USE_OLED_SSD1306 -#define STS_USE_TOF_VL53L1X -#define STS_USE_TOF_VL53L0X 1U +//#define STS_USE_TOF_VL53L1X +//#define STS_USE_TOF_VL53L0X 1U #ifdef STS_R1 /* STS R1 for single roll */ #define YUNHORN_STS_R1_ENABLED 1U From 2716d737ce4f1a5c1f92951d389acde273d01635 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 15 Oct 2024 20:14:18 +0800 Subject: [PATCH 03/12] wip for period check center distance --- Core/Inc/utilities_def.h | 2 +- Core/Src/main.c | 8 ++-- LoRaWAN/App/lora_app.c | 20 ++++++++-- STS/Core/Src/yunhorn_sts_process.c | 7 ++-- STS/TOF/App/app_tof.c | 60 +++++++++++++++++++++++++----- 5 files changed, 76 insertions(+), 21 deletions(-) diff --git a/Core/Inc/utilities_def.h b/Core/Inc/utilities_def.h index 32a810d..16c631e 100644 --- a/Core/Inc/utilities_def.h +++ b/Core/Inc/utilities_def.h @@ -92,7 +92,7 @@ typedef enum #if defined(STS_R1)||defined(STS_R1D)||defined(STS_R5)||defined(STS_R2) CFG_SEQ_Task_YunhornSTSEventP4, /* TOF RANGE */ #endif -#if defined(STS_P2)||defined(STS_T6) +#if defined(STS_P2)||defined(STS_T6)||defined(L8) CFG_SEQ_Task_YunhornSTSEventP5, /* TOF IN-OUT */ #endif #ifdef STS_R4 diff --git a/Core/Src/main.c b/Core/Src/main.c index 0d59c2d..e6b23b1 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -103,20 +103,22 @@ int main(void) MX_GPIO_Init(); MX_I2C2_Init(); - //MX_DMA_Init(); + MX_DMA_Init(); MX_LoRaWAN_Init(); /* USER CODE BEGIN 2 */ MX_USART2_UART_Init(); /* USER CODE END 2 */ - //MX_TOF_Init(); + /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ - MX_TOF_Process(); + MX_LoRaWAN_Process(); + //MX_TOF_Process(); + // MX_TOF_Ranging_Process(); /* USER CODE BEGIN 3 */ } diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 2a6c8ef..52be86c 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -518,7 +518,7 @@ void LoRaWAN_Init(void) #endif -#if defined(STS_P2)||defined(STS_T6) +#if defined(STS_P2)||defined(STS_T6)||defined(L8) UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process); @@ -532,8 +532,8 @@ void LoRaWAN_Init(void) UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), UTIL_SEQ_RFU, STS_YunhornSTSEventP4_Process); #endif -#if defined(STS_P2)||defined(STS_T6) - UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL); +#if defined(STS_P2)||defined(STS_T6)||defined(L8) + UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_ONESHOT, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); #endif @@ -841,6 +841,9 @@ static void SendTxData(void) AppData.Port = YUNHORN_STS_P2_LORA_APP_DATA_PORT; /* STS-P2 Data Port */ #elif defined(STS_T6) AppData.Port = YUNHORN_STS_T6_LORA_APP_DATA_PORT; /* STS-T6 Data Port */ +#elif defined(L8) + AppData.Port = YUNHORN_STS_L8_LORA_APP_DATA_PORT; /* STS-L8 Data Port */ + #endif #ifdef CAYENNE_LPP @@ -954,6 +957,14 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)((sts_t6_sensor_data.tof_range_presence_state & 0xFF)); #endif //STS_T6 + +#if defined(L8) + AppData.Buffer[i++] = 1; + AppData.Buffer[i++] = 8; //testing + //(uint8_t)((sts_l8_sensor_data.tof_range_presence_state & 0xFF)); + +#endif //STS_T6 + /* STS-R4 SOAP LEVEL SENSOR */ #ifdef STS_R4 AppData.Buffer[i++] = 2; @@ -1105,6 +1116,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams) APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:JOIN | DR:%d | PWR:%d\r\n", joinParams->Datarate, joinParams->TxPower); } + UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); /* USER CODE END OnJoinRequest_1 */ } @@ -1470,7 +1482,7 @@ void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) /* USER CODE BEGIN PrFD_YunhornSTSWakeUpScanTimerEvents */ static void OnYunhornSTSWakeUpScanTimerEvent(void *context) { -#if defined(STS_P2)||defined(STS_T6) +#if defined(STS_P2)||defined(STS_T6)||defined(L8) UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), CFG_SEQ_Prio_0); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index d1b477e..11253fa 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -112,7 +112,7 @@ volatile uint8_t sts_work_mode=4; volatile uint32_t rfac_timer=0; volatile uint16_t sts_sensor_install_height=3000; volatile uint8_t sensor_data_ready=0; -volatile uint32_t STS_TOFScanPeriod_msec=250, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; +volatile uint32_t STS_TOFScanPeriod_msec=5000, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; static uint8_t outbuf[128]={0x0}; extern volatile hmac_result_t hmac_result; extern uint16_t sensor_id; @@ -434,7 +434,8 @@ void STS_YunhornSTSEventP5_Process(void) } #elif defined(L8) //STS_TOF_VL53L8X_Process(); - MX_TOF_Process(); + //MX_TOF_Process(); + MX_TOF_Ranging_Process(); #endif } @@ -1686,7 +1687,7 @@ void STS_SENSOR_Distance_Test_Process(void) APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor Function Test: Distance Measured =%u mm\r\n", (int)sts_distance_rss_distance); #endif -#if defined(VL53LX) +#if defined(VL53LX)||defined(L8) //MX_TOF_Init(); //MX_TOF_Process(); sts_sensor_install_height = (uint16_t)MX_TOF_Ranging_Process(); diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 7b689ee..ef6d542 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -113,6 +113,7 @@ void MX_TOF_Init(void) //STS_TOF_VL53LX_PeopleCounting_Process(); #ifdef L8 MX_53L8A1_ThresholdDetection_Init(); + MX_53L8A1_ThresholdDetection_Process(); #endif /* USER CODE BEGIN TOF_Init_PostTreatment */ @@ -133,6 +134,26 @@ uint16_t MX_TOF_Ranging_Process(void) STS_TOF_VL53LX_Range_Process(range_mode, &range_distance); APP_LOG(TS_OFF, VLEVEL_M, "\n VL53L1 Range distance =%u mm \n\r", (uint16_t)range_distance); + return (uint16_t) range_distance; +#elif defined(L8) + uint16_t range_distance=0; + uint8_t center_roi[4] = {27,28,35,36}; + uint8_t range_mode = 2; //STS_TOF_LONG_RANGE; + int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result); +#if 1 + for (uint8_t zone_nbr = 0; zone_nbr < 4; zone_nbr++) + { + /* Print distance and status */ + if (Result.ZoneResult[center_roi[zone_nbr]].NumberOfTargets > 0) + printf("\n\r%2d distance = %4d mm status =%2d\n\r",center_roi[zone_nbr], + (long)Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1], + (long)Result.ZoneResult[center_roi[zone_nbr]].Status[RANGING_SENSOR_NB_TARGET_PER_ZONE-1]); + range_distance += Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1]; + } +#endif + range_distance /=4; + APP_LOG(TS_OFF, VLEVEL_M, "\n VL53L1 Range distance =%u mm \n\r", (uint16_t)range_distance); + return (uint16_t) range_distance; #endif @@ -150,16 +171,34 @@ void MX_TOF_Process(void) //sts_tof_vl53lx_peoplecount_subprocess(); #ifdef L8 - MX_53L8A1_ThresholdDetection_Process(); + //MX_53L8A1_ThresholdDetection_Process(); + STS_TOF_L8_Process(); #endif /* USER CODE BEGIN TOF_Process_PostTreatment */ /* USER CODE END TOF_Process_PostTreatment */ } - - #ifdef L8 +void STS_TOF_L8_Process(void) +{ + //while (1) + { + /* interrupt mode */ + if (ToF_EventDetected != 0) + { + ToF_EventDetected = 0; + + status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result); + + if (status == BSP_ERROR_NONE) + { + //print_result(&Result); + } + } + } +} + /* VL53L8A1 */ static void MX_53L8A1_ThresholdDetection_Init(void) { @@ -184,7 +223,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void) if (status != BSP_ERROR_NONE) { printf("VL53L8A1_RANGING_SENSOR_Init failed\n"); - while (1); + //while (1); } printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n"); } @@ -227,8 +266,8 @@ static void MX_53L8A1_ThresholdDetection_Process(void) printf("-------------------------------------------\n\r"); printf("please put a target between %d and %d millimeters from the sensor\n\r", LOW_THRESHOLD, HIGH_THRESHOLD); - - while (1) +#if 0 + //while (1) { /* interrupt mode */ if (ToF_EventDetected != 0) @@ -243,6 +282,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void) } } } +#endif } static void print_result(RANGING_SENSOR_Result_t *Result) @@ -266,7 +306,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result) printf(" \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status\r"); if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0)) { - printf(" %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]"); + printf(" %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]\r"); } } @@ -282,7 +322,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result) for (i = 0; i < zones_per_line; i++) { - printf("| "); + printf("| "); } printf("|\n"); @@ -292,8 +332,8 @@ static void print_result(RANGING_SENSOR_Result_t *Result) for (k = (zones_per_line - 1); k >= 0; k--) { if (Result->ZoneResult[j + k].NumberOfTargets > 0) - printf("| \033[38;5;10m%5ld\033[0m : %5ld ", - (long)Result->ZoneResult[j + k].Distance[l], + printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", + (long)Result->ZoneResult[j + k].Distance[l],(j+k), (long)Result->ZoneResult[j + k].Status[l]); else printf("| %5s : %5s ", "X", "X"); From 353deb7e48ba54d3fd494cdc7c59fe0c32bfaa3e Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Wed, 16 Oct 2024 12:06:16 +0800 Subject: [PATCH 04/12] refine output format for average measure --- STS/TOF/App/app_tof.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index ef6d542..0444d62 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -140,19 +140,29 @@ uint16_t MX_TOF_Ranging_Process(void) uint8_t center_roi[4] = {27,28,35,36}; uint8_t range_mode = 2; //STS_TOF_LONG_RANGE; int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result); -#if 1 + + printf("\r| 27 | 28 | 35 | 36 |\r\n"); + for (uint8_t zone_nbr = 0; zone_nbr < 4; zone_nbr++) { /* Print distance and status */ if (Result.ZoneResult[center_roi[zone_nbr]].NumberOfTargets > 0) - printf("\n\r%2d distance = %4d mm status =%2d\n\r",center_roi[zone_nbr], + { + printf("| %04ld %2ld", (long)Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1], (long)Result.ZoneResult[center_roi[zone_nbr]].Status[RANGING_SENSOR_NB_TARGET_PER_ZONE-1]); + } + else { + printf("| -- "); + } + range_distance += Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1]; + } -#endif + //printf("\n\r"); + range_distance /=4; - APP_LOG(TS_OFF, VLEVEL_M, "\n VL53L1 Range distance =%u mm \n\r", (uint16_t)range_distance); + printf("| %u mm\r\n", (uint16_t)range_distance); return (uint16_t) range_distance; #endif From 61b28d1e28d5eb8060943f7261ff5c17e0c9e32a Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Wed, 16 Oct 2024 13:06:08 +0800 Subject: [PATCH 05/12] ---- enable RF on WL55JC_DEV_BOARD with WLE5CC startup firmware --- Core/Inc/platform.h | 4 ++-- LoRaWAN/Target/radio_board_if.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Core/Inc/platform.h b/Core/Inc/platform.h index 6bb9bf9..1f78fbb 100644 --- a/Core/Inc/platform.h +++ b/Core/Inc/platform.h @@ -28,9 +28,9 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ -//#define USE_BSP_DRIVER +#define USE_BSP_DRIVER /* USER CODE BEGIN EC */ -#define YUNHORN_STS_WLE5CCxx 1 +//#define YUNHORN_STS_WLE5CCxx 1 /* USER CODE END EC */ /* Includes ------------------------------------------------------------------*/ diff --git a/LoRaWAN/Target/radio_board_if.h b/LoRaWAN/Target/radio_board_if.h index 187e0d4..09d8e4d 100644 --- a/LoRaWAN/Target/radio_board_if.h +++ b/LoRaWAN/Target/radio_board_if.h @@ -151,6 +151,12 @@ typedef enum RBI_SWITCH_RFO_LP = RADIO_SWITCH_RFO_LP, RBI_SWITCH_RFO_HP = RADIO_SWITCH_RFO_HP, } RBI_Switch_TypeDef; +typedef enum +{ + RBI_RFO_LP_MAXPOWER = 0, + RBI_RFO_HP_MAXPOWER = 1, +} RBI_RFOMaxPowerConfig_TypeDef; + #elif defined(YUNHORN_STS_WLE5CCxx) typedef enum { From d90d66eda88c5c4f8d5a7d8c5d8b4eddbd072510 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 17 Oct 2024 11:23:50 +0800 Subject: [PATCH 06/12] --- start fall state detection ALG --- STS/Core/Src/yunhorn_sts_process.c | 4 ++-- STS/TOF/App/app_tof.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index 11253fa..ecc98e4 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -434,8 +434,8 @@ void STS_YunhornSTSEventP5_Process(void) } #elif defined(L8) //STS_TOF_VL53L8X_Process(); - //MX_TOF_Process(); - MX_TOF_Ranging_Process(); + MX_TOF_Process(); + //MX_TOF_Ranging_Process(); #endif } diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 0444d62..e07ff24 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -203,7 +203,7 @@ void STS_TOF_L8_Process(void) if (status == BSP_ERROR_NONE) { - //print_result(&Result); + print_result(&Result); } } } @@ -276,7 +276,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void) printf("-------------------------------------------\n\r"); printf("please put a target between %d and %d millimeters from the sensor\n\r", LOW_THRESHOLD, HIGH_THRESHOLD); -#if 0 +#if 1 //while (1) { /* interrupt mode */ From be7ff4a7461e84a678e6591f14c631dec2d5d7ab Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Fri, 18 Oct 2024 19:19:05 +0800 Subject: [PATCH 07/12] wip add motion indicator --- LoRaWAN/App/lora_app.c | 2 +- STS/Core/Src/yunhorn_sts_process.c | 2 +- STS/TOF/App/app_tof.c | 65 ++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 52be86c..c95b6da 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -419,7 +419,7 @@ void LoRaWAN_Init(void) uint32_t feature_version = 0UL; /* USER CODE END LoRaWAN_Init_LV */ - APP_LOG(TS_OFF, VLEVEL_M, "\n\n# YUNHORN SMARTOILETS: (%s) MTM:%d.%d HWFW:%d.%d V:%d.%d.%d #\n\n",(char*)YUNHORN_STS_PRD_STRING, + APP_LOG(TS_OFF, VLEVEL_M, "\n\r# YUNHORN SMARTOILETS: (%s) MTM:%d.%d HWFW:%d.%d V:%d.%d.%d #\n\r",(char*)YUNHORN_STS_PRD_STRING, (uint8_t)sts_mtmcode1, (uint8_t)sts_mtmcode2,(uint8_t)sts_hardware_ver,(uint8_t)FirmwareVersion, (uint8_t)MajorVer,(uint8_t)MinorVer,(uint8_t)SubMinorVer); /* USER CODE BEGIN LoRaWAN_Init_1 */ diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index ecc98e4..8b7907c 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -112,7 +112,7 @@ volatile uint8_t sts_work_mode=4; volatile uint32_t rfac_timer=0; volatile uint16_t sts_sensor_install_height=3000; volatile uint8_t sensor_data_ready=0; -volatile uint32_t STS_TOFScanPeriod_msec=5000, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; +volatile uint32_t STS_TOFScanPeriod_msec=500, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; static uint8_t outbuf[128]={0x0}; extern volatile hmac_result_t hmac_result; extern uint16_t sensor_id; diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index e07ff24..55fad50 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -69,13 +69,15 @@ extern "C" { #ifdef L8 /* for VL53L8A1 */ #define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */ -#define LOW_THRESHOLD (200U) -#define HIGH_THRESHOLD (600U) +#define LOW_THRESHOLD (2000U) +#define HIGH_THRESHOLD (2600U) /* Private variables ---------------------------------------------------------*/ static RANGING_SENSOR_Capabilities_t Cap; static RANGING_SENSOR_ProfileConfig_t Profile; static RANGING_SENSOR_Result_t Result; +static VL53L8CX_ResultsData L8CXResult; +static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ static void MX_53L8A1_ThresholdDetection_Init(void); static void MX_53L8A1_ThresholdDetection_Process(void); @@ -235,7 +237,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void) printf("VL53L8A1_RANGING_SENSOR_Init failed\n"); //while (1); } - printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n"); + } static void MX_53L8A1_ThresholdDetection_Process(void) @@ -263,6 +265,37 @@ static void MX_53L8A1_ThresholdDetection_Process(void) VL53L8A1_RANGING_SENSOR_ConfigIT(VL53L8A1_DEV_CENTER, &ITConfig); + + // L8CX Motion + + /*********************************/ + /* Program motion indicator */ + /*********************************/ + + /* Create motion indicator with resolution 8x8 */ + int status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + if(status) + { + printf("Motion indicator init failed with status : %u\n", status); + return status; + } + + /* (Optional) Change the min and max distance used to detect motions. The + * difference between min and max must never be >1500mm, and minimum never be <400mm, + * otherwise the function below returns error 127 */ + status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000); + if(status) + { + printf("Motion indicator set distance motion failed with status : %u\n", status); + return status; + } + + /* If user want to change the resolution, he also needs to update the motion indicator resolution */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + + // L8 Motion + status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS); if (status != BSP_ERROR_NONE) @@ -308,9 +341,9 @@ static void print_result(RANGING_SENSOR_Result_t *Result) printf("%c[2H", 27); /* clear screen */ printf("53L8A1 Threshold Detection demo application\n\r"); - printf("-------------------------------------------\n\n\r"); - - printf("Cell Format :\n\n\r"); + printf("-------------------------------------------"); + printf("-------- Low= %4d High= %4d ------------", LOW_THRESHOLD, HIGH_THRESHOLD); + printf("Cell Format :"); for (l = 0; l < RANGING_SENSOR_NB_TARGET_PER_ZONE; l++) { printf(" \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status\r"); @@ -342,11 +375,29 @@ static void print_result(RANGING_SENSOR_Result_t *Result) for (k = (zones_per_line - 1); k >= 0; k--) { if (Result->ZoneResult[j + k].NumberOfTargets > 0) + { + /* ---- origin printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", (long)Result->ZoneResult[j + k].Distance[l],(j+k), (long)Result->ZoneResult[j + k].Status[l]); + */ + int32_t roi_distance =(uint32_t)(Result->ZoneResult[j + k].Distance[l]); + int16_t roi_low = (roi_distance - LOW_THRESHOLD)/10; + int16_t roi_high = (HIGH_THRESHOLD - roi_distance)/10; + + if ((roi_low> 0)&&(roi_high>0)) + { + //printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", (uint32_t)(roi_distance-LOW_THRESHOLD), (j+k), (uint32_t)Result->ZoneResult[j + k].Status[l]); + printf("| \033[38;5;10m%5d\033[0m : ", (uint16_t)roi_low); + } + else if ((roi_low< 0)|| (roi_high<0)) + { + //printf("| \033[38;5;10m%5s\033[0m :%2d%5ld ", ".",(j+k), (uint32_t)Result->ZoneResult[j + k].Status[l]); + printf("| \033[38;5;10m%5s\033[0m : ", "."); + } + } else - printf("| %5s : %5s ", "X", "X"); + printf("| %5s : %5s ", ".", "."); } printf("|\n"); From 015101d76edd3c3215d764cc67f073f5e122c0e2 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Oct 2024 18:08:53 +0800 Subject: [PATCH 08/12] start of L8M --- LoRaWAN/App/lora_app.c | 2 +- README.md | 1 + .../User/STS/TOF/App_l1cb/Src/subdir.mk | 9 ++++ .../User/STS/TOF/vl53l1cb/modules/subdir.mk | 9 ++++ .../User/STS/TOF/vl53l1cb/porting/subdir.mk | 9 ++++ .../User/STS/TOF/vl53l1cb/subdir.mk | 9 ++++ .../Release/Drivers/BSP/53L8A1/subdir.mk | 27 ++++++++++ .../Release/Drivers/BSP/Components/subdir.mk | 52 +++++++++++++++++++ STS/TOF/App/app_tof.c | 4 +- 9 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 STM32CubeIDE/Release/Application/User/STS/TOF/App_l1cb/Src/subdir.mk create mode 100644 STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/modules/subdir.mk create mode 100644 STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/porting/subdir.mk create mode 100644 STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/subdir.mk create mode 100644 STM32CubeIDE/Release/Drivers/BSP/53L8A1/subdir.mk create mode 100644 STM32CubeIDE/Release/Drivers/BSP/Components/subdir.mk diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index c95b6da..a9a61f0 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -50,7 +50,7 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm; extern volatile uint32_t rfac_timer; extern volatile uint32_t STS_TOFScanPeriod_msec, STS_TxPeriod_sec, STS_HeartBeatTimerPeriod_sec; volatile uint8_t sts_data_buf[LORAWAN_APP_DATA_BUFFER_MAX_SIZE]={0x0}; -volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; +//volatile LmHandlerAppData_t sts_app_data={ 0, 0, sts_data_buf }; /* USER CODE END EV */ diff --git a/README.md b/README.md index f81cc4b..6669d88 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,4 @@ 2024 09 20 START RR 2024 09 25 START R1D 2024 09 27 GOOD STS-R4 on single board RM2_1 + 2024 10 24 START L8M with workable L8 diff --git a/STM32CubeIDE/Release/Application/User/STS/TOF/App_l1cb/Src/subdir.mk b/STM32CubeIDE/Release/Application/User/STS/TOF/App_l1cb/Src/subdir.mk new file mode 100644 index 0000000..acbe69a --- /dev/null +++ b/STM32CubeIDE/Release/Application/User/STS/TOF/App_l1cb/Src/subdir.mk @@ -0,0 +1,9 @@ +################################################################################ +# Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (12.3.rel1) +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables + +# Each subdirectory must supply rules for building sources it contributes + diff --git a/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/modules/subdir.mk b/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/modules/subdir.mk new file mode 100644 index 0000000..acbe69a --- /dev/null +++ b/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/modules/subdir.mk @@ -0,0 +1,9 @@ +################################################################################ +# Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (12.3.rel1) +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables + +# Each subdirectory must supply rules for building sources it contributes + diff --git a/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/porting/subdir.mk b/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/porting/subdir.mk new file mode 100644 index 0000000..acbe69a --- /dev/null +++ b/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/porting/subdir.mk @@ -0,0 +1,9 @@ +################################################################################ +# Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (12.3.rel1) +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables + +# Each subdirectory must supply rules for building sources it contributes + diff --git a/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/subdir.mk b/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/subdir.mk new file mode 100644 index 0000000..acbe69a --- /dev/null +++ b/STM32CubeIDE/Release/Application/User/STS/TOF/vl53l1cb/subdir.mk @@ -0,0 +1,9 @@ +################################################################################ +# Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (12.3.rel1) +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables + +# Each subdirectory must supply rules for building sources it contributes + diff --git a/STM32CubeIDE/Release/Drivers/BSP/53L8A1/subdir.mk b/STM32CubeIDE/Release/Drivers/BSP/53L8A1/subdir.mk new file mode 100644 index 0000000..5e87a83 --- /dev/null +++ b/STM32CubeIDE/Release/Drivers/BSP/53L8A1/subdir.mk @@ -0,0 +1,27 @@ +################################################################################ +# Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (12.3.rel1) +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/53L8A1/53l8a1_ranging_sensor.c + +OBJS += \ +./Drivers/BSP/53L8A1/53l8a1_ranging_sensor.o + +C_DEPS += \ +./Drivers/BSP/53L8A1/53l8a1_ranging_sensor.d + + +# Each subdirectory must supply rules for building sources it contributes +Drivers/BSP/53L8A1/53l8a1_ranging_sensor.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/53L8A1/53l8a1_ranging_sensor.c Drivers/BSP/53L8A1/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" + +clean: clean-Drivers-2f-BSP-2f-53L8A1 + +clean-Drivers-2f-BSP-2f-53L8A1: + -$(RM) ./Drivers/BSP/53L8A1/53l8a1_ranging_sensor.cyclo ./Drivers/BSP/53L8A1/53l8a1_ranging_sensor.d ./Drivers/BSP/53L8A1/53l8a1_ranging_sensor.o ./Drivers/BSP/53L8A1/53l8a1_ranging_sensor.su + +.PHONY: clean-Drivers-2f-BSP-2f-53L8A1 + diff --git a/STM32CubeIDE/Release/Drivers/BSP/Components/subdir.mk b/STM32CubeIDE/Release/Drivers/BSP/Components/subdir.mk new file mode 100644 index 0000000..81bdd0e --- /dev/null +++ b/STM32CubeIDE/Release/Drivers/BSP/Components/subdir.mk @@ -0,0 +1,52 @@ +################################################################################ +# Automatically-generated file. Do not edit! +# Toolchain: GNU Tools for STM32 (12.3.rel1) +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/vl53l8cx.c \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_api.c \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_plugin_detection_thresholds.c \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_plugin_motion_indicator.c \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_plugin_xtalk.c \ +D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/porting/wle5cc_platform.c + +OBJS += \ +./Drivers/BSP/Components/vl53l8cx.o \ +./Drivers/BSP/Components/vl53l8cx_api.o \ +./Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.o \ +./Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.o \ +./Drivers/BSP/Components/vl53l8cx_plugin_xtalk.o \ +./Drivers/BSP/Components/wle5cc_platform.o + +C_DEPS += \ +./Drivers/BSP/Components/vl53l8cx.d \ +./Drivers/BSP/Components/vl53l8cx_api.d \ +./Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.d \ +./Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.d \ +./Drivers/BSP/Components/vl53l8cx_plugin_xtalk.d \ +./Drivers/BSP/Components/wle5cc_platform.d + + +# Each subdirectory must supply rules for building sources it contributes +Drivers/BSP/Components/vl53l8cx.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/vl53l8cx.c Drivers/BSP/Components/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" +Drivers/BSP/Components/vl53l8cx_api.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_api.c Drivers/BSP/Components/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" +Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_plugin_detection_thresholds.c Drivers/BSP/Components/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" +Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_plugin_motion_indicator.c Drivers/BSP/Components/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" +Drivers/BSP/Components/vl53l8cx_plugin_xtalk.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/modules/vl53l8cx_plugin_xtalk.c Drivers/BSP/Components/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" +Drivers/BSP/Components/wle5cc_platform.o: D:/ONEDRIVE/STM32WLV13/Drivers/BSP/Components/vl53l8cx/porting/wle5cc_platform.c Drivers/BSP/Components/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DL8 -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WLE5xx -c -I../../Core/Inc -I../../STS/Core/Inc -I../../STS/TOF/App -I../../STS/TOF/Target -I../../STS/TOF/vl53l1x_uld -I../../STS/TOF/vl53l0x -I../../LoRaWAN/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Middlewares/ST/STM32_Cryptographic/include -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" + +clean: clean-Drivers-2f-BSP-2f-Components + +clean-Drivers-2f-BSP-2f-Components: + -$(RM) ./Drivers/BSP/Components/vl53l8cx.cyclo ./Drivers/BSP/Components/vl53l8cx.d ./Drivers/BSP/Components/vl53l8cx.o ./Drivers/BSP/Components/vl53l8cx.su ./Drivers/BSP/Components/vl53l8cx_api.cyclo ./Drivers/BSP/Components/vl53l8cx_api.d ./Drivers/BSP/Components/vl53l8cx_api.o ./Drivers/BSP/Components/vl53l8cx_api.su ./Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.cyclo ./Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.d ./Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.o ./Drivers/BSP/Components/vl53l8cx_plugin_detection_thresholds.su ./Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.cyclo ./Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.d ./Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.o ./Drivers/BSP/Components/vl53l8cx_plugin_motion_indicator.su ./Drivers/BSP/Components/vl53l8cx_plugin_xtalk.cyclo ./Drivers/BSP/Components/vl53l8cx_plugin_xtalk.d ./Drivers/BSP/Components/vl53l8cx_plugin_xtalk.o ./Drivers/BSP/Components/vl53l8cx_plugin_xtalk.su ./Drivers/BSP/Components/wle5cc_platform.cyclo ./Drivers/BSP/Components/wle5cc_platform.d ./Drivers/BSP/Components/wle5cc_platform.o ./Drivers/BSP/Components/wle5cc_platform.su + +.PHONY: clean-Drivers-2f-BSP-2f-Components + diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 55fad50..5a60fee 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -267,7 +267,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void) // L8CX Motion - +#if 0 /*********************************/ /* Program motion indicator */ /*********************************/ @@ -295,7 +295,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void) status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); // L8 Motion - +#endif status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS); if (status != BSP_ERROR_NONE) From e60db68969e1ac9241b121039fc056fc757a332a Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Oct 2024 22:39:31 +0800 Subject: [PATCH 09/12] wip, not shown any print --- Core/Src/main.c | 5 +- Core/Src/sys_app.c | 2 +- Core/Src/usart_if.c | 2 +- STS/TOF/App/app_tof.c | 464 +++++++++++++++++++++++++++++++++++++++++- STS/TOF/App/app_tof.h | 4 +- 5 files changed, 466 insertions(+), 11 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index e6b23b1..21f8504 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -109,13 +109,14 @@ int main(void) /* USER CODE BEGIN 2 */ MX_USART2_UART_Init(); /* USER CODE END 2 */ - + example11_init(); + example11_process(); /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ - + example11(); MX_LoRaWAN_Process(); //MX_TOF_Process(); // MX_TOF_Ranging_Process(); diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c index 182c229..88f209f 100644 --- a/Core/Src/sys_app.c +++ b/Core/Src/sys_app.c @@ -123,7 +123,7 @@ void SystemApp_Init(void) /*Initialize the Sensors */ EnvSensors_Init(); #if defined(L8) - MX_TOF_Init(); + //MX_TOF_Init(); #endif #if defined(STS_P2) STS_TOF_VL53LX_PeopleCounting_Process_Init(); diff --git a/Core/Src/usart_if.c b/Core/Src/usart_if.c index 9f0331e..8ac0e4a 100644 --- a/Core/Src/usart_if.c +++ b/Core/Src/usart_if.c @@ -127,7 +127,7 @@ UTIL_ADV_TRACE_Status_t vcom_DeInit(void) /* ##-3- Disable the NVIC for DMA ########################################### */ /* USER CODE BEGIN 1 */ - HAL_NVIC_DisableIRQ(DMA1_Channel5_IRQn); + HAL_NVIC_DisableIRQ(DMA1_Channel6_IRQn); return UTIL_ADV_TRACE_OK; /* USER CODE END 1 */ diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 5a60fee..47a149f 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -36,7 +36,7 @@ extern "C" { #include "app_tof_pin_conf.h" #endif #include "stm32wlxx_nucleo.h" - +int example11(void); /* Private typedef -----------------------------------------------------------*/ /* * The application is to showcase the threshold detection @@ -76,8 +76,8 @@ extern "C" { static RANGING_SENSOR_Capabilities_t Cap; static RANGING_SENSOR_ProfileConfig_t Profile; static RANGING_SENSOR_Result_t Result; -static VL53L8CX_ResultsData L8CXResult; -static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ +//static VL53L8CX_ResultsData L8CXResult; +//static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ static void MX_53L8A1_ThresholdDetection_Init(void); static void MX_53L8A1_ThresholdDetection_Process(void); @@ -114,8 +114,9 @@ void MX_TOF_Init(void) //MX_53L1A2_SimpleRanging_Init(); //STS_TOF_VL53LX_PeopleCounting_Process(); #ifdef L8 - MX_53L8A1_ThresholdDetection_Init(); - MX_53L8A1_ThresholdDetection_Process(); + //MX_53L8A1_ThresholdDetection_Init(); + //MX_53L8A1_ThresholdDetection_Process(); + example11_init(); #endif /* USER CODE BEGIN TOF_Init_PostTreatment */ @@ -184,7 +185,8 @@ void MX_TOF_Process(void) //sts_tof_vl53lx_peoplecount_subprocess(); #ifdef L8 //MX_53L8A1_ThresholdDetection_Process(); - STS_TOF_L8_Process(); + //STS_TOF_L8_Process(); + example11_process(); #endif /* USER CODE BEGIN TOF_Process_PostTreatment */ @@ -210,6 +212,19 @@ void STS_TOF_L8_Process(void) } } } +void STS_Reset_Sensor(void) +{ +/* Sensor reset */ + HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_RESET); + HAL_Delay(2); + HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET); + HAL_Delay(2); + + HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_RESET); + HAL_Delay(2); + HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET); + HAL_Delay(2); +} /* VL53L8A1 */ static void MX_53L8A1_ThresholdDetection_Init(void) @@ -655,6 +670,443 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps) #endif } #endif +/* + * L8M + */ + +/************************************************************/ +/* VL53LMZ ULD motion indicator with detection thresholds */ +/************************************************************/ +/* +* This example shows how to use the motion indicator with detection threshold. +* This kind of configuration might be used for user detection applications. +* To use this example, user needs to be sure that macro +* VL53LMZ_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h). +*/ + +#include +#include +#include +#include "vl53l8cx_api.h" +#include "vl53l8cx_plugin_motion_indicator.h" +#include "vl53l8cx_plugin_detection_thresholds.h" + +VL53L8CX_Configuration Dev; /* Sensor configuration */ +VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ +VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ + +// #define UNUSED(x) (void)(x) + +/* This function needs to be filled by the customer. It allows knowing when + * the VL53LMZ interrupt is raised on GPIO1. This is the only way to use detection thresholds. + */ +/* +int WaitForL5Interrupt(VL53LMZ_Configuration * pDev) { + + //Add your implementation here ... + UNUSED(pDev); + + return 0; +} +*/ +//extern int WaitForL5Interrupt(VL53LMZ_Configuration * pDev); +//extern int IntCount; + +int example11(void) +{ + + /*********************************/ + /* VL53LMZ ranging variables */ + /*********************************/ + + uint8_t status, loop, isAlive, isReady, i; +#if 0 + VL53L8CX_Configuration Dev; /* Sensor configuration */ + VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ + VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ +#endif + + /*********************************/ + /* Customer platform */ + /*********************************/ + + /* Fill the platform structure with customer's implementation. For this + * example, only the I2C address is used. + */ + Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; + + /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ + //Reset_Sensor(&(Dev.platform)); + + /* (Optional) Set a new I2C address if the wanted address is different + * from the default one (filled with 0x20 for this example). + */ + //status = vl53lmz_set_i2c_address(&Dev, 0x20); + + + /*********************************/ + /* Power on sensor and init */ + /*********************************/ +#if 0 + /* (Optional) Check if there is a VL53LMZ sensor connected */ + status = vl53lmz_is_alive(&Dev, &isAlive); + if(!isAlive || status) + { + printf("VL53LMZ not detected at requested address\n"); + return status; + } +#endif + /* (Mandatory) Init VL53LMZ sensor */ + status = vl53l8cx_init(&Dev); + if(status) + { + printf("VL53LMZ ULD Loading failed\n"); + return status; + } + + //printf("VL53LMZ ULD ready ! (Version : %s)\n", + // VL53LMZ_API_REVISION); + + + /*********************************/ + /* Program motion indicator */ + /*********************************/ + + /* Create motion indicator with resolution 8x8 */ + status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + if(status) + { + printf("Motion indicator init failed with status : %u\n", status); + //return status; + } + + /* (Optional) Change the min and max distance used to detect motions. The + * difference between min and max must never be >1500mm, and minimum never be <400mm, + * otherwise the function below returns error 127 */ + //status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000); + status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 2000, 2600); + if(status) + { + printf("Motion indicator set distance motion failed with status : %u\n", status); + //return status; + } + + /* If user want to change the resolution, he also needs to update the motion indicator resolution */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + + + /* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS); + status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10); + status = vl53l8cx_set_integration_time_ms(&Dev, 10); + + + /*********************************/ + /* Program detection thresholds */ + /*********************************/ + + /* In this example, we want 1 thresholds per zone for a 8x8 resolution */ + /* Create array of thresholds (size cannot be changed) */ + VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS]; + + /* Set all values to 0 */ + memset(&thresholds, 0, sizeof(thresholds)); + + /* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */ + for(i = 0; i < 64; i++){ + thresholds[i].zone_num = i; + thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR; + thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER; + thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE; + + /* The value 44 is given as example. All motion above 44 will be considered as a movement */ + thresholds[i].param_low_thresh = 44; + thresholds[i].param_high_thresh = 44; + } + + /* The last thresholds must be clearly indicated. As we have 64 + * checkers, the last one is the 63 */ + thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num; + + /* Send array of thresholds to the sensor */ + vl53l8cx_set_detection_thresholds(&Dev, thresholds); + + /* Enable detection thresholds */ + vl53l8cx_set_detection_thresholds_enable(&Dev, 1); + + + /*********************************/ + /* Ranging loop */ + /*********************************/ + + int IntCount = 0; + status = vl53l8cx_start_ranging(&Dev); + printf("Waiting for a movement into the FOV between 1m and 2m...\n"); +#if 1 + loop = 10; + //while(loop < 11111) + while(1) + { + /* Function WaitForL5Interrupt() does not exists, and must be + * implemented by user. It allows catching the interrupt raised on + * pin A3 (INT), when the checkers detect the programmed + * conditions. + */ + +// isReady = WaitForL5Interrupt(&Dev); + isReady = ToF_EventDetected; + if (ToF_EventDetected != 0) + { + vl53l8cx_get_ranging_data(&Dev, &Results); + + /* As the sensor is set in 8x8 mode by default, we have a total + * of 64 zones to print. For this example, only the data of first zone are + * print */ + for(i = 0; i < 64; i++) + { + if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) + { + printf(" Movement detected in this zone : %3d !\n", i); + } + } + printf("\n"); + loop++; + } + + } + + status = vl53l8cx_stop_ranging(&Dev); + printf("End of ULD demo\n"); + //return status; +#endif +} + +int example11_init(void) +{ + + /*********************************/ + /* VL53LMZ ranging variables */ + /*********************************/ + + uint8_t status, loop, isAlive, isReady, i; +#if 0 + VL53L8CX_Configuration Dev; /* Sensor configuration */ + VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ + VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ +#endif + + /*********************************/ + /* Customer platform */ + /*********************************/ + + /* Fill the platform structure with customer's implementation. For this + * example, only the I2C address is used. + */ + Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; + + /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ + //STS_Reset_Sensor(&(Dev.platform)); + STS_Reset_Sensor(); + /* (Optional) Set a new I2C address if the wanted address is different + * from the default one (filled with 0x20 for this example). + */ + //status = vl53lmz_set_i2c_address(&Dev, 0x20); + + + /*********************************/ + /* Power on sensor and init */ + /*********************************/ +#if 0 + /* (Optional) Check if there is a VL53LMZ sensor connected */ + status = vl53lmz_is_alive(&Dev, &isAlive); + if(!isAlive || status) + { + printf("VL53LMZ not detected at requested address\n"); + return status; + } +#endif + /* (Mandatory) Init VL53LMZ sensor */ + status = vl53l8cx_init(&Dev); + if(status) + { + printf("VL53LMZ ULD Loading failed\n"); + return status; + } else { + printf("VL53L8CX ULD good\n"); + } + + //printf("VL53LMZ ULD ready ! (Version : %s)\n", + // VL53LMZ_API_REVISION); + + + /*********************************/ + /* Program motion indicator */ + /*********************************/ + + /* Create motion indicator with resolution 8x8 */ + status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + if(status) + { + printf("Motion indicator init failed with status : %u\n", status); + //return status; + } + + /* (Optional) Change the min and max distance used to detect motions. The + * difference between min and max must never be >1500mm, and minimum never be <400mm, + * otherwise the function below returns error 127 */ + status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 200, 400); + //status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 2000, 2600); + if(status) + { + printf("Motion indicator set distance motion failed with status : %u\n", status); + //return status; + } + + /* If user want to change the resolution, he also needs to update the motion indicator resolution */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + + + /* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS); + status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10); + status = vl53l8cx_set_integration_time_ms(&Dev, 10); + + + /*********************************/ + /* Program detection thresholds */ + /*********************************/ + + /* In this example, we want 1 thresholds per zone for a 8x8 resolution */ + /* Create array of thresholds (size cannot be changed) */ + VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS]; + + /* Set all values to 0 */ + memset(&thresholds, 0, sizeof(thresholds)); + + /* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */ + for(i = 0; i < 64; i++){ + thresholds[i].zone_num = i; + thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR; + thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER; + thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE; + + /* The value 44 is given as example. All motion above 44 will be considered as a movement */ + thresholds[i].param_low_thresh = 44; + thresholds[i].param_high_thresh = 44; + } + + /* The last thresholds must be clearly indicated. As we have 64 + * checkers, the last one is the 63 */ + thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num; + + /* Send array of thresholds to the sensor */ + vl53l8cx_set_detection_thresholds(&Dev, thresholds); + + /* Enable detection thresholds */ + vl53l8cx_set_detection_thresholds_enable(&Dev, 1); + + + /*********************************/ + /* Ranging loop */ + /*********************************/ + + int IntCount = 0; + status = vl53l8cx_start_ranging(&Dev); + printf("Waiting for a movement into the FOV between 1m and 2m...\n"); +#if 1 + loop = 0; + while(loop < 100) + //while(1) + { + printf("Waiting for a movement into the FOV between 1m and 2m...\n"); + /* Function WaitForL5Interrupt() does not exists, and must be + * implemented by user. It allows catching the interrupt raised on + * pin A3 (INT), when the checkers detect the programmed + * conditions. + */ + +// isReady = WaitForL5Interrupt(&Dev); + isReady = ToF_EventDetected; + if(isReady) + { + vl53l8cx_get_ranging_data(&Dev, &Results); + + /* As the sensor is set in 8x8 mode by default, we have a total + * of 64 zones to print. For this example, only the data of first zone are + * print */ + for(i = 0; i < 64; i++) + { + if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) + { + printf(" Movement detected in this zone : %3d !\n", i); + } + } + printf("\n"); + loop++; + } + + } + + status = vl53l8cx_stop_ranging(&Dev); + printf("End of ULD demo\n"); + //return status; +#endif +} +void example11_process() +{ + + /*********************************/ + /* Ranging loop */ + /*********************************/ + + int IntCount = 0; + int loop = 0; + //while(loop < 1) + //while(1) + { + /* Function WaitForL5Interrupt() does not exists, and must be + * implemented by user. It allows catching the interrupt raised on + * pin A3 (INT), when the checkers detect the programmed + * conditions. + */ + +// isReady = WaitForL5Interrupt(&Dev); + if (ToF_EventDetected !=0) + { + ToF_EventDetected = 0; + vl53l8cx_get_ranging_data(&Dev, &Results); + + /* As the sensor is set in 8x8 mode by default, we have a total + * of 64 zones to print. For this example, only the data of first zone are + * print */ + for(uint8_t i = 0; i < 64; i++) + { + if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) + { + printf(" Movement detected in this zone : %3d !\n", i); + } + } + printf("\n"); + //loop++; + } + + } + + //status = vl53l8cx_stop_ranging(&Dev); + //printf("End of ULD demo\n"); + //return status; + + +} + + +/* + * L8M + */ #ifdef __cplusplus } diff --git a/STS/TOF/App/app_tof.h b/STS/TOF/App/app_tof.h index fd86d1e..1989efd 100644 --- a/STS/TOF/App/app_tof.h +++ b/STS/TOF/App/app_tof.h @@ -34,7 +34,9 @@ void MX_TOF_Init(void); void MX_TOF_Process(void); uint16_t MX_TOF_Ranging_Process(void); - +int example11_init(void); +void example11_process(void); +void STS_Reset_Sensor(void); //void STS_TOF_VL53LX_PeopleCounting_Process(void); //int sts_tof_vl53lx_peoplecount_subprocess(void); From bd4a1a01350db360907cc23c482f838b0129f15a Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Fri, 25 Oct 2024 19:33:56 +0800 Subject: [PATCH 10/12] wip --- Core/Src/main.c | 12 +++++++++--- Core/Src/sys_app.c | 2 +- Core/Src/usart_if.c | 2 +- STS/TOF/App/app_tof.c | 41 ++++++++++++++++++++++++++--------------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 21f8504..f8d7b02 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -109,14 +109,20 @@ int main(void) /* USER CODE BEGIN 2 */ MX_USART2_UART_Init(); /* USER CODE END 2 */ - example11_init(); - example11_process(); + printf("\n\n####### start 1\n\r"); + printf("\n\n####### start 2\n\r"); + printf("\n\n####### start 3\n\r"); + printf("\n\n####### start 4\n\r"); + + //example11_init(); + //example11_process(); /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ - example11(); + //example11(); + //example11_process(); MX_LoRaWAN_Process(); //MX_TOF_Process(); // MX_TOF_Ranging_Process(); diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c index 88f209f..182c229 100644 --- a/Core/Src/sys_app.c +++ b/Core/Src/sys_app.c @@ -123,7 +123,7 @@ void SystemApp_Init(void) /*Initialize the Sensors */ EnvSensors_Init(); #if defined(L8) - //MX_TOF_Init(); + MX_TOF_Init(); #endif #if defined(STS_P2) STS_TOF_VL53LX_PeopleCounting_Process_Init(); diff --git a/Core/Src/usart_if.c b/Core/Src/usart_if.c index 8ac0e4a..7a9a992 100644 --- a/Core/Src/usart_if.c +++ b/Core/Src/usart_if.c @@ -128,7 +128,7 @@ UTIL_ADV_TRACE_Status_t vcom_DeInit(void) /* ##-3- Disable the NVIC for DMA ########################################### */ /* USER CODE BEGIN 1 */ HAL_NVIC_DisableIRQ(DMA1_Channel6_IRQn); - + HAL_NVIC_DisableIRQ(DMA1_Channel7_IRQn); return UTIL_ADV_TRACE_OK; /* USER CODE END 1 */ /* USER CODE BEGIN vcom_DeInit_2 */ diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 47a149f..99d554a 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -114,9 +114,9 @@ void MX_TOF_Init(void) //MX_53L1A2_SimpleRanging_Init(); //STS_TOF_VL53LX_PeopleCounting_Process(); #ifdef L8 - //MX_53L8A1_ThresholdDetection_Init(); - //MX_53L8A1_ThresholdDetection_Process(); - example11_init(); + MX_53L8A1_ThresholdDetection_Init(); + MX_53L8A1_ThresholdDetection_Process(); + //example11_init(); #endif /* USER CODE BEGIN TOF_Init_PostTreatment */ @@ -185,8 +185,8 @@ void MX_TOF_Process(void) //sts_tof_vl53lx_peoplecount_subprocess(); #ifdef L8 //MX_53L8A1_ThresholdDetection_Process(); - //STS_TOF_L8_Process(); - example11_process(); + STS_TOF_L8_Process(); + //example11_process(); #endif /* USER CODE BEGIN TOF_Process_PostTreatment */ @@ -215,15 +215,21 @@ void STS_TOF_L8_Process(void) void STS_Reset_Sensor(void) { /* Sensor reset */ + printf("\r\nSTS_reset_sensor start 1\r\n"); HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_RESET); - HAL_Delay(2); + printf("\r\nSTS_reset_sensor start 1.1\r\n"); + //HAL_Delay(50); + printf("\r\nSTS_reset_sensor start 1.2\r\n"); HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET); - HAL_Delay(2); - + //HAL_Delay(50); + printf("\r\nSTS_reset_sensor start 2\r\n"); HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_RESET); - HAL_Delay(2); + printf("\r\nSTS_reset_sensor start 2.1\r\n"); + //HAL_Delay(50); + printf("\r\nSTS_reset_sensor start 2.2\r\n"); HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET); - HAL_Delay(2); + //HAL_Delay(50); + printf("\r\nSTS_reset_sensor finished \r\n"); } /* VL53L8A1 */ @@ -324,7 +330,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void) printf("-------------------------------------------\n\r"); printf("please put a target between %d and %d millimeters from the sensor\n\r", LOW_THRESHOLD, HIGH_THRESHOLD); -#if 1 +#if 0 //while (1) { /* interrupt mode */ @@ -905,7 +911,7 @@ int example11_init(void) * example, only the I2C address is used. */ Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; - + printf("\r\n example11_init: dev =%02x\r\n", Dev.platform.address); /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ //STS_Reset_Sensor(&(Dev.platform)); STS_Reset_Sensor(); @@ -920,19 +926,23 @@ int example11_init(void) /*********************************/ #if 0 /* (Optional) Check if there is a VL53LMZ sensor connected */ - status = vl53lmz_is_alive(&Dev, &isAlive); + printf("\r\n check Alive status \r\n"); + status = vl53l8cx_is_alive(&Dev, &isAlive); + if(!isAlive || status) { printf("VL53LMZ not detected at requested address\n"); - return status; + //return status; } #endif /* (Mandatory) Init VL53LMZ sensor */ + printf("\r\nstart Init \r\n"); status = vl53l8cx_init(&Dev); + printf("\r\nInit status =%d \r\n", status); if(status) { printf("VL53LMZ ULD Loading failed\n"); - return status; + //return status; } else { printf("VL53L8CX ULD good\n"); } @@ -944,6 +954,7 @@ int example11_init(void) /*********************************/ /* Program motion indicator */ /*********************************/ + printf("VL53LMZ program motion indicator\n"); /* Create motion indicator with resolution 8x8 */ status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); From 9491bcc26f82f634ad22903d957ac5d8b4f81238 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 28 Oct 2024 10:46:01 +0800 Subject: [PATCH 11/12] wip 1028 10:46 --- STS/TOF/App/app_tof.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 99d554a..2ef6c6a 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -69,8 +69,8 @@ int example11(void); #ifdef L8 /* for VL53L8A1 */ #define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */ -#define LOW_THRESHOLD (2000U) -#define HIGH_THRESHOLD (2600U) +#define LOW_THRESHOLD (200U) +#define HIGH_THRESHOLD (1200U) /* Private variables ---------------------------------------------------------*/ static RANGING_SENSOR_Capabilities_t Cap; From 9c9ed4e5dda3953649bbe8e75aeb3a047eed20f2 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 28 Oct 2024 18:29:02 +0800 Subject: [PATCH 12/12] clean L8 --- Core/Src/main.c | 14 +- STS/TOF/App/app_tof.c | 501 ++---------------------------------------- 2 files changed, 18 insertions(+), 497 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index f8d7b02..9b28119 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -109,23 +109,13 @@ int main(void) /* USER CODE BEGIN 2 */ MX_USART2_UART_Init(); /* USER CODE END 2 */ - printf("\n\n####### start 1\n\r"); - printf("\n\n####### start 2\n\r"); - printf("\n\n####### start 3\n\r"); - printf("\n\n####### start 4\n\r"); - - //example11_init(); - //example11_process(); - /* Infinite loop */ + /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ - //example11(); - //example11_process(); + MX_LoRaWAN_Process(); - //MX_TOF_Process(); - // MX_TOF_Ranging_Process(); /* USER CODE BEGIN 3 */ } diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 2ef6c6a..45367e7 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -116,7 +116,7 @@ void MX_TOF_Init(void) #ifdef L8 MX_53L8A1_ThresholdDetection_Init(); MX_53L8A1_ThresholdDetection_Process(); - //example11_init(); + #endif /* USER CODE BEGIN TOF_Init_PostTreatment */ @@ -142,7 +142,7 @@ uint16_t MX_TOF_Ranging_Process(void) uint16_t range_distance=0; uint8_t center_roi[4] = {27,28,35,36}; uint8_t range_mode = 2; //STS_TOF_LONG_RANGE; - int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result); + int32_t status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result); printf("\r| 27 | 28 | 35 | 36 |\r\n"); @@ -186,7 +186,7 @@ void MX_TOF_Process(void) #ifdef L8 //MX_53L8A1_ThresholdDetection_Process(); STS_TOF_L8_Process(); - //example11_process(); + #endif /* USER CODE BEGIN TOF_Process_PostTreatment */ @@ -212,24 +212,26 @@ void STS_TOF_L8_Process(void) } } } +#endif + void STS_Reset_Sensor(void) { /* Sensor reset */ - printf("\r\nSTS_reset_sensor start 1\r\n"); + HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_RESET); - printf("\r\nSTS_reset_sensor start 1.1\r\n"); + //HAL_Delay(50); - printf("\r\nSTS_reset_sensor start 1.2\r\n"); + HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET); //HAL_Delay(50); - printf("\r\nSTS_reset_sensor start 2\r\n"); + HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_RESET); - printf("\r\nSTS_reset_sensor start 2.1\r\n"); + //HAL_Delay(50); - printf("\r\nSTS_reset_sensor start 2.2\r\n"); + HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET); //HAL_Delay(50); - printf("\r\nSTS_reset_sensor finished \r\n"); + } /* VL53L8A1 */ @@ -269,7 +271,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void) VL53L8A1_RANGING_SENSOR_ReadID(VL53L8A1_DEV_CENTER, &Id); VL53L8A1_RANGING_SENSOR_GetCapabilities(VL53L8A1_DEV_CENTER, &Cap); - + printf("\n detection process, after get capabilities\r\n"); Profile.RangingProfile = RS_PROFILE_8x8_AUTONOMOUS; Profile.TimingBudget = TIMING_BUDGET; Profile.Frequency = RANGING_FREQUENCY; /* Ranging frequency Hz (shall be consistent with TimingBudget value) */ @@ -287,36 +289,6 @@ static void MX_53L8A1_ThresholdDetection_Process(void) VL53L8A1_RANGING_SENSOR_ConfigIT(VL53L8A1_DEV_CENTER, &ITConfig); - // L8CX Motion -#if 0 - /*********************************/ - /* Program motion indicator */ - /*********************************/ - - /* Create motion indicator with resolution 8x8 */ - int status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); - if(status) - { - printf("Motion indicator init failed with status : %u\n", status); - return status; - } - - /* (Optional) Change the min and max distance used to detect motions. The - * difference between min and max must never be >1500mm, and minimum never be <400mm, - * otherwise the function below returns error 127 */ - status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000); - if(status) - { - printf("Motion indicator set distance motion failed with status : %u\n", status); - return status; - } - - /* If user want to change the resolution, he also needs to update the motion indicator resolution */ - status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); - status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); - - // L8 Motion -#endif status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS); if (status != BSP_ERROR_NONE) @@ -421,7 +393,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result) printf("| %5s : %5s ", ".", "."); } printf("|\n"); - +#if 0 if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0)) { /* Print Signal and Ambient */ @@ -448,6 +420,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result) } printf("|\n"); } +#endif } } @@ -460,7 +433,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result) -#endif + #if defined(STS_P2)||defined(STS_T6) uint8_t IsInterruptDetected(uint16_t dev) @@ -676,448 +649,6 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps) #endif } #endif -/* - * L8M - */ - -/************************************************************/ -/* VL53LMZ ULD motion indicator with detection thresholds */ -/************************************************************/ -/* -* This example shows how to use the motion indicator with detection threshold. -* This kind of configuration might be used for user detection applications. -* To use this example, user needs to be sure that macro -* VL53LMZ_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h). -*/ - -#include -#include -#include -#include "vl53l8cx_api.h" -#include "vl53l8cx_plugin_motion_indicator.h" -#include "vl53l8cx_plugin_detection_thresholds.h" - -VL53L8CX_Configuration Dev; /* Sensor configuration */ -VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ -VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ - -// #define UNUSED(x) (void)(x) - -/* This function needs to be filled by the customer. It allows knowing when - * the VL53LMZ interrupt is raised on GPIO1. This is the only way to use detection thresholds. - */ -/* -int WaitForL5Interrupt(VL53LMZ_Configuration * pDev) { - - //Add your implementation here ... - UNUSED(pDev); - - return 0; -} -*/ -//extern int WaitForL5Interrupt(VL53LMZ_Configuration * pDev); -//extern int IntCount; - -int example11(void) -{ - - /*********************************/ - /* VL53LMZ ranging variables */ - /*********************************/ - - uint8_t status, loop, isAlive, isReady, i; -#if 0 - VL53L8CX_Configuration Dev; /* Sensor configuration */ - VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ - VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ -#endif - - /*********************************/ - /* Customer platform */ - /*********************************/ - - /* Fill the platform structure with customer's implementation. For this - * example, only the I2C address is used. - */ - Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; - - /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ - //Reset_Sensor(&(Dev.platform)); - - /* (Optional) Set a new I2C address if the wanted address is different - * from the default one (filled with 0x20 for this example). - */ - //status = vl53lmz_set_i2c_address(&Dev, 0x20); - - - /*********************************/ - /* Power on sensor and init */ - /*********************************/ -#if 0 - /* (Optional) Check if there is a VL53LMZ sensor connected */ - status = vl53lmz_is_alive(&Dev, &isAlive); - if(!isAlive || status) - { - printf("VL53LMZ not detected at requested address\n"); - return status; - } -#endif - /* (Mandatory) Init VL53LMZ sensor */ - status = vl53l8cx_init(&Dev); - if(status) - { - printf("VL53LMZ ULD Loading failed\n"); - return status; - } - - //printf("VL53LMZ ULD ready ! (Version : %s)\n", - // VL53LMZ_API_REVISION); - - - /*********************************/ - /* Program motion indicator */ - /*********************************/ - - /* Create motion indicator with resolution 8x8 */ - status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); - if(status) - { - printf("Motion indicator init failed with status : %u\n", status); - //return status; - } - - /* (Optional) Change the min and max distance used to detect motions. The - * difference between min and max must never be >1500mm, and minimum never be <400mm, - * otherwise the function below returns error 127 */ - //status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000); - status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 2000, 2600); - if(status) - { - printf("Motion indicator set distance motion failed with status : %u\n", status); - //return status; - } - - /* If user want to change the resolution, he also needs to update the motion indicator resolution */ - status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); - status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); - - - /* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */ - status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); - status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS); - status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10); - status = vl53l8cx_set_integration_time_ms(&Dev, 10); - - - /*********************************/ - /* Program detection thresholds */ - /*********************************/ - - /* In this example, we want 1 thresholds per zone for a 8x8 resolution */ - /* Create array of thresholds (size cannot be changed) */ - VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS]; - - /* Set all values to 0 */ - memset(&thresholds, 0, sizeof(thresholds)); - - /* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */ - for(i = 0; i < 64; i++){ - thresholds[i].zone_num = i; - thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR; - thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER; - thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE; - - /* The value 44 is given as example. All motion above 44 will be considered as a movement */ - thresholds[i].param_low_thresh = 44; - thresholds[i].param_high_thresh = 44; - } - - /* The last thresholds must be clearly indicated. As we have 64 - * checkers, the last one is the 63 */ - thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num; - - /* Send array of thresholds to the sensor */ - vl53l8cx_set_detection_thresholds(&Dev, thresholds); - - /* Enable detection thresholds */ - vl53l8cx_set_detection_thresholds_enable(&Dev, 1); - - - /*********************************/ - /* Ranging loop */ - /*********************************/ - - int IntCount = 0; - status = vl53l8cx_start_ranging(&Dev); - printf("Waiting for a movement into the FOV between 1m and 2m...\n"); -#if 1 - loop = 10; - //while(loop < 11111) - while(1) - { - /* Function WaitForL5Interrupt() does not exists, and must be - * implemented by user. It allows catching the interrupt raised on - * pin A3 (INT), when the checkers detect the programmed - * conditions. - */ - -// isReady = WaitForL5Interrupt(&Dev); - isReady = ToF_EventDetected; - if (ToF_EventDetected != 0) - { - vl53l8cx_get_ranging_data(&Dev, &Results); - - /* As the sensor is set in 8x8 mode by default, we have a total - * of 64 zones to print. For this example, only the data of first zone are - * print */ - for(i = 0; i < 64; i++) - { - if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) - { - printf(" Movement detected in this zone : %3d !\n", i); - } - } - printf("\n"); - loop++; - } - - } - - status = vl53l8cx_stop_ranging(&Dev); - printf("End of ULD demo\n"); - //return status; -#endif -} - -int example11_init(void) -{ - - /*********************************/ - /* VL53LMZ ranging variables */ - /*********************************/ - - uint8_t status, loop, isAlive, isReady, i; -#if 0 - VL53L8CX_Configuration Dev; /* Sensor configuration */ - VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ - VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ -#endif - - /*********************************/ - /* Customer platform */ - /*********************************/ - - /* Fill the platform structure with customer's implementation. For this - * example, only the I2C address is used. - */ - Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; - printf("\r\n example11_init: dev =%02x\r\n", Dev.platform.address); - /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ - //STS_Reset_Sensor(&(Dev.platform)); - STS_Reset_Sensor(); - /* (Optional) Set a new I2C address if the wanted address is different - * from the default one (filled with 0x20 for this example). - */ - //status = vl53lmz_set_i2c_address(&Dev, 0x20); - - - /*********************************/ - /* Power on sensor and init */ - /*********************************/ -#if 0 - /* (Optional) Check if there is a VL53LMZ sensor connected */ - printf("\r\n check Alive status \r\n"); - status = vl53l8cx_is_alive(&Dev, &isAlive); - - if(!isAlive || status) - { - printf("VL53LMZ not detected at requested address\n"); - //return status; - } -#endif - /* (Mandatory) Init VL53LMZ sensor */ - printf("\r\nstart Init \r\n"); - status = vl53l8cx_init(&Dev); - printf("\r\nInit status =%d \r\n", status); - if(status) - { - printf("VL53LMZ ULD Loading failed\n"); - //return status; - } else { - printf("VL53L8CX ULD good\n"); - } - - //printf("VL53LMZ ULD ready ! (Version : %s)\n", - // VL53LMZ_API_REVISION); - - - /*********************************/ - /* Program motion indicator */ - /*********************************/ - printf("VL53LMZ program motion indicator\n"); - - /* Create motion indicator with resolution 8x8 */ - status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); - if(status) - { - printf("Motion indicator init failed with status : %u\n", status); - //return status; - } - - /* (Optional) Change the min and max distance used to detect motions. The - * difference between min and max must never be >1500mm, and minimum never be <400mm, - * otherwise the function below returns error 127 */ - status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 200, 400); - //status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 2000, 2600); - if(status) - { - printf("Motion indicator set distance motion failed with status : %u\n", status); - //return status; - } - - /* If user want to change the resolution, he also needs to update the motion indicator resolution */ - status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); - status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); - - - /* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */ - status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); - status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS); - status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10); - status = vl53l8cx_set_integration_time_ms(&Dev, 10); - - - /*********************************/ - /* Program detection thresholds */ - /*********************************/ - - /* In this example, we want 1 thresholds per zone for a 8x8 resolution */ - /* Create array of thresholds (size cannot be changed) */ - VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS]; - - /* Set all values to 0 */ - memset(&thresholds, 0, sizeof(thresholds)); - - /* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */ - for(i = 0; i < 64; i++){ - thresholds[i].zone_num = i; - thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR; - thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER; - thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE; - - /* The value 44 is given as example. All motion above 44 will be considered as a movement */ - thresholds[i].param_low_thresh = 44; - thresholds[i].param_high_thresh = 44; - } - - /* The last thresholds must be clearly indicated. As we have 64 - * checkers, the last one is the 63 */ - thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num; - - /* Send array of thresholds to the sensor */ - vl53l8cx_set_detection_thresholds(&Dev, thresholds); - - /* Enable detection thresholds */ - vl53l8cx_set_detection_thresholds_enable(&Dev, 1); - - - /*********************************/ - /* Ranging loop */ - /*********************************/ - - int IntCount = 0; - status = vl53l8cx_start_ranging(&Dev); - printf("Waiting for a movement into the FOV between 1m and 2m...\n"); -#if 1 - loop = 0; - while(loop < 100) - //while(1) - { - printf("Waiting for a movement into the FOV between 1m and 2m...\n"); - /* Function WaitForL5Interrupt() does not exists, and must be - * implemented by user. It allows catching the interrupt raised on - * pin A3 (INT), when the checkers detect the programmed - * conditions. - */ - -// isReady = WaitForL5Interrupt(&Dev); - isReady = ToF_EventDetected; - if(isReady) - { - vl53l8cx_get_ranging_data(&Dev, &Results); - - /* As the sensor is set in 8x8 mode by default, we have a total - * of 64 zones to print. For this example, only the data of first zone are - * print */ - for(i = 0; i < 64; i++) - { - if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) - { - printf(" Movement detected in this zone : %3d !\n", i); - } - } - printf("\n"); - loop++; - } - - } - - status = vl53l8cx_stop_ranging(&Dev); - printf("End of ULD demo\n"); - //return status; -#endif -} -void example11_process() -{ - - /*********************************/ - /* Ranging loop */ - /*********************************/ - - int IntCount = 0; - int loop = 0; - //while(loop < 1) - //while(1) - { - /* Function WaitForL5Interrupt() does not exists, and must be - * implemented by user. It allows catching the interrupt raised on - * pin A3 (INT), when the checkers detect the programmed - * conditions. - */ - -// isReady = WaitForL5Interrupt(&Dev); - if (ToF_EventDetected !=0) - { - ToF_EventDetected = 0; - vl53l8cx_get_ranging_data(&Dev, &Results); - - /* As the sensor is set in 8x8 mode by default, we have a total - * of 64 zones to print. For this example, only the data of first zone are - * print */ - for(uint8_t i = 0; i < 64; i++) - { - if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) - { - printf(" Movement detected in this zone : %3d !\n", i); - } - } - printf("\n"); - //loop++; - } - - } - - //status = vl53l8cx_stop_ranging(&Dev); - //printf("End of ULD demo\n"); - //return status; - - -} - - -/* - * L8M - */ #ifdef __cplusplus }