embedded code copied from jankae/VNA and adjusted for STM32G4

This commit is contained in:
Jan Käberich 2020-08-24 19:06:50 +02:00
parent 7af204b349
commit 30d4ebe37b
215 changed files with 186208 additions and 0 deletions

View file

@ -0,0 +1,130 @@
/* USER CODE BEGIN Header */
/*
* FreeRTOS Kernel V10.0.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* USER CODE END Header */
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* These parameters and more are described within the 'configuration' section of the
* FreeRTOS API documentation available on the FreeRTOS.org web site.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* Section where include file can be added */
/* USER CODE END Includes */
/* Ensure stdint is only used by the compiler, and not the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 7 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)3072)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 0
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#endif
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
/* USER CODE END 1 */
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick,
to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
#define xPortSysTickHandler SysTick_Handler
/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,106 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal.h"
#include "stm32g4xx_ll_ucpd.h"
#include "stm32g4xx_ll_bus.h"
#include "stm32g4xx_ll_cortex.h"
#include "stm32g4xx_ll_rcc.h"
#include "stm32g4xx_ll_system.h"
#include "stm32g4xx_ll_utils.h"
#include "stm32g4xx_ll_pwr.h"
#include "stm32g4xx_ll_gpio.h"
#include "stm32g4xx_ll_dma.h"
#include "stm32g4xx_ll_exti.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define FPGA_INIT_B_Pin GPIO_PIN_1
#define FPGA_INIT_B_GPIO_Port GPIOF
#define FPGA_AUX1_Pin GPIO_PIN_1
#define FPGA_AUX1_GPIO_Port GPIOA
#define FPGA_AUX2_Pin GPIO_PIN_2
#define FPGA_AUX2_GPIO_Port GPIOA
#define FPGA_AUX3_Pin GPIO_PIN_3
#define FPGA_AUX3_GPIO_Port GPIOA
#define FPGA_CS_Pin GPIO_PIN_4
#define FPGA_CS_GPIO_Port GPIOA
#define FLASH_CS_Pin GPIO_PIN_0
#define FLASH_CS_GPIO_Port GPIOB
#define FPGA_INTR_Pin GPIO_PIN_1
#define FPGA_INTR_GPIO_Port GPIOB
#define FPGA_PROGRAM_B_Pin GPIO_PIN_2
#define FPGA_PROGRAM_B_GPIO_Port GPIOB
#define EN_6V_Pin GPIO_PIN_12
#define EN_6V_GPIO_Port GPIOB
#define LED1_Pin GPIO_PIN_15
#define LED1_GPIO_Port GPIOA
#define FPGA_RESET_Pin GPIO_PIN_7
#define FPGA_RESET_GPIO_Port GPIOB
#define FPGA_DONE_Pin GPIO_PIN_9
#define FPGA_DONE_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,53 @@
/**
******************************************************************************
* @file stm32_assert.h
* @brief STM32 assert file.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_ASSERT_H
#define __STM32_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32_ASSERT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,381 @@
/**
******************************************************************************
* @file stm32g4xx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G4xx_HAL_CONF_H
#define STM32G4xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CORDIC_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_FDCAN_MODULE_ENABLED */
/*#define HAL_FMAC_MODULE_ENABLED */
/*#define HAL_HRTIM_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
#define HAL_I2C_MODULE_ENABLED
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_NOR_MODULE_ENABLED */
/*#define HAL_OPAMP_MODULE_ENABLED */
#define HAL_PCD_MODULE_ENABLED
/*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/*#define HAL_SRAM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
/* ########################## Register Callbacks selection ############################## */
/**
* @brief This is the list of modules where register callback can be used
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U
#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U
#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG.
* This internal oscillator is mainly dedicated to provide a high precision clock to
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
* which is subject to manufacturing process variations.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
/*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations in voltage and temperature.*/
#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for I2S and SAI peripherals
* This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source
* frequency, this source is inserted directly through I2S_CKIN pad.
*/
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/
#endif /* EXTERNAL_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY (5UL) /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32g4xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32g4xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32g4xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32g4xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32g4xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32g4xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CORDIC_MODULE_ENABLED
#include "stm32g4xx_hal_cordic.h"
#endif /* HAL_CORDIC_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32g4xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32g4xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32g4xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32g4xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_FDCAN_MODULE_ENABLED
#include "stm32g4xx_hal_fdcan.h"
#endif /* HAL_FDCAN_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32g4xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_FMAC_MODULE_ENABLED
#include "stm32g4xx_hal_fmac.h"
#endif /* HAL_FMAC_MODULE_ENABLED */
#ifdef HAL_HRTIM_MODULE_ENABLED
#include "stm32g4xx_hal_hrtim.h"
#endif /* HAL_HRTIM_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32g4xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32g4xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32g4xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32g4xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32g4xx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32g4xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32g4xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_OPAMP_MODULE_ENABLED
#include "stm32g4xx_hal_opamp.h"
#endif /* HAL_OPAMP_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32g4xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32g4xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_QSPI_MODULE_ENABLED
#include "stm32g4xx_hal_qspi.h"
#endif /* HAL_QSPI_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32g4xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32g4xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32g4xx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32g4xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32g4xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32g4xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32g4xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32g4xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32g4xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32g4xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32g4xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32G4xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,72 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g4xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32G4xx_IT_H
#define __STM32G4xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel2_IRQHandler(void);
void USB_HP_IRQHandler(void);
void USB_LP_IRQHandler(void);
void TIM1_TRG_COM_TIM17_IRQHandler(void);
void UCPD1_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32G4xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,61 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd.h
* @author MCD Application Team
* @brief This file contains the device define.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __usbpd_H
#define __usbpd_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbpd_core.h"
#include "usbpd_dpm_core.h"
#include "usbpd_dpm_user.h"
#include "usbpd_hw_if.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* Global variables ---------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* USBPD init function */
void MX_USBPD_Init(void);
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
#ifdef __cplusplus
}
#endif
#endif /*__usbpd_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,127 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_devices_conf.h
* @author MCD Application Team
* @brief This file contains the device define.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* CubeMX Generated */
#define CUBEMX_GENERATED
#ifndef USBPD_DEVICE_CONF_H
#define USBPD_DEVICE_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_ll_bus.h"
#include "stm32g4xx_ll_dma.h"
#include "stm32g4xx_ll_gpio.h"
#include "stm32g4xx_ll_rcc.h"
#include "stm32g4xx_ll_ucpd.h"
#include "stm32g4xx_ll_pwr.h"
#include "stm32g4xx_ll_tim.h"
/* USER CODE BEGIN Includes */
#include "usbpd_pwr_user.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* -----------------------------------------------------------------------------
usbpd_hw.c
-------------------------------------------------------------------------------*/
/* defined used to configure function : BSP_USBPD_GetUSPDInstance */
#define UCPD_INSTANCE0 UCPD1
/* defined used to configure function : BSP_USBPD_Init_DMARxInstance,BSP_USBPD_DeInit_DMARxInstance */
#define UCPDDMA_INSTANCE0_CLOCKENABLE_RX LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1)
#define UCPDDMA_INSTANCE0_DMA_RX DMA1
#define UCPDDMA_INSTANCE0_REQUEST_RX DMA_REQUEST_UCPD1_RX
#define UCPDDMA_INSTANCE0_LL_CHANNEL_RX LL_DMA_CHANNEL_1
#define UCPDDMA_INSTANCE0_CHANNEL_RX DMA1_Channel1
/* defined used to configure function : BSP_USBPD_Init_DMATxInstance, BSP_USBPD_DeInit_DMATxInstance */
#define UCPDDMA_INSTANCE0_CLOCKENABLE_TX LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1)
#define UCPDDMA_INSTANCE0_DMA_TX DMA1
#define UCPDDMA_INSTANCE0_REQUEST_TX DMA_REQUEST_UCPD1_TX
#define UCPDDMA_INSTANCE0_LL_CHANNEL_TX LL_DMA_CHANNEL_2
#define UCPDDMA_INSTANCE0_CHANNEL_TX DMA1_Channel2
/* defined used to configure BSP_USBPD_SetFRSSignalling */
#define UCPDFRS_INSTANCE0_FRSCC1
#define UCPDFRS_INSTANCE0_FRSCC2
#define UCPD_INSTANCE0_ENABLEIRQ do{ \
NVIC_SetPriority(UCPD1_IRQn,4); \
NVIC_EnableIRQ(UCPD1_IRQn); \
} while(0)
/* -----------------------------------------------------------------------------
Definitions for timer service feature
-------------------------------------------------------------------------------*/
#define TIMX TIM2
#define TIMX_CLK_ENABLE LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2)
#define TIMX_CLK_DISABLE LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2)
#define TIMX_IRQ TIM2_IRQn
#define TIMX_CHANNEL_CH1 LL_TIM_CHANNEL_CH1
#define TIMX_CHANNEL_CH2 LL_TIM_CHANNEL_CH2
#define TIMX_CHANNEL_CH3 LL_TIM_CHANNEL_CH3
#define TIMX_CHANNEL_CH4 LL_TIM_CHANNEL_CH4
#define TIMX_CHANNEL1_SETEVENT do{ \
LL_TIM_OC_SetCompareCH1(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
LL_TIM_ClearFlag_CC1(TIMX); \
}while(0)
#define TIMX_CHANNEL2_SETEVENT do{ \
LL_TIM_OC_SetCompareCH2(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
LL_TIM_ClearFlag_CC2(TIMX); \
}while(0)
#define TIMX_CHANNEL3_SETEVENT do{ \
LL_TIM_OC_SetCompareCH3(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
LL_TIM_ClearFlag_CC3(TIMX); \
}while(0)
#define TIMX_CHANNEL4_SETEVENT do{ \
LL_TIM_OC_SetCompareCH4(TIMX, (TimeUs + TIMX->CNT) % TIM_MAX_TIME);\
LL_TIM_ClearFlag_CC4(TIMX); \
}while(0)
#define TIMX_CHANNEL1_GETFLAG LL_TIM_IsActiveFlag_CC1
#define TIMX_CHANNEL2_GETFLAG LL_TIM_IsActiveFlag_CC2
#define TIMX_CHANNEL3_GETFLAG LL_TIM_IsActiveFlag_CC3
#define TIMX_CHANNEL4_GETFLAG LL_TIM_IsActiveFlag_CC4
#ifdef __cplusplus
}
#endif
#endif /* USBPD_DEVICE_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,121 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_dpm_conf.h
* @author MCD Application Team
* @brief Header file for stack/application settings file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#ifndef __USBPD_DPM_CONF_H_
#define __USBPD_DPM_CONF_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbpd_pdo_defs.h"
#include "usbpd_vdm_user.h"
#include "usbpd_dpm_user.h"
/* USER CODE BEGIN Includes */
/* Section where include file can be added */
/* USER CODE END Includes */
/* Define ------------------------------------------------------------------*/
/* Define VID, PID,... manufacturer parameters */
#define USBPD_VID (0x0483u) /*!< Vendor ID (assigned by the USB-IF) */
#define USBPD_PID (0x0002u) /*!< Product ID (assigned by the manufacturer) */
#define USBPD_XID (0xF0000003u) /*!< Value provided by the USB-IF assigned to the product */
/* USER CODE BEGIN Define */
/* Section where Define can be added */
/* USER CODE END Define */
/* Exported typedef ----------------------------------------------------------*/
/* USER CODE BEGIN Typedef */
/* Section where Typedef can be added */
/* USER CODE END Typedef */
/* Private variables ---------------------------------------------------------*/
#ifndef __USBPD_DPM_CORE_C
extern USBPD_SettingsTypeDef DPM_Settings[USBPD_PORT_COUNT];
#else /* __USBPD_DPM_CORE_C */
USBPD_SettingsTypeDef DPM_Settings[USBPD_PORT_COUNT] =
{
{
.PE_SupportedSOP = USBPD_SUPPORTED_SOP_SOP , /* Supported SOP : SOP, SOP' SOP" SOP'Debug SOP"Debug */
.PE_SpecRevision = USBPD_SPECIFICATION_REV2,/* spec revision value */
.PE_DefaultRole = USBPD_PORTPOWERROLE_SNK, /* Default port role */
.PE_RoleSwap = USBPD_FALSE, /* support port role swap */
.PE_VDMSupport = USBPD_FALSE,
.PE_RespondsToDiscovSOP = USBPD_FALSE, /*!< Can respond successfully to a Discover Identity */
.PE_AttemptsDiscovSOP = USBPD_FALSE, /*!< Can send a Discover Identity */
.PE_PingSupport = USBPD_FALSE, /* support Ping (only for PD3.0) */
.PE_CapscounterSupport = USBPD_FALSE, /* support caps counter */
.CAD_RoleToggle = USBPD_FALSE, /* CAD role toggle */
.CAD_TryFeature = 0, /* CAD try feature */
.CAD_AccesorySupport = USBPD_FALSE, /* CAD accessory support */
.PE_PD3_Support.d = /*!< PD3 SUPPORT FEATURE */
{
.PE_UnchunkSupport = USBPD_FALSE, /* support Unchunked mode (valid only spec revision 3.0) */
.PE_FastRoleSwapSupport = USBPD_FALSE, /* support fast role swap only spec revsion 3.0 */
.Is_GetPPSStatus_Supported = USBPD_FALSE, /*!< PPS message NOT supported by PE stack */
.Is_SrcCapaExt_Supported = USBPD_FALSE, /*!< Source_Capabilities_Extended message supported or not by DPM */
.Is_Alert_Supported = USBPD_FALSE, /*!< Alert message supported or not by DPM */
.Is_GetStatus_Supported = USBPD_FALSE, /*!< Status message supported or not by DPM (Is_Alert_Supported should be enabled) */
.Is_GetManufacturerInfo_Supported = USBPD_FALSE, /*!< Manufacturer_Info message supported or not by DPM */
.Is_GetCountryCodes_Supported = USBPD_FALSE, /*!< Country_Codes message supported or not by DPM */
.Is_GetCountryInfo_Supported = USBPD_FALSE, /*!< Country_Info message supported or not by DPM */
.Is_SecurityRequest_Supported = USBPD_FALSE, /*!< Security_Response message supported or not by DPM */
.Is_FirmUpdateRequest_Supported = USBPD_FALSE, /*!< Firmware update response message supported by PE */
.Is_SnkCapaExt_Supported = USBPD_FALSE, /*!< Sink_Capabilities_Extended message supported by PE */
},
.CAD_SRCToggleTime = 0, /* uint8_t CAD_SRCToggleTime; */
.CAD_SNKToggleTime = 0, /* uint8_t CAD_SNKToggleTime; */
}
};
#endif
/* USER CODE BEGIN Variable */
/* Section where Variable can be added */
/* USER CODE END Variable */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN Constant */
/* Section where Constant can be added */
/* USER CODE END Constant */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* Section where Macro can be added */
/* USER CODE END Macro */
#ifdef __cplusplus
}
#endif
#endif /* __USBPD_DPM_CONF_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,75 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_dpm_core.h
* @author MCD Application Team
* @brief Header file for usbpd_dpm_core.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#ifndef __USBPD_DPM_CORE_H_
#define __USBPD_DPM_CORE_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported typedef ----------------------------------------------------------*/
/* USER CODE BEGIN typedef */
/* USER CODE END typedef */
/* Exported define -----------------------------------------------------------*/
/* USER CODE BEGIN define */
/* USER CODE END define */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN constants */
/* USER CODE END constants */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN macro */
/* USER CODE END macro */
/* Exported variables --------------------------------------------------------*/
extern USBPD_ParamsTypeDef DPM_Params[USBPD_PORT_COUNT];
/* USER CODE BEGIN variables */
/* USER CODE END variables */
/* Exported functions --------------------------------------------------------*/
USBPD_StatusTypeDef USBPD_DPM_InitCore(void);
USBPD_StatusTypeDef USBPD_DPM_InitOS(void);
void USBPD_DPM_Run(void);
void USBPD_DPM_TimerCounter(void);
/* USER CODE BEGIN functions */
/* USER CODE END functions */
#ifdef __cplusplus
}
#endif
#endif /* __USBPD_DPM_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,136 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_dpm_user.h
* @author MCD Application Team
* @brief Header file for usbpd_dpm_user.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#ifndef __USBPD_DPM_USER_H_
#define __USBPD_DPM_USER_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Include */
/* USER CODE END Include */
/** @addtogroup STM32_USBPD_APPLICATION
* @{
*/
/** @addtogroup STM32_USBPD_APPLICATION_DPM_USER
* @{
*/
/* Exported typedef ----------------------------------------------------------*/
/* USER CODE BEGIN Typedef */
/* USER CODE END Typedef */
/* Exported define -----------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN Constant */
/* USER CODE END Constant */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Exported variables --------------------------------------------------------*/
/* USER CODE BEGIN Private_Variables */
/* USER CODE END Private_Variables */
/* Exported functions --------------------------------------------------------*/
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS
* @{
*/
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP1
* @{
*/
USBPD_StatusTypeDef USBPD_DPM_UserInit(void);
void USBPD_DPM_UserExecute(void const *argument);
void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State);
void USBPD_DPM_WaitForTime(uint32_t Time);
void USBPD_DPM_UserTimerCounter(uint8_t PortNum);
/**
* @}
*/
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP2
* @{
*/
USBPD_StatusTypeDef USBPD_DPM_SetupNewPower(uint8_t PortNum);
void USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status);
USBPD_StatusTypeDef USBPD_DPM_EvaluatePowerRoleSwap(uint8_t PortNum);
void USBPD_DPM_Notification(uint8_t PortNum, USBPD_NotifyEventValue_TypeDef EventVal);
USBPD_StatusTypeDef USBPD_DPM_IsContractStillValid(uint8_t PortNum);
void USBPD_DPM_ExtendedMessageReceived(uint8_t PortNum, USBPD_ExtendedMsg_TypeDef MsgType, uint8_t *ptrData, uint16_t DataSize);
void USBPD_DPM_GetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t *Size);
void USBPD_DPM_SetDataInfo(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId , uint8_t *Ptr, uint32_t Size);
USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject);
void USBPD_DPM_SNK_EvaluateCapabilities(uint8_t PortNum, uint32_t *PtrRequestData, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObjectType);
uint32_t USBPD_DPM_SNK_EvaluateMatchWithSRCPDO(uint8_t PortNum, uint32_t SrcPDO, uint32_t* PtrRequestedVoltage, uint32_t* PtrRequestedPower);
void USBPD_DPM_PowerRoleSwap(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_PRS_Status_TypeDef Status);
USBPD_StatusTypeDef USBPD_DPM_EvaluateVconnSwap(uint8_t PortNum);
USBPD_StatusTypeDef USBPD_DPM_PE_VconnPwr(uint8_t PortNum, USBPD_FunctionalState State);
USBPD_StatusTypeDef USBPD_DPM_EvaluateDataRoleSwap(uint8_t PortNum);
USBPD_FunctionalState USBPD_DPM_IsPowerReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe);
/**
* @}
*/
/** @addtogroup USBPD_USER_EXPORTED_FUNCTIONS_GROUP3
* @{
*/
/* USER CODE BEGIN Function */
/* USER CODE END Function */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBPD_DPM_USER_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,137 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_pdo_defs.h
* @author MCD Application Team
* @brief Header file for definition of PDO/APDO values for 2 ports(DRP/SNK) configuration
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#ifndef __USBPD_PDO_DEF_H_
#define __USBPD_PDO_DEF_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Define ------------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Exported typedef ----------------------------------------------------------*/
/* USER CODE BEGIN typedef */
/**
* @brief USBPD Port PDO Structure definition
*
*/
/* USER CODE END typedef */
/* Exported define -----------------------------------------------------------*/
/* USER CODE BEGIN Exported_Define */
#define USBPD_CORE_PDO_SRC_FIXED_MAX_CURRENT 3
#define USBPD_CORE_PDO_SNK_FIXED_MAX_CURRENT 1500
/* USER CODE END Exported_Define */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN constants */
/* USER CODE END constants */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN macro */
/* USER CODE END macro */
/* Exported variables --------------------------------------------------------*/
/* USER CODE BEGIN variables */
/* USER CODE END variables */
#ifndef __USBPD_PWR_IF_C
extern const uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO];
extern const uint32_t PORT0_PDO_ListSNK[USBPD_MAX_NB_PDO];
extern const uint32_t PORT1_PDO_ListSRC[USBPD_MAX_NB_PDO];
extern const uint32_t PORT1_PDO_ListSNK[USBPD_MAX_NB_PDO];
#else
/* Definition of Source PDO for Port 0 */
const uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO] =
{
/* PDO 1 */
(0x00000000U),
/* PDO 2 */
(0x00000000U),
/* PDO 3 */
(0x00000000U),
/* PDO 4 */
(0x00000000U),
/* PDO 5 */
(0x00000000U),
/* PDO 6 */
(0x00000000U),
/* PDO 7 */
(0x00000000U)
};
/* Definition of Sink PDO for Port 0 */
const uint32_t PORT0_PDO_ListSNK[USBPD_MAX_NB_PDO] =
{
/* PDO 1 */
(0x00000000U),
/* PDO 2 */
(0x00000000U),
/* PDO 3 */
(0x00000000U),
/* PDO 4 */
(0x00000000U),
/* PDO 5 */
(0x00000000U),
/* PDO 6 */
(0x00000000U),
/* PDO 7 */
(0x00000000U)
};
#endif
/* Exported functions --------------------------------------------------------*/
/* USER CODE BEGIN functions */
/* USER CODE END functions */
#ifdef __cplusplus
}
#endif
#endif /* __USBPD_PDO_DEF_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,229 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_pwr_if.h
* @author MCD Application Team
* @brief This file contains the headers of usbpd_pw_if.h.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#ifndef __USBPD_PW_IF_H_
#define __USBPD_PW_IF_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbpd_def.h"
/** @addtogroup STM32_USBPD_APPLICATION
* @{
*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF
* @{
*/
/* Exported typedef ----------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/** @defgroup USBPD_USER_PWR_IF_Exported_Macros USBPD PWR IF Exported Macros
* @{
*/
/* Macros used to convert values into PDO representation */
#define PWR_V_20MV(_V_) ((uint16_t)(( (_V_) * 1000.0) / 20.0)) /* From Volt to 20mV multiples */
#define PWR_V_50MV(_V_) ((uint16_t)(( (_V_) * 1000.0) / 50.0)) /* From Volt to 50mV multiples */
#define PWR_V_100MV(_V_) ((uint16_t)(( (_V_) * 1000.0) / 100.0)) /* From Volt to 100mV multiples */
#define PWR_A_10MA(_A_) ((uint16_t)(( (_A_) * 1000.0) / 10.0)) /* From Ampere to 10mA multiples */
#define PWR_A_50MA(_A_) ((uint16_t)(( (_A_) * 1000.0) / 50.0)) /* From Ampere to 50mA multiples */
#define PWR_W(_W_) ((uint16_t)(( (_W_) * 1000.0) / 250.0)) /* From Watt to 250mW multiples */
/* Macros used to get values from PDO representation */
#define PWR_DECODE_50MV(_Value_) ((uint16_t)(( (float)(_Value_) * 50.0))) /* From 50mV multiples to mV */
#define PWR_DECODE_100MV(_Value_) ((uint16_t)(( (float)(_Value_) * 100.0))) /* From 100mV multiples to mV */
#define PWR_DECODE_10MA(_Value_) ((uint16_t)(( (float)(_Value_) * 10.0))) /* From 10mA multiples to mA */
#define PWR_DECODE_50MA(_Value_) ((uint16_t)(( (float)(_Value_) * 50.0))) /* From 50mA multiples to mA */
#define PWR_DECODE_MW(_Value_) ((uint16_t)(( (float)(_Value_) * 250.0))) /* From 250mW multiples to mW */
#define USBPD_PORT_IsValid(__Port__) ((__Port__) < (USBPD_PORT_COUNT))
/**
* @}
*/
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup STM32_USBPD_APPLICATION_POWER_IF_Exported_Functions USBPD PWR IF Exported Functions
* @{
*/
/**
* @brief Initialize structures and variables related to power board profiles
* used by Sink and Source, for all available ports.
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_Init(void);
/**
* @brief Sets the required power profile
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum);
/**
* @brief Resets the Power Board
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_PowerResetGlobal(void);
/**
* @brief Resets the Power on a specified port
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_PowerReset(uint8_t PortNum);
/**
* @brief Checks if the power on a specified port is ready
* @param PortNum Port number
* @param Vsafe Vsafe status based on @ref USBPD_VSAFE_StatusTypeDef
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_SupplyReady(uint8_t PortNum, USBPD_VSAFE_StatusTypeDef Vsafe);
/**
* @brief Initialize the power on a specified port
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_InitPower(uint8_t PortNum);
/**
* @brief Enable VBUS power on a specified port
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum);
/**
* @brief Disable VBUS power on a specified port
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum);
/**
* @brief Disable the SNK to stop current consumption
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_SNKDisable(uint8_t PortNum);
/**
* @brief Checks if the power on a specified port is enabled
* @param PortNum Port number
* @retval ENABLE or DISABLE
*/
USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum);
/**
* @brief Reads the voltage and the current on a specified port
* @param PortNum Port number
* @param pVoltage The Voltage in mV
* @param pCurrent The Current in mA
* @retval ENABLE or DISABLE
*/
USBPD_StatusTypeDef USBPD_PWR_IF_ReadVA(uint8_t PortNum, uint16_t *pVoltage, uint16_t *pCurrent);
/**
* @brief Enables the VConn on the port.
* @param PortNum Port number
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
* @retval USBPD Status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_Enable_VConn(uint8_t PortNum, CCxPin_TypeDef CC);
/**
* @brief Disable the VConn on the port.
* @param PortNum Port number
* @param CC Specifies the CCx to be selected based on @ref CCxPin_TypeDef structure
* @retval USBPD Status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_Disable_VConn(uint8_t PortNum, CCxPin_TypeDef CC);
/**
* @brief Allow PDO data reading from PWR_IF storage.
* @param PortNum Port number
* @param DataId Type of data to be read from PWR_IF
* This parameter can be one of the following values:
* @arg @ref USBPD_CORE_DATATYPE_SRC_PDO Source PDO reading requested
* @arg @ref USBPD_CORE_DATATYPE_SNK_PDO Sink PDO reading requested
* @param Ptr Pointer on address where PDO values should be written (u8 pointer)
* @param Size Pointer on nb of u32 written by PWR_IF (nb of PDOs)
* @retval None
*/
void USBPD_PWR_IF_GetPortPDOs(uint8_t PortNum, USBPD_CORE_DataInfoType_TypeDef DataId, uint8_t *Ptr, uint32_t *Size);
/**
* @brief Find out SRC PDO pointed out by a position provided in a Request DO (from Sink).
* @param PortNum Port number
* @param RdoPosition RDO Position in list of provided PDO
* @param Pdo Pointer on PDO value pointed out by RDO position (u32 pointer)
* @retval Status of search
* USBPD_OK : Src PDO found for requested DO position (output Pdo parameter is set)
* USBPD_FAIL : Position is not compliant with current Src PDO for this port (no corresponding PDO value)
*/
USBPD_StatusTypeDef USBPD_PWR_IF_SearchRequestedPDO(uint8_t PortNum, uint32_t RdoPosition, uint32_t *Pdo);
/**
* @brief the function is called in case of critical issue is detected to switch in safety mode.
* @retval None
*/
void USBPD_PWR_IF_Alarm(void);
/**
* @brief Function to check validity between SNK PDO and power user settings
* @param PortNum Port number
* @retval USBPD Status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_CheckUpdateSNKPower(uint8_t PortNum);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBPD_PW_IF_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,236 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_pwr_user.h
* @author MCD Application Team
* @brief Header file for usbpd_pwr_user.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USBPD_PWR_USER_H_
#define __USBPD_PWR_USER_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup POWER
* @{
*/
/** @defgroup POWER_Exported_Types Exported Types
* @{
*/
/**
* @brief POWER Status
*/
typedef enum
{
PWR_OK = 0,
PWR_ERROR
} PWR_StatusTypeDef;
/**
* @brief Power role
*/
typedef enum
{
POWER_ROLE_SOURCE = 0,
POWER_ROLE_SINK,
POWER_ROLE_DUAL
} PWR_PowerRoleTypeDef;
/**
* @brief Voltage control mode
*/
typedef enum
{
DCDC_CTRL_MODE_UNKNOWN = 0,
DCDC_CTRL_MODE_GPIO,
DCDC_CTRL_MODE_PWM,
} PWR_DCDCCtrlModeTypeDef;
/**
* @brief VBUS connection status
*/
typedef enum
{
VBUS_CONNECTED = 0,
VBUS_NOT_CONNECTED
} PWR_VBUSConnectionStatusTypeDef;
/**
* @brief VBUS Detection Callback
*/
typedef void PWR_VBUSDetectCallbackFunc(uint32_t PortId,
PWR_VBUSConnectionStatusTypeDef VBUSConnectionStatus);
/**
* @}
*/
/** @defgroup POWER_Exported_Constants Exported Constants
* @{
*/
/**
* @brief Number of TypeC ports
*/
#define PWR_TYPEC_PORT_NB 2
/**
* @brief Type-C port identifier
*/
#define TYPE_C_PORT_1 0
#define TYPE_C_PORT_2 1
/**
* @brief CC pin identifier
*/
#define TYPE_C_CC1 1
#define TYPE_C_CC2 2
/**
* @brief VBUS disconnection threshold values (in mV)
*/
#define BSP_PWR_HIGH_VBUS_THRESHOLD (4500)
#define BSP_PWR_LOW_VBUS_THRESHOLD (800)
/**
* @brief VBUS discharge parameters
*/
#define BSP_PWR_DISCHARGE_MARGIN (500)
#define BSP_PWR_DISCHARGE_TIME (6)
/**
* @brief Calibration settings
*/
#define BSP_PWR_DCDC_PRECISION (40) /* DCDC output precision set to 40mV (Noise)*/
#define BSP_PWR_CALIBRATION_ENABLED (1)
#define BSP_PWR_CALIBRATION_DISABLED (0)
/**
* @brief Standard VBUS voltage levels
*/
#define BSP_PWR_VBUS_5V 5000
#define BSP_PWR_VBUS_9V 9000
#define BSP_PWR_VBUS_15V 15000
/**
* @brief power timeout
*/
#define BSP_PWR_TIMEOUT_PDO 250u
#define BSP_PWR_TIMEOUT_APDO 25u
/**
* @brief Invalid value set during issue with voltage setting
*/
#define BSP_PWR_INVALID_VALUE 0xFFFFFFFFu
/**
* @}
*/
/** @defgroup POWER_Exported_Functions Exported Functions
* @{
*/
PWR_StatusTypeDef BSP_PWR_VBUSInit(uint32_t PortId);
PWR_StatusTypeDef BSP_PWR_VBUSDeInit(uint32_t PortId);
PWR_StatusTypeDef BSP_PWR_VBUSOn(uint32_t PortId);
PWR_StatusTypeDef BSP_PWR_VBUSOff(uint32_t PortId);
PWR_StatusTypeDef BSP_PWR_VBUSSetVoltage_Fixed(uint32_t PortNum,
uint32_t VbusTargetInmv,
uint32_t OperatingCurrent,
uint32_t MaxOperatingCurrent);
PWR_StatusTypeDef BSP_PWR_VBUSSetVoltage_Variable(uint32_t PortNum,
uint32_t VbusTargetMaxInmv,
uint32_t VbusTargetMinInmv,
uint32_t OperatingCurrent,
uint32_t MaxOperatingCurrent);
PWR_StatusTypeDef BSP_PWR_VBUSSetVoltage_Battery(uint32_t PortId,
uint32_t VbusTargetMin,
uint32_t VbusTargetMax,
uint32_t OperatingPower,
uint32_t MaxOperatingPower);
PWR_StatusTypeDef BSP_PWR_VBUSSetVoltage_APDO(uint32_t PortId,
uint32_t VbusTargetInmv,
uint32_t OperatingCurrent,
int32_t Delta);
uint32_t BSP_PWR_VBUSGetVoltage(uint32_t PortId);
int32_t BSP_PWR_VBUSGetCurrent(uint32_t PortId);
PWR_StatusTypeDef BSP_PWR_VCONNInit(uint32_t PortId,
uint32_t CCPinId);
PWR_StatusTypeDef BSP_PWR_VCONNDeInit(uint32_t PortId,
uint32_t CCPinId);
PWR_StatusTypeDef BSP_PWR_VCONNOn(uint32_t PortId,
uint32_t CCPinId);
PWR_StatusTypeDef BSP_PWR_VCONNOff(uint32_t PortId,
uint32_t CCPinId);
void BSP_PWR_SetVBUSDisconnectionThreshold(uint32_t PortId,
uint32_t VoltageThreshold);
PWR_StatusTypeDef BSP_PWR_RegisterVBUSDetectCallback(uint32_t PortId,
PWR_VBUSDetectCallbackFunc * pfnVBUSDetectCallback);
uint8_t BSP_PWR_VBUSIsOn(uint32_t PortId);
uint8_t BSP_PWR_VCONNIsOn(uint32_t PortId,
uint32_t CCPinId);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __STM32G081B_EVAL_POWER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,61 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_vdm_user.h
* @author MCD Application Team
* @brief Header file for usbpd_vdm_user.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
#ifndef __USBPD_VDM_USER_H_
#define __USBPD_VDM_USER_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/** @addtogroup STM32_USBPD_APPLICATION
* @{
*/
/** @addtogroup STM32_USBPD_APPLICATION_VDM_USER
* @{
*/
/* Exported typedef ----------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
USBPD_StatusTypeDef USBPD_VDM_UserInit(uint8_t PortNum);
void USBPD_VDM_UserReset(uint8_t PortNum);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBPD_VDM_USER_H_ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/