Initial commit

This commit is contained in:
Jochen Friedrich 2021-01-01 14:06:20 +01:00
commit 66c5a26d69
1145 changed files with 938088 additions and 0 deletions

View file

@ -0,0 +1,61 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : app_freertos.c
* Description : Code for freertos applications
******************************************************************************
* @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 */
/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* USER CODE END FunctionPrototypes */
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
/* USER CODE END Application */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,622 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @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 */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
#include "usbpd.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
LPTIM_HandleTypeDef hlptim1;
osThreadId defaultTaskHandle;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void StartDefaultTask(void const * argument);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* USBPD initialisation ---------------------------------*/
MX_USBPD_Init();
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2)
{
}
/* HSI configuration and activation */
LL_RCC_HSI_Enable();
while(LL_RCC_HSI_IsReady() != 1)
{
}
/* Main PLL configuration and activation */
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 8, LL_RCC_PLLR_DIV_2);
LL_RCC_PLL_Enable();
LL_RCC_PLL_EnableDomain_SYS();
while(LL_RCC_PLL_IsReady() != 1)
{
}
/* Set AHB prescaler*/
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
/* Sysclk activation on the main PLL */
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}
/* Set APB1 prescaler*/
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
/* Update the time base */
if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
{
Error_Handler();
}
/* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
LL_SetSystemCoreClock(64000000);
LL_RCC_SetUSARTClockSource(LL_RCC_USART3_CLKSOURCE_PCLK1);
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM1_CLKSOURCE_PCLK1);
LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_SYSCLK);
}
/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5;
hadc1.Init.OversamplingMode = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_11;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
/**
* @brief LPTIM1 Initialization Function
* @param None
* @retval None
*/
void MX_LPTIM1_Init(void)
{
/* USER CODE BEGIN LPTIM1_Init 0 */
/* USER CODE END LPTIM1_Init 0 */
/* USER CODE BEGIN LPTIM1_Init 1 */
/* USER CODE END LPTIM1_Init 1 */
hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim1.Init.UltraLowPowerClock.Polarity = LPTIM_CLOCKPOLARITY_RISING;
hlptim1.Init.UltraLowPowerClock.SampleTime = LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
hlptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_EXTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_COMP1;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
if (HAL_LPTIM_Init(&hlptim1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN LPTIM1_Init 2 */
/* USER CODE END LPTIM1_Init 2 */
}
/**
* @brief UCPD1 Initialization Function
* @param None
* @retval None
*/
void MX_UCPD1_Init(void)
{
/* USER CODE BEGIN UCPD1_Init 0 */
/* USER CODE END UCPD1_Init 0 */
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UCPD1);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
/**UCPD1 GPIO Configuration
PB15 ------> UCPD1_CC2
PA8 ------> UCPD1_CC1
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_8;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* UCPD1 DMA Init */
/* UCPD1_RX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_4, LL_DMAMUX_REQ_UCPD1_RX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PRIORITY_LOW);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MDATAALIGN_BYTE);
/* UCPD1_TX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_2, LL_DMAMUX_REQ_UCPD1_TX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_LOW);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
/* UCPD1 interrupt Init */
NVIC_SetPriority(USB_UCPD1_2_IRQn, 3);
NVIC_EnableIRQ(USB_UCPD1_2_IRQn);
/* USER CODE BEGIN UCPD1_Init 1 */
/* USER CODE END UCPD1_Init 1 */
/* USER CODE BEGIN UCPD1_Init 2 */
/* USER CODE END UCPD1_Init 2 */
}
/**
* @brief USART3 Initialization Function
* @param None
* @retval None
*/
void MX_USART3_UART_Init(void)
{
/* USER CODE BEGIN USART3_Init 0 */
/* USER CODE END USART3_Init 0 */
LL_USART_InitTypeDef USART_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
/**USART3 GPIO Configuration
PC10 ------> USART3_TX
PC11 ------> USART3_RX
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_11;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USART3 DMA Init */
/* USART3_TX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_7, LL_DMAMUX_REQ_USART3_TX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_7, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_7, LL_DMA_PRIORITY_LOW);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_7, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_7, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_7, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_7, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_7, LL_DMA_MDATAALIGN_BYTE);
/* USART3 interrupt Init */
NVIC_SetPriority(USART3_4_5_6_LPUART1_IRQn, 3);
NVIC_EnableIRQ(USART3_4_5_6_LPUART1_IRQn);
/* USER CODE BEGIN USART3_Init 1 */
/* USER CODE END USART3_Init 1 */
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
USART_InitStruct.BaudRate = 921600;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(USART3, &USART_InitStruct);
LL_USART_SetTXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
LL_USART_SetRXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
LL_USART_DisableFIFO(USART3);
LL_USART_ConfigAsyncMode(USART3);
/* USER CODE BEGIN WKUPType USART3 */
/* USER CODE END WKUPType USART3 */
LL_USART_Enable(USART3);
/* Polling USART3 initialisation */
while((!(LL_USART_IsActiveFlag_TEACK(USART3))) || (!(LL_USART_IsActiveFlag_REACK(USART3))))
{
}
/* USER CODE BEGIN USART3_Init 2 */
/* USER CODE END USART3_Init 2 */
}
/**
* Enable DMA controller clock
*/
void MX_DMA_Init(void)
{
/* Init with LL driver */
/* DMA controller clock enable */
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* DMA1_Channel2_3_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 3);
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
/* DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn, 3);
NVIC_EnableIRQ(DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
void MX_GPIO_Init(void)
{
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOD);
/**/
LL_GPIO_ResetOutputPin(VCONN_EN2_GPIO_Port, VCONN_EN2_Pin);
/**/
LL_GPIO_ResetOutputPin(VCONN_DISCHARGE2_GPIO_Port, VCONN_DISCHARGE2_Pin);
/**/
LL_GPIO_ResetOutputPin(VBUS_DISCHARGE1_GPIO_Port, VBUS_DISCHARGE1_Pin);
/**/
LL_GPIO_ResetOutputPin(VBUS_DISCHARGE2_GPIO_Port, VBUS_DISCHARGE2_Pin);
/**/
LL_GPIO_ResetOutputPin(SOURCE_EN_GPIO_Port, SOURCE_EN_Pin);
/**/
LL_GPIO_ResetOutputPin(VCONN_EN1_GPIO_Port, VCONN_EN1_Pin);
/**/
GPIO_InitStruct.Pin = VCONN_EN2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(VCONN_EN2_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = VCONN_DISCHARGE2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(VCONN_DISCHARGE2_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = VBUS_DISCHARGE1_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(VBUS_DISCHARGE1_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = VBUS_DISCHARGE2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(VBUS_DISCHARGE2_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = SOURCE_EN_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(SOURCE_EN_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = VCONN_EN1_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(VCONN_EN1_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/* USER CODE BEGIN Header_StartDefaultTask */
/**
* @brief Function implementing the defaultTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const * argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END 5 */
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,255 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g0xx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @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 */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern DMA_HandleTypeDef hdma_adc1;
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0);
/** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
*/
HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD2_STROBE);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/**
* @brief ADC MSP Initialization
* This function configures the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_ADC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**ADC1 GPIO Configuration
PA3 ------> ADC1_IN3
PB10 ------> ADC1_IN11
PB11 ------> ADC1_IN15
PB12 ------> ADC1_IN16
*/
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* ADC1 DMA Init */
/* ADC1 Init */
hdma_adc1.Instance = DMA1_Channel1;
hdma_adc1.Init.Request = DMA_REQUEST_ADC1;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_adc1.Init.Mode = DMA_NORMAL;
hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
/* ADC1 interrupt Init */
HAL_NVIC_SetPriority(ADC1_COMP_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(ADC1_COMP_IRQn);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
/**
* @brief ADC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC_CLK_DISABLE();
/**ADC1 GPIO Configuration
PA3 ------> ADC1_IN3
PB10 ------> ADC1_IN11
PB11 ------> ADC1_IN15
PB12 ------> ADC1_IN16
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
/* ADC1 DMA DeInit */
HAL_DMA_DeInit(hadc->DMA_Handle);
/* ADC1 interrupt DeInit */
HAL_NVIC_DisableIRQ(ADC1_COMP_IRQn);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/**
* @brief LPTIM MSP Initialization
* This function configures the hardware resources used in this example
* @param hlptim: LPTIM handle pointer
* @retval None
*/
void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef* hlptim)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hlptim->Instance==LPTIM1)
{
/* USER CODE BEGIN LPTIM1_MspInit 0 */
/* USER CODE END LPTIM1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_LPTIM1_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**LPTIM1 GPIO Configuration
PC2 ------> LPTIM1_IN2
*/
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_LPTIM1;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN LPTIM1_MspInit 1 */
/* USER CODE END LPTIM1_MspInit 1 */
}
}
/**
* @brief LPTIM MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hlptim: LPTIM handle pointer
* @retval None
*/
void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef* hlptim)
{
if(hlptim->Instance==LPTIM1)
{
/* USER CODE BEGIN LPTIM1_MspDeInit 0 */
/* USER CODE END LPTIM1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_LPTIM1_CLK_DISABLE();
/**LPTIM1 GPIO Configuration
PC2 ------> LPTIM1_IN2
*/
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2);
/* USER CODE BEGIN LPTIM1_MspDeInit 1 */
/* USER CODE END LPTIM1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,222 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g0xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @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 */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32g0xx_it.h"
#include "FreeRTOS.h"
#include "task.h"
#include "usbpd.h"
#include "tracer_emb.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_adc1;
extern ADC_HandleTypeDef hadc1;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M0+ Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
#endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
}
#endif /* INCLUDE_xTaskGetSchedulerState */
USBPD_DPM_TimerCounter();
/* USER CODE BEGIN SysTick_IRQn 1 */
#if defined(_GUI_INTERFACE)
GUI_TimerCounter();
#endif /* _GUI_INTERFACE */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32G0xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32g0xx.s). */
/******************************************************************************/
/**
* @brief This function handles USB, UCPD1 and UCPD2 global interrupts.
*/
void USB_UCPD1_2_IRQHandler(void)
{
/* USER CODE BEGIN USB_UCPD1_2_IRQn 0 */
/* USER CODE END USB_UCPD1_2_IRQn 0 */
USBPD_PORT0_IRQHandler();
/* USER CODE BEGIN USB_UCPD1_2_IRQn 1 */
/* USER CODE END USB_UCPD1_2_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel 1 interrupt.
*/
void DMA1_Channel1_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
/* USER CODE END DMA1_Channel1_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_adc1);
/* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
/* USER CODE END DMA1_Channel1_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel 2 and channel 3 interrupts.
*/
void DMA1_Channel2_3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel2_3_IRQn 0 */
/* USER CODE END DMA1_Channel2_3_IRQn 0 */
/* USER CODE BEGIN DMA1_Channel2_3_IRQn 1 */
/* USER CODE END DMA1_Channel2_3_IRQn 1 */
}
/**
* @brief This function handles DMA1 Ch4 to Ch7, DMA2 Ch1 to Ch5 and DMAMUX1 Overrun Interrupts.
*/
void DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn 0 */
/* USER CODE END DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn 0 */
TRACER_EMB_IRQHandlerDMA();
/* USER CODE BEGIN DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn 1 */
/* USER CODE END DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQn 1 */
}
/**
* @brief This function handles ADC1, COMP1,COMP2, COMP3 Interrupts (combined with EXTI 17 & 18).
*/
void ADC1_COMP_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_COMP_IRQn 0 */
/* USER CODE END ADC1_COMP_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
/* USER CODE BEGIN ADC1_COMP_IRQn 1 */
/* USER CODE END ADC1_COMP_IRQn 1 */
}
/**
* @brief This function handles USART3, USART4, USART5, USART6, LPUART1 globlal Interrupts (combined with EXTI 28).
*/
void USART3_4_5_6_LPUART1_IRQHandler(void)
{
/* USER CODE BEGIN USART3_4_5_6_LPUART1_IRQn 0 */
/* USER CODE END USART3_4_5_6_LPUART1_IRQn 0 */
TRACER_EMB_IRQHandlerUSART();
/* USER CODE BEGIN USART3_4_5_6_LPUART1_IRQn 1 */
/* USER CODE END USART3_4_5_6_LPUART1_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,290 @@
/**
******************************************************************************
* @file system_stm32g0xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M0+ Device Peripheral Access Layer System Source File
*
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32g0xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* After each device reset the HSI (8 MHz then 16 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32g0xx.s" file, to
* configure the system clock before to branch to main program.
*
* This file configures the system clock as follows:
*=============================================================================
*-----------------------------------------------------------------------------
* System Clock source | HSI
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 16000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 16000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB Prescaler | 1
*-----------------------------------------------------------------------------
* HSI Division factor | 1
*-----------------------------------------------------------------------------
* PLL_M | 1
*-----------------------------------------------------------------------------
* PLL_N | 8
*-----------------------------------------------------------------------------
* PLL_P | 7
*-----------------------------------------------------------------------------
* PLL_Q | 2
*-----------------------------------------------------------------------------
* PLL_R | 2
*-----------------------------------------------------------------------------
* Require 48MHz for RNG | Disabled
*-----------------------------------------------------------------------------
*=============================================================================
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Apache License, Version 2.0,
* 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/Apache-2.0
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32g0xx_system
* @{
*/
/** @addtogroup STM32G0xx_System_Private_Includes
* @{
*/
#include "stm32g0xx.h"
#if !defined (HSE_VALUE)
#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
#if !defined (LSI_VALUE)
#define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/
#endif /* LSI_VALUE */
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/
#endif /* LSE_VALUE */
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Defines
* @{
*/
/************************* Miscellaneous Configuration ************************/
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x0U /*!< Vector Table base offset field.
This value must be a multiple of 0x100. */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Variables
* @{
*/
/* The SystemCoreClock variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = 16000000UL;
const uint32_t AHBPrescTable[16UL] = {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL, 6UL, 7UL, 8UL, 9UL};
const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL};
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32G0xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) / HSI division factor
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
*
* - If SYSCLK source is LSI, SystemCoreClock will contain the LSI_VALUE
*
* - If SYSCLK source is LSE, SystemCoreClock will contain the LSE_VALUE
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
*
* (**) HSI_VALUE is a constant defined in stm32g0xx_hal_conf.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (***) HSE_VALUE is a constant defined in stm32g0xx_hal_conf.h file (default value
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
* frequency of the crystal used. Otherwise, this function may
* have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
*
* @param None
* @retval None
*/
void SystemCoreClockUpdate(void)
{
uint32_t tmp;
uint32_t pllvco;
uint32_t pllr;
uint32_t pllsource;
uint32_t pllm;
uint32_t hsidiv;
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case RCC_CFGR_SWS_0: /* HSE used as system clock */
SystemCoreClock = HSE_VALUE;
break;
case (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0): /* LSI used as system clock */
SystemCoreClock = LSI_VALUE;
break;
case RCC_CFGR_SWS_2: /* LSE used as system clock */
SystemCoreClock = LSE_VALUE;
break;
case RCC_CFGR_SWS_1: /* PLL used as system clock */
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
SYSCLK = PLL_VCO / PLLR
*/
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> RCC_PLLCFGR_PLLM_Pos) + 1UL;
if(pllsource == 0x03UL) /* HSE used as PLL clock source */
{
pllvco = (HSE_VALUE / pllm);
}
else /* HSI used as PLL clock source */
{
pllvco = (HSI_VALUE / pllm);
}
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos);
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL);
SystemCoreClock = pllvco/pllr;
break;
case 0x00000000U: /* HSI used as system clock */
default: /* HSI used as system clock */
hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV))>> RCC_CR_HSIDIV_Pos));
SystemCoreClock = (HSI_VALUE/hsidiv);
break;
}
/* Compute HCLK clock frequency --------------------------------------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,107 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd.c
* @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 */
/* Includes ------------------------------------------------------------------*/
#include "usbpd.h"
#include "gui_api.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* Private variables ---------------------------------------------------------*/
const uint8_t HWBoardVersionName[] = "STM32G0C1E-EV";
const uint8_t PDTypeName[] = "MB1581B";
/* Private functions ---------------------------------------------------------*/
static const uint8_t* GetHWBoardVersionName(void);
static const uint8_t* GetPDTypeName(void);
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* USBPD init function */
void MX_USBPD_Init(void)
{
/* Global Init of USBPD HW */
USBPD_HW_IF_GlobalHwInit();
/* Initialize the Device Policy Manager */
if (USBPD_OK != USBPD_DPM_InitCore())
{
while(1);
}
/* Initialize GUI before retrieving PDO from RAM */
GUI_Init(GetHWBoardVersionName, GetPDTypeName, HW_IF_PWR_GetVoltage, HW_IF_PWR_GetCurrent);
/* Initialise the DPM application */
if (USBPD_OK != USBPD_DPM_UserInit())
{
while(1);
}
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
if (USBPD_OK != USBPD_DPM_InitOS())
{
while(1);
}
/* USER CODE BEGIN EnableIRQ */
/* Enable IRQ which has been disabled by FreeRTOS services */
__enable_irq();
/* USER CODE END EnableIRQ */
}
/**
* @brief This method returns HW board version name
* @retval HW Board version name
*/
static const uint8_t* GetHWBoardVersionName(void)
{
return HWBoardVersionName;
}
/**
* @brief This method returns HW PD Type name
* @retval HW Board version name
*/
static const uint8_t* GetPDTypeName(void)
{
return PDTypeName;
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -0,0 +1,496 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_dpm_core.c
* @author MCD Application Team
* @brief USBPD dpm core 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 __USBPD_DPM_CORE_C
/* Includes ------------------------------------------------------------------*/
#include "usbpd_core.h"
#include "usbpd_trace.h"
#include "usbpd_dpm_core.h"
#include "usbpd_dpm_user.h"
#include "usbpd_dpm_conf.h"
#include "cmsis_os.h"
#if (osCMSIS >= 0x20000U)
#include "task.h"
#endif /* osCMSIS >= 0x20000U */
/* Generic STM32 prototypes */
extern uint32_t HAL_GetTick(void);
/* Private function prototypes -----------------------------------------------*/
#if (osCMSIS < 0x20000U)
void USBPD_PE_Task(void const *argument);
void USBPD_CAD_Task(void const *argument);
#else /* osCMSIS >= 0x20000U */
void USBPD_PE_Task_P0(void *argument);
void USBPD_PE_Task_P1(void *argument);
static void PE_Task(uint32_t PortNum);
void USBPD_CAD_Task(void *argument);
#endif /* osCMSIS < 0x20000U */
/* Private typedef -----------------------------------------------------------*/
#if (osCMSIS < 0x20000U)
#define DPM_STACK_SIZE_ADDON_FOR_CMSIS 1
#else
#define DPM_STACK_SIZE_ADDON_FOR_CMSIS 4
#endif /* osCMSIS < 0x20000U */
#define FREERTOS_PE_PRIORITY osPriorityAboveNormal
#define FREERTOS_PE_STACK_SIZE (200 * DPM_STACK_SIZE_ADDON_FOR_CMSIS)
#define FREERTOS_CAD_PRIORITY osPriorityRealtime
#define FREERTOS_CAD_STACK_SIZE (300 * DPM_STACK_SIZE_ADDON_FOR_CMSIS)
#if (osCMSIS < 0x20000U)
osThreadDef(PE_0, USBPD_PE_Task, FREERTOS_PE_PRIORITY, 0, FREERTOS_PE_STACK_SIZE);
osThreadDef(PE_1, USBPD_PE_Task, FREERTOS_PE_PRIORITY, 0, FREERTOS_PE_STACK_SIZE);
osMessageQDef(queuePE, 1, uint16_t);
osThreadDef(CAD, USBPD_CAD_Task, FREERTOS_CAD_PRIORITY, 0, FREERTOS_CAD_STACK_SIZE);
osMessageQDef(queueCAD, 2, uint16_t);
#else /* osCMSIS >= 0x20000U */
osThreadAttr_t PE0_Thread_Atrr = {
.name = "PE_0",
.priority = FREERTOS_PE_PRIORITY, /*osPriorityAboveNormal,*/
.stack_size = FREERTOS_PE_STACK_SIZE
};
osThreadAttr_t PE1_Thread_Atrr = {
.name = "PE_1",
.priority = FREERTOS_PE_PRIORITY,
.stack_size = FREERTOS_PE_STACK_SIZE
};
osThreadAttr_t CAD_Thread_Atrr = {
.name = "CAD",
.priority = FREERTOS_CAD_PRIORITY, /*osPriorityRealtime,*/
.stack_size = FREERTOS_CAD_STACK_SIZE
};
#endif /* osCMSIS < 0x20000U */
/* Private define ------------------------------------------------------------*/
#if (osCMSIS < 0x20000U)
#define OSTHREAD_PE(__PORT__) (((__PORT__) == USBPD_PORT_0) ? osThread(PE_0) : osThread(PE_1))
#else
#define OSTHREAD_PE(__PORT__) (((__PORT__) == USBPD_PORT_0) ? USBPD_PE_Task_P0 : USBPD_PE_Task_P1)
#define OSTHREAD_PE_ATTR(__PORT__) (((__PORT__) == USBPD_PORT_0) ? &PE0_Thread_Atrr : &PE1_Thread_Atrr)
#endif /* osCMSIS < 0x20000U */
/* Private macro -------------------------------------------------------------*/
#define CHECK_PE_FUNCTION_CALL(_function_) _retr = _function_; \
if(USBPD_OK != _retr) {return _retr;}
#define CHECK_CAD_FUNCTION_CALL(_function_) if(USBPD_CAD_OK != _function_) {return USBPD_ERROR;}
#if defined(_DEBUG_TRACE)
#define DPM_CORE_DEBUG_TRACE(_PORTNUM_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, _PORTNUM_, 0u, (uint8_t *)(__MESSAGE__), sizeof(__MESSAGE__) - 1u);
#else
#define DPM_CORE_DEBUG_TRACE(_PORTNUM_, __MESSAGE__)
#endif /* _DEBUG_TRACE */
/* Private variables ---------------------------------------------------------*/
static osThreadId DPM_PEThreadId_Table[USBPD_PORT_COUNT];
static osMessageQId CADQueueId;
static osMessageQId PEQueueId[USBPD_PORT_COUNT];
USBPD_ParamsTypeDef DPM_Params[USBPD_PORT_COUNT];
/* Private function prototypes -----------------------------------------------*/
static void USBPD_PE_TaskWakeUp(uint8_t PortNum);
static void DPM_ManageAttachedState(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc);
void USBPD_DPM_CADCallback(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc);
static void USBPD_DPM_CADTaskWakeUp(void);
/**
* @brief Initialize the core stack (port power role, PWR_IF, CAD and PE Init procedures)
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_DPM_InitCore(void)
{
/* variable to get dynamique memory allocated by usbpd stack */
uint32_t stack_dynamemsize;
USBPD_StatusTypeDef _retr = USBPD_OK;
static const USBPD_PE_Callbacks dpmCallbacks =
{
USBPD_DPM_SetupNewPower,
USBPD_DPM_HardReset,
NULL,
USBPD_DPM_Notification,
USBPD_DPM_ExtendedMessageReceived,
USBPD_DPM_GetDataInfo,
USBPD_DPM_SetDataInfo,
USBPD_DPM_EvaluateRequest,
NULL,
NULL,
USBPD_PE_TaskWakeUp,
#if defined(_VCONN_SUPPORT)
USBPD_DPM_EvaluateVconnSwap,
USBPD_DPM_PE_VconnPwr,
#else
NULL,
NULL,
#endif /* _VCONN_SUPPORT */
NULL,
USBPD_DPM_EvaluateDataRoleSwap,
USBPD_DPM_IsPowerReady
};
static const USBPD_CAD_Callbacks CAD_cbs = { USBPD_DPM_CADCallback, USBPD_DPM_CADTaskWakeUp };
/* Check the lib selected */
if (USBPD_TRUE != USBPD_PE_CheckLIB(_LIB_ID))
{
return USBPD_ERROR;
}
/* to get how much memory are dynamically allocated by the stack
the memory return is corresponding to 2 ports so if the application
managed only one port divide the value return by 2 */
stack_dynamemsize = USBPD_PE_GetMemoryConsumption();
/* done to avoid warning */
(void)stack_dynamemsize;
/* Variable to be sure that DPM is correctly initialized */
DPM_Params[USBPD_PORT_0].DPM_Initialized = USBPD_FALSE;
#if USBPD_PORT_COUNT == 2
DPM_Params[USBPD_PORT_1].DPM_Initialized = USBPD_FALSE;
#endif /* USBPD_PORT_COUNT == 2 */
/* check the stack settings */
DPM_Params[USBPD_PORT_0].PE_SpecRevision = DPM_Settings[USBPD_PORT_0].PE_SpecRevision;
DPM_Params[USBPD_PORT_0].PE_PowerRole = DPM_Settings[USBPD_PORT_0].PE_DefaultRole;
DPM_Params[USBPD_PORT_0].PE_SwapOngoing = USBPD_FALSE;
DPM_Params[USBPD_PORT_0].ActiveCCIs = CCNONE;
DPM_Params[USBPD_PORT_0].VconnCCIs = CCNONE;
DPM_Params[USBPD_PORT_0].VconnStatus = USBPD_FALSE;
#if USBPD_PORT_COUNT == 2
DPM_Params[USBPD_PORT_1].PE_SpecRevision = DPM_Settings[USBPD_PORT_1].PE_SpecRevision;
DPM_Params[USBPD_PORT_1].PE_PowerRole = DPM_Settings[USBPD_PORT_1].PE_DefaultRole;
DPM_Params[USBPD_PORT_1].PE_SwapOngoing = USBPD_FALSE;
DPM_Params[USBPD_PORT_1].ActiveCCIs = CCNONE;
DPM_Params[USBPD_PORT_1].VconnCCIs = CCNONE;
DPM_Params[USBPD_PORT_1].VconnStatus = USBPD_FALSE;
#endif /* USBPD_PORT_COUNT == 2 */
/* Initialise the TRACE */
USBPD_TRACE_Init();
/* CAD SET UP : Port 0 */
CHECK_CAD_FUNCTION_CALL(USBPD_CAD_Init(USBPD_PORT_0, (USBPD_CAD_Callbacks *)&CAD_cbs, (USBPD_SettingsTypeDef *)&DPM_Settings[USBPD_PORT_0], &DPM_Params[USBPD_PORT_0]));
#if USBPD_PORT_COUNT == 2
CHECK_CAD_FUNCTION_CALL(USBPD_CAD_Init(USBPD_PORT_1, (USBPD_CAD_Callbacks *)&CAD_cbs, (USBPD_SettingsTypeDef *)&DPM_Settings[USBPD_PORT_1], &DPM_Params[USBPD_PORT_1]));
#endif /* USBPD_PORT_COUNT == 2 */
/* PE SET UP : Port 0 */
CHECK_PE_FUNCTION_CALL(USBPD_PE_Init(USBPD_PORT_0, (USBPD_SettingsTypeDef *)&DPM_Settings[USBPD_PORT_0], &DPM_Params[USBPD_PORT_0], &dpmCallbacks));
#if USBPD_PORT_COUNT == 2
CHECK_PE_FUNCTION_CALL(USBPD_PE_Init(USBPD_PORT_1, (USBPD_SettingsTypeDef *)&DPM_Settings[USBPD_PORT_1], &DPM_Params[USBPD_PORT_1], &dpmCallbacks));
#endif /* USBPD_PORT_COUNT == 2 */
/* DPM is correctly initialized */
DPM_Params[USBPD_PORT_0].DPM_Initialized = USBPD_TRUE;
#if USBPD_PORT_COUNT == 2
DPM_Params[USBPD_PORT_1].DPM_Initialized = USBPD_TRUE;
#endif /* USBPD_PORT_COUNT == 2 */
/* Enable CAD on Port 0 */
USBPD_CAD_PortEnable(USBPD_PORT_0, USBPD_CAD_ENABLE);
#if USBPD_PORT_COUNT == 2
USBPD_CAD_PortEnable(USBPD_PORT_1, USBPD_CAD_ENABLE);
#endif /* USBPD_PORT_COUNT == 2 */
return _retr;
}
/**
* @brief Initialize the OS parts (task, queue,... )
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_DPM_InitOS(void)
{
#if (osCMSIS < 0x20000U)
CADQueueId = osMessageCreate(osMessageQ(queueCAD), NULL);
if (osThreadCreate(osThread(CAD), NULL) == NULL)
#else
CADQueueId = osMessageQueueNew (2, sizeof(uint16_t), NULL);
if (NULL == osThreadNew(USBPD_CAD_Task, &CADQueueId, &CAD_Thread_Atrr))
#endif /* osCMSIS < 0x20000U */
{
return USBPD_ERROR;
}
/* Create the queue corresponding to PE task */
#if (osCMSIS < 0x20000U)
PEQueueId[0] = osMessageCreate(osMessageQ(queuePE), NULL);
#if USBPD_PORT_COUNT == 2
PEQueueId[1] = osMessageCreate(osMessageQ(queuePE), NULL);
#endif /* USBPD_PORT_COUNT == 2 */
#else
PEQueueId[0] = osMessageQueueNew (1, sizeof(uint16_t), NULL);
#if USBPD_PORT_COUNT == 2
PEQueueId[1] = osMessageQueueNew (1, sizeof(uint16_t), NULL);
#endif /* USBPD_PORT_COUNT == 2 */
#endif /* osCMSIS < 0x20000U */
/* PE task to be created on attachment */
DPM_PEThreadId_Table[USBPD_PORT_0] = NULL;
#if USBPD_PORT_COUNT == 2
DPM_PEThreadId_Table[USBPD_PORT_1] = NULL;
#endif /* USBPD_PORT_COUNT == 2 */
return USBPD_OK;
}
/**
* @brief Initialize the OS parts (port power role, PWR_IF, CAD and PE Init procedures)
* @retval None
*/
void USBPD_DPM_Run(void)
{
#if (osCMSIS >= 0x20000U)
osKernelInitialize();
#endif /* osCMSIS >= 0x20000U */
osKernelStart();
}
/**
* @brief Initialize DPM (port power role, PWR_IF, CAD and PE Init procedures)
* @retval USBPD status
*/
void USBPD_DPM_TimerCounter(void)
{
/* Call PE/PRL timers functions only if DPM is initialized */
if (USBPD_TRUE == DPM_Params[USBPD_PORT_0].DPM_Initialized)
{
USBPD_DPM_UserTimerCounter(USBPD_PORT_0);
USBPD_PE_TimerCounter(USBPD_PORT_0);
USBPD_PRL_TimerCounter(USBPD_PORT_0);
}
#if USBPD_PORT_COUNT==2
if (USBPD_TRUE == DPM_Params[USBPD_PORT_1].DPM_Initialized)
{
USBPD_DPM_UserTimerCounter(USBPD_PORT_1);
USBPD_PE_TimerCounter(USBPD_PORT_1);
USBPD_PRL_TimerCounter(USBPD_PORT_1);
}
#endif /* USBPD_PORT_COUNT == 2 */
}
/**
* @brief WakeUp PE task
* @param PortNum port number
* @retval None
*/
static void USBPD_PE_TaskWakeUp(uint8_t PortNum)
{
#if (osCMSIS < 0x20000U)
(void)osMessagePut(PEQueueId[PortNum], 0xFFFF, 0);
#else
uint32_t event = 0xFFFFU;
(void)osMessageQueuePut(PEQueueId[PortNum], &event, 0U, 0U);
#endif /* osCMSIS < 0x20000U */
}
/**
* @brief WakeUp CAD task
* @retval None
*/
static void USBPD_DPM_CADTaskWakeUp(void)
{
#if (osCMSIS < 0x20000U)
(void)osMessagePut(CADQueueId, 0xFFFF, 0);
#else
uint32_t event = 0xFFFFU;
(void)osMessageQueuePut(CADQueueId, &event, 0U, 0U);
#endif /* osCMSIS < 0x20000U */
}
#if (osCMSIS < 0x20000U)
/**
* @brief Main task for PE layer
* @param argument Not used
* @retval None
*/
void USBPD_PE_Task(void const *argument)
{
uint8_t _port = (uint32_t)argument;
uint32_t _timing;
for(;;)
{
_timing = USBPD_PE_StateMachine_SRC(_port);
osMessageGet(PEQueueId[_port],_timing);
}
}
#else /* osCMSIS > 0x20000U */
/**
* @brief Main task for PE layer on Port0
* @param argument Not used
* @retval None
*/
void USBPD_PE_Task_P0(void *argument)
{
PE_Task(USBPD_PORT_0);
}
/**
* @brief Main task for PE layer on Port1
* @param argument Not used
* @retval None
*/
void USBPD_PE_Task_P1(void *argument)
{
PE_Task(USBPD_PORT_1);
}
/**
* @brief Main task for PE layer
* @param argument Not used
* @retval None
*/
static void PE_Task(uint32_t PortNum)
{
for (;;)
{
uint32_t event;
(void)osMessageQueueGet(PEQueueId[PortNum], &event, NULL,
USBPD_PE_StateMachine_SRC(PortNum));
}
}
#endif /* osCMSIS < 0x20000U */
/**
* @brief Main task for CAD layer
* @param argument Not used
* @retval None
*/
#if (osCMSIS < 0x20000U)
void USBPD_CAD_Task(void const *argument)
#else
void USBPD_CAD_Task(void *argument)
#endif /* osCMSIS < 0x20000U */
{
for (;;)
{
#if (osCMSIS < 0x20000U)
osMessageGet(CADQueueId, USBPD_CAD_Process());
#else
uint32_t event;
(void)osMessageQueueGet(CADQueueId, &event, NULL, USBPD_CAD_Process());
#endif /* osCMSIS < 0x20000U */
}
}
/**
* @brief CallBack reporting events on a specified port from CAD layer.
* @param PortNum The handle of the port
* @param State CAD state
* @param Cc The Communication Channel for the USBPD communication
* @retval None
*/
void USBPD_DPM_CADCallback(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc)
{
USBPD_TRACE_Add(USBPD_TRACE_CADEVENT, PortNum, (uint8_t)State, NULL, 0);
switch (State)
{
case USBPD_CAD_EVENT_ATTEMC :
{
#ifdef _VCONN_SUPPORT
DPM_Params[PortNum].VconnStatus = USBPD_TRUE;
#endif /* _VCONN_SUPPORT */
DPM_ManageAttachedState(PortNum, State, Cc);
#ifdef _VCONN_SUPPORT
DPM_CORE_DEBUG_TRACE(PortNum, "Note: VconnStatus=TRUE");
#endif /* _VCONN_SUPPORT */
break;
}
case USBPD_CAD_EVENT_ATTACHED :
DPM_ManageAttachedState(PortNum, State, Cc);
break;
case USBPD_CAD_EVENT_DETACHED :
case USBPD_CAD_EVENT_EMC :
{
/* The ufp is detached */
(void)USBPD_PE_IsCableConnected(PortNum, 0);
/* Terminate PE task */
if (DPM_PEThreadId_Table[PortNum] != NULL)
{
osThreadTerminate(DPM_PEThreadId_Table[PortNum]);
DPM_PEThreadId_Table[PortNum] = NULL;
}
DPM_Params[PortNum].PE_SwapOngoing = USBPD_FALSE;
DPM_Params[PortNum].ActiveCCIs = CCNONE;
DPM_Params[PortNum].PE_Power = USBPD_POWER_NO;
USBPD_DPM_UserCableDetection(PortNum, State);
#ifdef _VCONN_SUPPORT
DPM_Params[PortNum].VconnCCIs = CCNONE;
DPM_Params[PortNum].VconnStatus = USBPD_FALSE;
DPM_CORE_DEBUG_TRACE(PortNum, "Note: VconnStatus=FALSE");
#endif /* _VCONN_SUPPORT */
break;
}
default :
/* nothing to do */
break;
}
}
static void DPM_ManageAttachedState(uint8_t PortNum, USBPD_CAD_EVENT State, CCxPin_TypeDef Cc)
{
#ifdef _VCONN_SUPPORT
if (CC1 == Cc)
{
DPM_Params[PortNum].VconnCCIs = CC2;
}
if (CC2 == Cc)
{
DPM_Params[PortNum].VconnCCIs = CC1;
}
#endif /* _VCONN_SUPPORT */
DPM_Params[PortNum].ActiveCCIs = Cc;
(void)USBPD_PE_IsCableConnected(PortNum, 1);
USBPD_DPM_UserCableDetection(PortNum, State);
/* Create PE task */
if (DPM_PEThreadId_Table[PortNum] == NULL)
{
#if (osCMSIS < 0x20000U)
DPM_PEThreadId_Table[PortNum] = osThreadCreate(OSTHREAD_PE(PortNum), (void *)((uint32_t)PortNum));
#else
DPM_PEThreadId_Table[PortNum] = osThreadNew(OSTHREAD_PE(PortNum), NULL, OSTHREAD_PE_ATTR(PortNum));
#endif /* osCMSIS < 0x20000U */
if (DPM_PEThreadId_Table[PortNum] == NULL)
{
/* should not occur. May be an issue with FreeRTOS heap size too small */
while (1);
}
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,439 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_pwr_if.c
* @author MCD Application Team
* @brief This file contains power interface control functions.
******************************************************************************
* @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 __USBPD_PWR_IF_C
/* Includes ------------------------------------------------------------------*/
#include "usbpd_pwr_if.h"
#include "usbpd_hw_if.h"
#include "usbpd_dpm_core.h"
#include "usbpd_dpm_conf.h"
#include "usbpd_pdo_defs.h"
#include "usbpd_core.h"
#if defined(_TRACE)
#include "usbpd_trace.h"
#endif /* _TRACE */
#include "string.h"
#include "gui_api.h"
/* USER CODE BEGIN Include */
/* USER CODE END Include */
/** @addtogroup STM32_USBPD_APPLICATION
* @{
*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_TypeDef
* @{
*/
/* USER CODE BEGIN Private_Typedef */
/* USER CODE END Private_Typedef */
/**
* @}
*/
/* Private define ------------------------------------------------------------*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Defines
* @{
*/
/* USER CODE BEGIN Private_Define */
/* USER CODE END Private_Define */
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Macros
* @{
*/
#if defined(_TRACE)
#define PWR_IF_DEBUG_TRACE(_PORT_, __MESSAGE__) USBPD_TRACE_Add(USBPD_TRACE_DEBUG, (_PORT_), 0u, (uint8_t*)(__MESSAGE__), sizeof(__MESSAGE__) - 1u)
#else
#define PWR_IF_DEBUG_TRACE(_PORT_, __MESSAGE__)
#endif /* _TRACE */
/* USER CODE BEGIN Private_Macro */
/* USER CODE END Private_Macro */
/**
* @}
*/
/* Private variables ---------------------------------------------------------*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Variables
* @{
*/
/* USER CODE BEGIN Private_Variables */
/**
* @brief USBPD Port PDO Storage array declaration
*/
/**** PDO ****/
USBPD_PWR_Port_PDO_Storage_TypeDef PWR_Port_PDO_Storage[USBPD_PORT_COUNT];
/* USER CODE END Private_Variables */
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Functions
* @{
*/
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Prototypes */
/**
* @}
*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_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)
{
/* USER CODE BEGIN USBPD_PWR_IF_Init */
USBPD_StatusTypeDef _status = USBPD_OK;
/* Set links to PDO values and number for Port 0 (defined in PDO arrays in H file).
*/
PWR_Port_PDO_Storage[USBPD_PORT_0].SourcePDO.ListOfPDO = (uint32_t *) PORT0_PDO_ListSRC;
PWR_Port_PDO_Storage[USBPD_PORT_0].SourcePDO.NumberOfPDO = &USBPD_NbPDO[1];
return _status;
/* USER CODE END USBPD_PWR_IF_Init */
}
/**
* @brief Sets the required power profile, now it works only with Fixed ones
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_SetProfile(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_PWR_IF_SetProfile */
USBPD_StatusTypeDef _ret = USBPD_ERROR;
USBPD_PDO_TypeDef _pdo;
USBPD_SNKRDO_TypeDef _rdo;
_rdo.d32 = DPM_Ports[PortNum].DPM_RcvRequestDOMsg;
if (0 == PortNum)
_pdo.d32 = PORT0_PDO_ListSRC[0];
else
_pdo.d32 = PORT0_PDO_ListSRC[0];
if(PWR_OK == BSP_USBPD_PWR_VBUSSetVoltage_Fixed(PortNum, _pdo.SRCFixedPDO.VoltageIn50mVunits * 50,
(_rdo.FixedVariableRDO.OperatingCurrentIn10mAunits * 10),
(_rdo.FixedVariableRDO.MaxOperatingCurrent10mAunits * 10)))
{
_ret = USBPD_OK;
}
return _ret;
/* USER CODE END USBPD_PWR_IF_SetProfile */
}
/**
* @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)
{
/* USER CODE BEGIN USBPD_PWR_IF_SupplyReady */
return USBPD_ERROR;
/* USER CODE END USBPD_PWR_IF_SupplyReady */
}
/**
* @brief Enables VBUS power on a specified port
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSEnable(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_PWR_IF_VBUSEnable */
USBPD_StatusTypeDef _status = (USBPD_StatusTypeDef)HW_IF_PWR_Enable(PortNum, USBPD_ENABLE, CCNONE, USBPD_FALSE, USBPD_PORTPOWERROLE_SRC);
return _status;
/* USER CODE END USBPD_PWR_IF_VBUSEnable */
}
/**
* @brief Disable VBUS/VCONN the power on a specified port
* @param PortNum Port number
* @retval USBPD status
*/
USBPD_StatusTypeDef USBPD_PWR_IF_VBUSDisable(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_PWR_IF_VBUSDisable */
USBPD_StatusTypeDef _status = (USBPD_StatusTypeDef)HW_IF_PWR_Enable(PortNum, USBPD_DISABLE, CCNONE, USBPD_FALSE, USBPD_PORTPOWERROLE_SRC);
return _status;
/* USER CODE END USBPD_PWR_IF_VBUSDisable */
}
/**
* @brief Checks if the power on a specified port is enabled
* @param PortNum Port number
* @retval USBPD_ENABLE or USBPD_DISABLE
*/
USBPD_FunctionalState USBPD_PWR_IF_VBUSIsEnabled(uint8_t PortNum)
{
/* Get the Status of the port */
return USBPD_PORT_IsValid(PortNum) ? (USBPD_FunctionalState)HW_IF_PWR_VBUSIsEnabled(PortNum) : USBPD_DISABLE;
}
/**
* @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 USBPD_ERROR or USBPD_OK
*/
USBPD_StatusTypeDef USBPD_PWR_IF_ReadVA(uint8_t PortNum, uint16_t *pVoltage, uint16_t *pCurrent)
{
/* USER CODE BEGIN USBPD_PWR_IF_ReadVA */
return USBPD_ERROR;
/* USER CODE END USBPD_PWR_IF_ReadVA */
}
/**
* @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)
{
/* USER CODE BEGIN USBPD_PWR_IF_Enable_VConn */
return USBPD_ERROR;
/* USER CODE END USBPD_PWR_IF_Enable_VConn */
}
/**
* @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)
{
/* USER CODE BEGIN USBPD_PWR_IF_Disable_VConn */
return USBPD_ERROR;
/* USER CODE END USBPD_PWR_IF_Disable_VConn */
}
/**
* @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)
{
if (DataId == USBPD_CORE_DATATYPE_SRC_PDO)
{
*Size = USBPD_NbPDO[1];
memcpy(Ptr,PORT0_PDO_ListSRC, sizeof(uint32_t) * USBPD_NbPDO[1]);
}
/* USER CODE BEGIN USBPD_PWR_IF_GetPortPDOs */
uint32_t nbpdo, index, nb_valid_pdo = 0;
uint32_t *ptpdoarray = NULL;
USBPD_PDO_TypeDef pdo_first;
USBPD_PDO_TypeDef pdo;
/* Check if valid port */
if (USBPD_PORT_IsValid(PortNum))
{
/* According to type of PDO to be read, set pointer on values and nb of elements */
switch(DataId)
{
case USBPD_CORE_DATATYPE_SRC_PDO :
nbpdo = *PWR_Port_PDO_Storage[PortNum].SourcePDO.NumberOfPDO;
ptpdoarray = PWR_Port_PDO_Storage[PortNum].SourcePDO.ListOfPDO;
/* Save the 1st PDO */
pdo_first.d32 = *ptpdoarray;
/* Reset unchunked bit if current revision is PD2.0*/
if (USBPD_SPECIFICATION_REV2 == DPM_Params[PortNum].PE_SpecRevision)
{
pdo_first.SRCFixedPDO.UnchunkedExtendedMessage = USBPD_PDO_SRC_FIXED_UNCHUNK_NOT_SUPPORTED;
}
break;
default :
nbpdo = 0;
break;
}
/* Copy PDO data in output buffer */
for (index = 0; index < nbpdo; index++)
{
pdo.d32 = *ptpdoarray;
/* Copy only PDO (and not APDO in case of current revision is PD2.0) */
if ((USBPD_SPECIFICATION_REV2 == DPM_Params[PortNum].PE_SpecRevision)
&& (pdo.GenericPDO.PowerObject == USBPD_CORE_PDO_TYPE_APDO))
{
}
else
{
/* Copy 1st PDO as potentially FRS or UNCHUNKED bits have been reset */
if (0 == index)
{
(void)memcpy(Ptr, (uint8_t*)&pdo_first.d32, 4u);
}
else
{
(void)memcpy((Ptr + (nb_valid_pdo * 4u)), (uint8_t*)ptpdoarray, 4u);
}
nb_valid_pdo++;
}
ptpdoarray++;
}
/* Set nb of read PDO (nb of u32 elements); */
*Size = nb_valid_pdo;
}
/* USER CODE END USBPD_PWR_IF_GetPortPDOs */
}
/**
* @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)
{
/* USER CODE BEGIN USBPD_PWR_IF_SearchRequestedPDO */
if((RdoPosition == 0) || (RdoPosition > *PWR_Port_PDO_Storage[PortNum].SourcePDO.NumberOfPDO))
{
/* Invalid PDO index */
return USBPD_FAIL;
}
*Pdo = PWR_Port_PDO_Storage[PortNum].SourcePDO.ListOfPDO[RdoPosition - 1];
return USBPD_OK;
/* USER CODE END USBPD_PWR_IF_SearchRequestedPDO */
}
/**
* @brief the function is called in case of critical issue is detected to switch in safety mode.
* @retval None
*/
void USBPD_PWR_IF_Alarm()
{
/* USER CODE BEGIN USBPD_PWR_IF_Alarm */
/* USER CODE END USBPD_PWR_IF_Alarm */
}
/**
* @brief Function is called to get VBUS power status.
* @param PortNum Port number
* @param PowerTypeStatus Power type status based on @ref USBPD_VBUSPOWER_STATUS
* @retval UBBPD_TRUE or USBPD_FALSE
*/
uint8_t USBPD_PWR_IF_GetVBUSStatus(uint8_t PortNum, USBPD_VBUSPOWER_STATUS PowerTypeStatus)
{
/* USER CODE BEGIN USBPD_PWR_IF_GetVBUSStatus */
uint8_t _status = USBPD_FALSE;
uint32_t _vbus = HW_IF_PWR_GetVoltage(PortNum);
switch(PowerTypeStatus)
{
case USBPD_PWR_BELOWVSAFE0V :
if (_vbus < USBPD_PWR_LOW_VBUS_THRESHOLD) _status = USBPD_TRUE;
break;
case USBPD_PWR_VSAFE5V :
if (_vbus >= USBPD_PWR_HIGH_VBUS_THRESHOLD) _status = USBPD_TRUE;
break;
case USBPD_PWR_SNKDETACH:
if (_vbus < USBPD_PWR_HIGH_VBUS_THRESHOLD) _status = USBPD_TRUE;
break;
default :
break;
}
return _status;
/* USER CODE END USBPD_PWR_IF_GetVBUSStatus */
}
/**
* @brief Function is called to set the VBUS threshold when a request has been accepted.
* @param PortNum Port number
* @retval None
*/
void USBPD_PWR_IF_UpdateVbusThreshold(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_PWR_IF_UpdateVbusThreshold */
/* USER CODE END USBPD_PWR_IF_UpdateVbusThreshold */
}
/**
* @brief Function is called to reset the VBUS threshold when there is a power reset.
* @param PortNum Port number
* @retval None
*/
void USBPD_PWR_IF_ResetVbusThreshold(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_PWR_IF_ResetVbusThreshold */
/* USER CODE END USBPD_PWR_IF_ResetVbusThreshold */
}
/**
* @}
*/
/** @addtogroup STM32_USBPD_APPLICATION_POWER_IF_Private_Functions
* @{
*/
/* USER CODE BEGIN USBPD_USER_PRIVATE_FUNCTIONS_Definition */
/* USER CODE END USBPD_USER_PRIVATE_FUNCTIONS_Definition */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,475 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usbpd_vdm_user.c
* @author MCD Application Team
* @brief USBPD provider demo 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 */
/* Includes ------------------------------------------------------------------*/
#include "usbpd_core.h"
#include "usbpd_dpm_conf.h"
#include "usbpd_vdm_user.h"
#include "usbpd_dpm_user.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/** @addtogroup STM32_USBPD_APPLICATION
* @{
*/
/** @addtogroup STM32_USBPD_APPLICATION_VDM_USER
* @{
*/
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Private_define */
/* USER CODE END Private_define */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN Private_typedef */
/* USER CODE END Private_typedef */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Private_macro */
/* USER CODE END Private_macro */
/* Private function prototypes -----------------------------------------------*/
static USBPD_StatusTypeDef USBPD_VDM_DiscoverIdentity(uint8_t PortNum, USBPD_DiscoveryIdentity_TypeDef *pIdentity);
static USBPD_StatusTypeDef USBPD_VDM_DiscoverSVIDs(uint8_t PortNum, uint16_t **p_SVID_Info, uint8_t *nb);
static USBPD_StatusTypeDef USBPD_VDM_DiscoverModes(uint8_t PortNum, uint16_t SVID, uint32_t **p_ModeInfo, uint8_t *nbMode);
static USBPD_StatusTypeDef USBPD_VDM_ModeEnter(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex);
static USBPD_StatusTypeDef USBPD_VDM_ModeExit(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex);
static void USBPD_VDM_SendAttention(uint8_t PortNum, uint8_t *NbData, uint32_t *VDO);
static void USBPD_VDM_ReceiveAttention(uint8_t PortNum, uint8_t NbData, uint32_t VDO);
static USBPD_StatusTypeDef USBPD_VDM_ReceiveSpecific(uint8_t PortNum, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *NbData, uint32_t *VDO);
static void USBPD_VDM_InformIdentity(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_DiscoveryIdentity_TypeDef *pIdentity);
static void USBPD_VDM_InformSVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_SVIDInfo_TypeDef *pListSVID);
static void USBPD_VDM_InformMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_ModeInfo_TypeDef *pModesInfo);
static void USBPD_VDM_InformModeEnter(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex);
static void USBPD_VDM_InformModeExit(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex);
static void USBPD_VDM_InformSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *NbData, uint32_t *VDO);
static void USBPD_VDM_SendSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *NbData, uint32_t *VDO);
static void USBPD_VDM_SendUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef *pUVDM_Header, uint8_t *pNbData, uint32_t *pVDO);
static USBPD_StatusTypeDef USBPD_VDM_ReceiveUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef UVDM_Header, uint8_t *pNbData, uint32_t *pVDO);
/* USER CODE BEGIN Private_prototypes */
/* USER CODE END Private_prototypes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Private_variables */
const USBPD_VDM_Callbacks vdmCallbacks =
{
USBPD_VDM_DiscoverIdentity,
USBPD_VDM_DiscoverSVIDs,
USBPD_VDM_DiscoverModes,
USBPD_VDM_ModeEnter,
USBPD_VDM_ModeExit,
USBPD_VDM_InformIdentity,
USBPD_VDM_InformSVID,
USBPD_VDM_InformMode,
USBPD_VDM_InformModeEnter,
USBPD_VDM_InformModeExit,
USBPD_VDM_SendAttention,
USBPD_VDM_ReceiveAttention,
USBPD_VDM_SendSpecific,
USBPD_VDM_ReceiveSpecific,
USBPD_VDM_InformSpecific,
USBPD_VDM_SendUVDM,
USBPD_VDM_ReceiveUVDM,
};
/* USER CODE END Private_variables */
/* Private functions ---------------------------------------------------------*/
/**
* @brief VDM Discovery identity callback
* @note Function is called to get Discovery identity information linked to the device and answer
* to SVDM Discovery identity init message sent by port partner
* @param PortNum current port number
* @param pIdentity Pointer on @ref USBPD_DiscoveryIdentity_TypeDef structure
* @retval USBPD status: @ref USBPD_ACK or @ref USBPD_BUSY
*/
static USBPD_StatusTypeDef USBPD_VDM_DiscoverIdentity(uint8_t PortNum, USBPD_DiscoveryIdentity_TypeDef *pIdentity)
{
/* USER CODE BEGIN USBPD_VDM_DiscoverIdentity */
return USBPD_NAK;
/* USER CODE END USBPD_VDM_DiscoverIdentity */
}
/**
* @brief VDM Discover SVID callback
* @note Function is called to retrieve SVID supported by device and answer
* to SVDM Discovery SVID init message sent by port partner
* @param PortNum current port number
* @param p_SVID_Info Pointer on @ref USBPD_SVIDInfo_TypeDef structure
* @param pNbSVID Pointer on number of SVID
* @retval USBPD status @ref USBPD_BUSY or @ref USBPD_ACK or @ref USBPD_NAK
*/
static USBPD_StatusTypeDef USBPD_VDM_DiscoverSVIDs(uint8_t PortNum, uint16_t **p_SVID_Info, uint8_t *pNbSVID)
{
/* USER CODE BEGIN USBPD_VDM_DiscoverSVIDs */
return USBPD_NAK;
/* USER CODE END USBPD_VDM_DiscoverSVIDs */
}
/**
* @brief VDM Discover Mode callback (report all the modes supported by SVID)
* @note Function is called to report all the modes supported by selected SVID and answer
* to SVDM Discovery Mode init message sent by port partner
* @param PortNum current port number
* @param SVID SVID value
* @param p_ModeTab Pointer on the mode value
* @param NumberOfMode Number of mode available
* @retval USBPD status
*/
static USBPD_StatusTypeDef USBPD_VDM_DiscoverModes(uint8_t PortNum, uint16_t SVID, uint32_t **p_ModeTab, uint8_t *NumberOfMode)
{
/* USER CODE BEGIN USBPD_VDM_DiscoverModes */
return USBPD_NAK;
/* USER CODE END USBPD_VDM_DiscoverModes */
}
/**
* @brief VDM Mode enter callback
* @note Function is called to check if device can enter in the mode received for the selected SVID in the
* SVDM enter mode init message sent by port partner
* @param PortNum current port number
* @param SVID SVID value
* @param ModeIndex Index of the mode to be entered
* @retval USBPD status @ref USBPD_ACK/@ref USBPD_NAK
*/
static USBPD_StatusTypeDef USBPD_VDM_ModeEnter(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex)
{
/* USER CODE BEGIN USBPD_VDM_ModeEnter */
return USBPD_NAK;
/* USER CODE END USBPD_VDM_ModeEnter */
}
/**
* @brief VDM Mode exit callback
* @note Function is called to check if device can exit from the mode received for the selected SVID in the
* SVDM exit mode init message sent by port partner
* @param PortNum current port number
* @param SVID SVID value
* @param ModeIndex Index of the mode to be exited
* @retval USBPD status @ref USBPD_ACK/@ref USBPD_NAK
*/
static USBPD_StatusTypeDef USBPD_VDM_ModeExit(uint8_t PortNum, uint16_t SVID, uint32_t ModeIndex)
{
/* USER CODE BEGIN USBPD_VDM_ModeExit */
return USBPD_NAK;
/* USER CODE END USBPD_VDM_ModeExit */
}
/**
* @brief Send VDM Attention message callback
* @note Function is called when device wants to send a SVDM attention message to port partner
* (for instance DP status can be filled through this function)
* @param PortNum current port number
* @param pNbData Pointer of number of VDO to send
* @param pVDO Pointer of VDO to send
* @retval None
*/
static void USBPD_VDM_SendAttention(uint8_t PortNum, uint8_t *pNbData, uint32_t *pVDO)
{
/* USER CODE BEGIN USBPD_VDM_SendAttention */
/* USER CODE END USBPD_VDM_SendAttention */
}
/**
* @brief Receive VDM Attention callback
* @note Function is called when a SVDM attention init message has been received from port partner
* (for instance, save DP status data through this function)
* @param PortNum current port number
* @param NbData Number of received VDO
* @param VDO Received VDO
* @retval None
*/
static void USBPD_VDM_ReceiveAttention(uint8_t PortNum, uint8_t NbData, uint32_t VDO)
{
/* USER CODE BEGIN USBPD_VDM_ReceiveAttention */
/* USER CODE END USBPD_VDM_ReceiveAttention */
}
/**
* @brief VDM Receive Specific message callback
* @note Function is called to answer to a SVDM specific init message received by port partner.
* (for instance, retrieve DP status or DP configure data through this function)
* @param PortNum Current port number
* @param VDMCommand VDM command based on @ref USBPD_VDM_Command_Typedef
* @param pNbData Pointer of number of received VDO and used for the answer
* @param pVDO Pointer of received VDO and use for the answer
* @retval USBPD Status
*/
static USBPD_StatusTypeDef USBPD_VDM_ReceiveSpecific(uint8_t PortNum, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *pNbData, uint32_t *pVDO)
{
/* USER CODE BEGIN USBPD_VDM_ReceiveSpecific */
return USBPD_NAK;
/* USER CODE END USBPD_VDM_ReceiveSpecific */
}
/**
* @brief Inform identity callback
* @note Function is called to save Identity information received in Discovery identity from port partner
(answer to SVDM discovery identity sent by device)
* @param PortNum current port number
* @param SOPType SOP type
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
* @param pIdentity Pointer on the discovery identity information based on @ref USBPD_DiscoveryIdentity_TypeDef
* @retval None
*/
static void USBPD_VDM_InformIdentity(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_DiscoveryIdentity_TypeDef *pIdentity)
{
/* USER CODE BEGIN USBPD_VDM_InformIdentity */
switch(CommandStatus)
{
case SVDM_RESPONDER_ACK :
break;
case SVDM_RESPONDER_NAK :
break;
case SVDM_RESPONDER_BUSY :
break;
default :
break;
}
/* USER CODE END USBPD_VDM_InformIdentity */
}
/**
* @brief Inform SVID callback
* @note Function is called to save list of SVID received in Discovery SVID from port partner
(answer to SVDM discovery SVID sent by device)
* @param PortNum current port number
* @param SOPType SOP type
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
* @param pListSVID Pointer of list of SVID based on @ref USBPD_SVIDInfo_TypeDef
* @retval None
*/
static void USBPD_VDM_InformSVID(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_SVIDInfo_TypeDef *pListSVID)
{
/* USER CODE BEGIN USBPD_VDM_InformSVID */
switch(CommandStatus)
{
case SVDM_RESPONDER_ACK :
break;
case SVDM_RESPONDER_NAK :
break;
case SVDM_RESPONDER_BUSY :
break;
default :
break;
}
/* USER CODE END USBPD_VDM_InformSVID */
}
/**
* @brief Inform Mode callback ( received in Discovery Modes ACK)
* @note Function is called to save list of modes linked to SVID received in Discovery mode from port partner
(answer to SVDM discovery mode sent by device)
* @param PortNum current port number
* @param SOPType SOP type
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
* @param pModesInfo Pointer of Modes info based on @ref USBPD_ModeInfo_TypeDef
* @retval None
*/
static void USBPD_VDM_InformMode(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, USBPD_ModeInfo_TypeDef *pModesInfo)
{
/* USER CODE BEGIN USBPD_VDM_InformMode */
switch(CommandStatus)
{
case SVDM_RESPONDER_ACK :
break;
case SVDM_RESPONDER_NAK :
break;
case SVDM_RESPONDER_BUSY :
break;
default :
break;
}
/* USER CODE END USBPD_VDM_InformMode */
}
/**
* @brief Inform Mode enter callback
* @note Function is called to inform if port partner accepted or not to enter in the mode
* specified in the SVDM enter mode sent by the device
* @param PortNum current port number
* @param SOPType SOP type
* @param CommandStatus Command status based on @ref USBPD_VDM_CommandType_Typedef
* @param SVID SVID ID
* @param ModeIndex Index of the mode to be entered
* @retval None
*/
static void USBPD_VDM_InformModeEnter(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex)
{
/* USER CODE BEGIN USBPD_VDM_InformModeEnter */
switch(CommandStatus)
{
case SVDM_RESPONDER_ACK :
break;
case SVDM_RESPONDER_NAK :
break;
case SVDM_RESPONDER_BUSY :
/* retry in 50ms */
break;
default :
break;
}
/* USER CODE END USBPD_VDM_InformModeEnter */
}
/**
* @brief Inform Exit enter callback
* @param PortNum current port number
* @param SVID SVID ID
* @param ModeIndex Index of the mode to be entered
* @retval None
*/
static void USBPD_VDM_InformModeExit(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_CommandType_Typedef CommandStatus, uint16_t SVID, uint32_t ModeIndex)
{
/* USER CODE BEGIN USBPD_VDM_InformModeExit */
switch(CommandStatus)
{
case SVDM_RESPONDER_ACK :
break;
case SVDM_RESPONDER_NAK :
break;
case SVDM_RESPONDER_BUSY :
/* retry in 50ms */
break;
default :
break;
}
/* USER CODE END USBPD_VDM_InformModeExit */
}
/**
* @brief VDM Send Specific message callback
* @note Function is called when device wants to send a SVDM specific init message to port partner
* (for instance DP status or DP configure can be filled through this function)
* @param PortNum current port number
* @param SOPType SOP type
* @param VDMCommand VDM command based on @ref USBPD_VDM_Command_Typedef
* @param pNbData Pointer of number of VDO to send
* @param pVDO Pointer of VDO to send
* @retval None
*/
static void USBPD_VDM_SendSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *pNbData, uint32_t *pVDO)
{
/* USER CODE BEGIN USBPD_VDM_SendSpecific */
/* USER CODE END USBPD_VDM_SendSpecific */
}
/**
* @brief VDM Specific message callback to inform user of reception of VDM specific message
* @note Function is called when answer from SVDM specific init message has been received by the device
* (for instance, save DP status and DP configure data through this function)
* @param PortNum current port number
* @param SOPType SOP type
* @param VDMCommand VDM command based on @ref USBPD_VDM_Command_Typedef
* @param pNbData Pointer of number of received VDO
* @param pVDO Pointer of received VDO
* @retval None
*/
static void USBPD_VDM_InformSpecific(uint8_t PortNum, USBPD_SOPType_TypeDef SOPType, USBPD_VDM_Command_Typedef VDMCommand, uint8_t *pNbData, uint32_t *pVDO)
{
/* USER CODE BEGIN USBPD_VDM_InformSpecific */
/* USER CODE END USBPD_VDM_InformSpecific */
}
/**
* @brief VDM Send Unstructured message callback
* @param PortNum current port number
* @param pUVDM_Header Pointer on UVDM header based on @ref USBPD_UVDMHeader_TypeDef
* @param pNbData Pointer of number of VDO to send
* @param pVDO Pointer of VDO to send
* @retval None
*/
static void USBPD_VDM_SendUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef *pUVDM_Header, uint8_t *pNbData, uint32_t *pVDO)
{
/* USER CODE BEGIN USBPD_VDM_SendUVDM */
/* USER CODE END USBPD_VDM_SendUVDM */
}
/**
* @brief Unstructured VDM message callback to inform user of reception of UVDM message
* @param PortNum current port number
* @param UVDM_Header UVDM header based on @ref USBPD_UVDMHeader_TypeDef
* @param pNbData Pointer of number of received VDO
* @param pVDO Pointer of received VDO
* @retval USBPD Status
*/
static USBPD_StatusTypeDef USBPD_VDM_ReceiveUVDM(uint8_t PortNum, USBPD_UVDMHeader_TypeDef UVDM_Header, uint8_t *pNbData, uint32_t *pVDO)
{
/* USER CODE BEGIN USBPD_VDM_ReceiveUVDM */
return USBPD_ERROR;
/* USER CODE END USBPD_VDM_ReceiveUVDM */
}
/* USER CODE BEGIN Private_functions */
/* USER CODE END Private_functions */
/* Exported functions ---------------------------------------------------------*/
/**
* @brief VDM Initialization function
* @param PortNum Index of current used port
* @retval status
*/
USBPD_StatusTypeDef USBPD_VDM_UserInit(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_VDM_UserInit */
return USBPD_OK;
/* USER CODE END USBPD_VDM_UserInit */
}
/**
* @brief VDM Reset function
* @param PortNum Index of current used port
* @retval status
*/
void USBPD_VDM_UserReset(uint8_t PortNum)
{
/* USER CODE BEGIN USBPD_VDM_UserReset */
/* USER CODE END USBPD_VDM_UserReset */
}
/* USER CODE BEGIN Exported_functions */
/* USER CODE END Exported_functions */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/