Nouveaux messages + ajout middleware USBPD

This commit is contained in:
Allan Cueff
2025-05-14 10:54:37 +02:00
parent 97c357aa73
commit 8ead29bef5
57 changed files with 20244 additions and 101 deletions

34
Core/Inc/alim.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* alim.h
*
* Created on: May 11, 2025
* Author: allan
*/
#ifndef INC_ALIM_H_
#define INC_ALIM_H_
extern UART_HandleTypeDef huart2;
extern I2C_HandleTypeDef hi2c1;
typedef enum i2cAdress {
I2C_TEMP = 0x18,
I2C_IN1 = 0x48,
I2C_IN2 = 0x4A,
I2C_OUT5V = 0x43,
I2C_OUT5V1 = 0x40,
I2C_OUT12V = 0x41,
I2C_OUT24V = 0x4B
} i2cAdress;
// Prototypes
HAL_StatusTypeDef read_bau_state(int* val);
HAL_StatusTypeDef read_mcp9808_temp(float* val);
HAL_StatusTypeDef ina236_write_reg(i2cAdress address, uint8_t reg, uint16_t value);
HAL_StatusTypeDef ina236_read_reg(i2cAdress address, uint8_t reg, uint16_t *value);
HAL_StatusTypeDef ina236_init(i2cAdress address, float r_shunt, float current_lsb);
HAL_StatusTypeDef read_ina236_voltage(i2cAdress address, float *voltage);
HAL_StatusTypeDef read_ina236_current(i2cAdress address, float currentLSB, float *current);
#endif /* INC_ALIM_H_ */

20
Core/Inc/comm.h Normal file
View File

@@ -0,0 +1,20 @@
/*
* comm.h
*
* Created on: May 12, 2025
* Author: allan
*/
#ifndef INC_COMM_H_
#define INC_COMM_H_
#define RX_BUFFER_SIZE 128
// Prototypes
void handle_uart_message(const char *msg);
void handle_get(const char *xxx, const char *yyy);
void handle_set(const char *xxx, const char *yyy, const char *val);
void send_set_response(const char *xxx, const char *yyy, int val);
void send_error_response(void);
#endif /* INC_COMM_H_ */

View File

@@ -29,6 +29,18 @@ extern "C" {
/* 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 */
@@ -59,6 +71,8 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define TCPP02_EN_Pin GPIO_PIN_9
#define TCPP02_EN_GPIO_Port GPIOA
/* USER CODE BEGIN Private defines */

53
Core/Inc/stm32_assert.h Normal file
View File

@@ -0,0 +1,53 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32_assert.h
* @author MCD Application Team
* @brief STM32 assert file.
******************************************************************************
* @attention
*
* Copyright (c) 2019 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __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 */

View File

@@ -56,8 +56,11 @@ void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void EXTI1_IRQHandler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel2_IRQHandler(void);
void EXTI9_5_IRQHandler(void);
void USART2_IRQHandler(void);
void UCPD1_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */

87
Core/Src/alim.c Normal file
View File

@@ -0,0 +1,87 @@
#include "main.h"
#include "alim.h"
#include "comm.h"
#include <stdio.h>
#include <stdlib.h>
HAL_StatusTypeDef read_bau_state(int* val){
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET){
*val = 0;
return HAL_ERROR;
} else {
*val = 1;
return HAL_ERROR;
}
return HAL_OK;
}
HAL_StatusTypeDef read_mcp9808_temp(float* temp) {
uint8_t reg = 0x05;
uint8_t data[2];
if (HAL_I2C_Master_Transmit(&hi2c1, I2C_TEMP << 1, &reg, 1, HAL_MAX_DELAY) != HAL_OK){
return HAL_ERROR;
}
if (HAL_I2C_Master_Receive(&hi2c1, I2C_TEMP << 1, data, 2, HAL_MAX_DELAY) != HAL_OK){
return HAL_ERROR;
}
uint16_t raw = (data[0] << 8) | data[1];
raw &= 0x1FFF;
*temp = raw & 0x1000 ? (raw - 8192) * 0.0625f : raw * 0.0625f;
return HAL_OK;
}
HAL_StatusTypeDef ina236_write_reg(i2cAdress address, uint8_t reg, uint16_t value) {
uint8_t data[3];
data[0] = reg;
data[1] = (value >> 8);
data[2] = (value & 0xFF);
return HAL_I2C_Master_Transmit(&hi2c1, address << 1, data, 3, HAL_MAX_DELAY);
}
HAL_StatusTypeDef ina236_read_reg(i2cAdress address, uint8_t reg, uint16_t *value) {
uint8_t data[2];
if (HAL_I2C_Master_Transmit(&hi2c1, address << 1, &reg, 1, HAL_MAX_DELAY) != HAL_OK)
return HAL_ERROR;
if (HAL_I2C_Master_Receive(&hi2c1, address << 1, data, 2, HAL_MAX_DELAY) != HAL_OK)
return HAL_ERROR;
*value = (data[0] << 8) | data[1];
return HAL_OK;
}
HAL_StatusTypeDef ina236_init(i2cAdress address, float r_shunt, float current_lsb) {
uint16_t calibration = (uint16_t)(0.00512 / (r_shunt * current_lsb));
if(ina236_write_reg(address, 0x05, calibration) != HAL_OK){
return HAL_ERROR;
}
uint16_t config = 0x4127; // Exemple: moyenne x4, conversion 1.1ms, mode shunt+bus continuous
if(ina236_write_reg(address, 0x00, config) != HAL_OK){
return HAL_ERROR;
}
return HAL_OK;
}
HAL_StatusTypeDef read_ina236_voltage(i2cAdress address, float *voltage) {
uint16_t raw;
if (ina236_read_reg(address, 0x02, &raw) != HAL_OK){
return HAL_ERROR;
}
*voltage = (raw * 1.25f); // 1.25 mV/bit → en mV
return HAL_OK;
}
HAL_StatusTypeDef read_ina236_current(i2cAdress address, float currentLSB, float *current) {
uint16_t raw;
if (ina236_read_reg(address, 0x04, &raw) != HAL_OK){
return HAL_ERROR;
}
*current = ((int16_t)raw) * currentLSB * 1000; // en mA
return HAL_OK;
}

View File

@@ -1,33 +1,17 @@
#include "comm.h"
#include "main.h"
#include "alim.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <math.h>
extern UART_HandleTypeDef huart2;
extern I2C_HandleTypeDef hi2c1;
typedef enum errorCode {
COMM_SUCCESS,
COMM_ERROR
} errorCode ;
#define RX_BUFFER_SIZE 128
static char rxBuffer[RX_BUFFER_SIZE];
static uint8_t rxIndex = 0;
static char rxChar;
// Prototypes
void handle_uart_message(const char *msg);
void handle_get(const char *xxx, const char *yyy);
void handle_set(const char *xxx, const char *yyy, const char *val);
void send_set_response(const char *xxx, const char *yyy, int val);
void send_error_response(void);
errorCode read_bau_state(int* val);
errorCode read_mcp9808_temp(float* val);
// Lancer la réception UART
void uart_start_reception() {
HAL_UART_Receive_IT(&huart2, (uint8_t *)&rxChar, 1);
@@ -71,19 +55,94 @@ void handle_uart_message(const char *msg) {
void handle_get(const char *xxx, const char *yyy) {
if (strcmp(xxx, "BAU") == 0 && strcmp(yyy, "STATE") == 0) {
int val = 0;
errorCode res = read_bau_state(&val);
if(res == COMM_SUCCESS){
HAL_StatusTypeDef res = read_bau_state(&val);
if(res == HAL_OK){
send_set_response(xxx, yyy, val);
return;
}
} else if (strcmp(xxx, "TEMP") == 0 && strcmp(yyy, "CELS") == 0) {
float temp = -1000.0f;
errorCode res = read_mcp9808_temp(&temp);
if (res == COMM_SUCCESS) {
HAL_StatusTypeDef res = read_mcp9808_temp(&temp);
if (res == HAL_OK) {
int temp_dixieme = (int)(temp * 10.0f + 0.5f);
send_set_response(xxx, yyy, temp_dixieme);
return;
}
} else {
// Concerne les entrees sorties
i2cAdress address;
float currentLSB;
bool validZone = false;
uint16_t controlPin;
uint16_t validPin;
// Selection zone mesure
if(strcmp(xxx, "IN1") == 0){
address = I2C_IN1;
currentLSB = 0.000610f;
validPin = GPIO_PIN_5;
validZone = true;
} else if (strcmp(xxx, "IN2") == 0){
address = I2C_IN2;
currentLSB = 0.000610f;
validPin = GPIO_PIN_6;
validZone = true;
} else if (strcmp(xxx, "OUT5V") == 0){
address = I2C_OUT5V;
currentLSB = 0.000185f;
controlPin = GPIO_PIN_0;
validZone = true;
} else if (strcmp(xxx, "OUT5V1") == 0){
address = I2C_OUT5V1;
currentLSB = 0.000185f;
validZone = true;
} else if (strcmp(xxx, "OUT12V") == 0){
address = I2C_OUT12V;
currentLSB = 0.000125f;
controlPin = GPIO_PIN_10;
validZone = true;
} else if (strcmp(xxx, "OUT24") == 0){
address = I2C_OUT24V;
currentLSB = 0.000040f;
controlPin = GPIO_PIN_11;
validZone = true;
}
// Selection type mesure
if(strcmp(yyy, "VOLT") == 0 && validZone){
float val = 0.0f;
HAL_StatusTypeDef res = read_ina236_voltage(address, &val);
if (res == HAL_OK) {
send_set_response(xxx, yyy, val);
return;
}
} else if (strcmp(yyy, "AMPS") == 0 && validZone){
float val = 0.0f;
HAL_StatusTypeDef res = read_ina236_current(address, currentLSB, &val);
if (res == HAL_OK) {
send_set_response(xxx, yyy, val);
return;
}
} else if (strcmp(yyy, "VALID") == 0 && validZone){
int val = 0;
if((strcmp(xxx, "IN1") == 0) || (strcmp(xxx, "IN2") == 0)){
val = (HAL_GPIO_ReadPin(GPIOA, validPin) == GPIO_PIN_RESET) ? 1 : 0;
} else {
val = 1;
}
send_set_response(xxx, yyy, val);
return;
} else if (strcmp(yyy, "STATE") == 0 && validZone){
int val = 0;
if((strcmp(xxx, "OUT5V") == 0) || (strcmp(xxx, "OUT12V") == 0) || (strcmp(xxx, "OUT24V") == 0)){
val = (HAL_GPIO_ReadPin(GPIOA, controlPin) == GPIO_PIN_RESET) ? 1 : 0;
} else {
val = 1;
}
send_set_response(xxx, yyy, val);
return;
}
}
send_error_response();
}
@@ -97,9 +156,20 @@ void handle_set(const char *xxx, const char *yyy, const char *val) {
(strcmp(xxx, "OUT12V") == 0 && strcmp(yyy, "STATE") == 0) ||
(strcmp(xxx, "OUT24V") == 0 && strcmp(yyy, "STATE") == 0))) {
// Appliquer commande...
GPIO_PinState pin_state = (v == 1) ? GPIO_PIN_RESET : GPIO_PIN_SET; // Niveau actif bas
int success = 0;
if (strcmp(xxx, "OUT5V") == 0 && strcmp(yyy, "STATE") == 0) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, pin_state);
success = 1;
} else if (strcmp(xxx, "OUT12V") == 0 && strcmp(yyy, "STATE") == 0) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, pin_state);
success = 1;
} else if (strcmp(xxx, "OUT24V") == 0 && strcmp(yyy, "STATE") == 0) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, pin_state);
success = 1;
}
int success = 1;
if (success) {
char msg[64];
snprintf(msg, sizeof(msg), "OK;%s;%s;%d\n", xxx, yyy, v);
@@ -124,33 +194,3 @@ void send_error_response() {
const char *msg = "KO;PARSE;ERROR;0\n";
HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), HAL_MAX_DELAY);
}
errorCode read_bau_state(int* val){
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET){
*val = 0;
return COMM_SUCCESS;
} else {
*val = 1;
return COMM_SUCCESS;
}
return COMM_ERROR;
}
errorCode read_mcp9808_temp(float* temp) {
uint8_t reg = 0x05;
uint8_t data[2];
if (HAL_I2C_Master_Transmit(&hi2c1, 0x18 << 1, &reg, 1, HAL_MAX_DELAY) != HAL_OK){
return COMM_ERROR;
}
if (HAL_I2C_Master_Receive(&hi2c1, 0x18 << 1, data, 2, HAL_MAX_DELAY) != HAL_OK){
return COMM_ERROR;
}
uint16_t raw = (data[0] << 8) | data[1];
raw &= 0x1FFF;
*temp = raw & 0x1000 ? (raw - 8192) * 0.0625f : raw * 0.0625f;
return COMM_SUCCESS;
}

View File

@@ -18,9 +18,11 @@
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usbpd.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "alim.h"
#include <string.h>
/* USER CODE END Includes */
@@ -53,9 +55,11 @@ UART_HandleTypeDef huart2;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_TIM3_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_I2C1_Init(void);
static void MX_UCPD1_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@@ -94,20 +98,33 @@ int main(void)
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM3_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
MX_UCPD1_Init();
/* USER CODE BEGIN 2 */
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1) == GPIO_PIN_SET){
BAU_State = 0;
}else{
BAU_State = 1;
}
ina236_init(I2C_IN1, 0.004f, 0.000610f); // Rshunt = 4 mOhm, currentLSB = 610 uA (maxCurrent = 20A)
ina236_init(I2C_IN2, 0.004f, 0.000610f); // Rshunt = 4 mOhm, currentLSB = 610 uA (maxCurrent = 20A)
ina236_init(I2C_OUT5V, 0.013f, 0.000185f); // Rshunt = 13 mOhm, currentLSB = 185 uA (maxCurrent = 6A)
ina236_init(I2C_OUT5V1, 0.013f, 0.000185f); // Rshunt = 13 mOhm, currentLSB = 185 uA (maxCurrent = 6A)
ina236_init(I2C_OUT12V, 0.020f, 0.000125f); // Rshunt = 20 mOhm, currentLSB = 305 uA (maxCurrent = 4A)
ina236_init(I2C_OUT24V, 0.062f, 0.000040f); // Rshunt = 62 mOhm, currentLSB = 40 uA (maxCurrent = 1A25)
uart_start_reception();
/* USER CODE END 2 */
/* USBPD initialisation ---------------------------------*/
MX_USBPD_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
@@ -118,6 +135,7 @@ int main(void)
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_Delay(500);*/
/* USER CODE END WHILE */
USBPD_DPM_Run();
/* USER CODE BEGIN 3 */
}
@@ -277,6 +295,87 @@ static void MX_TIM3_Init(void)
}
/**
* @brief UCPD1 Initialization Function
* @param None
* @retval None
*/
static 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_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
/**UCPD1 GPIO Configuration
PB4 ------> UCPD1_CC2
PB6 ------> UCPD1_CC1
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_4;
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_6;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* UCPD1 DMA Init */
/* UCPD1_RX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_UCPD1_RX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, 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(UCPD1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(UCPD1_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 USART2 Initialization Function
* @param None
@@ -325,6 +424,26 @@ static void MX_USART2_UART_Init(void)
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMAMUX1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* DMA1_Channel2_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(DMA1_Channel2_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None
@@ -340,6 +459,16 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|TCPP02_EN_Pin|GPIO_PIN_10|GPIO_PIN_11, GPIO_PIN_RESET);
/*Configure GPIO pins : PA0 PA10 PA11 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PA1 */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
@@ -352,6 +481,19 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : TCPP02_EN_Pin */
GPIO_InitStruct.Pin = TCPP02_EN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(TCPP02_EN_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PA12 */
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PB5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

View File

@@ -20,6 +20,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32g4xx_it.h"
#include "usbpd.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
@@ -186,6 +187,7 @@ void SysTick_Handler(void)
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
USBPD_DPM_TimerCounter();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
@@ -212,6 +214,32 @@ void EXTI1_IRQHandler(void)
/* USER CODE END EXTI1_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel1 global interrupt.
*/
void DMA1_Channel1_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
/* USER CODE END DMA1_Channel1_IRQn 0 */
/* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
/* USER CODE END DMA1_Channel1_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel2 global interrupt.
*/
void DMA1_Channel2_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
/* USER CODE END DMA1_Channel2_IRQn 0 */
/* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
/* USER CODE END DMA1_Channel2_IRQn 1 */
}
/**
* @brief This function handles EXTI line[9:5] interrupts.
*/
@@ -240,6 +268,21 @@ void USART2_IRQHandler(void)
/* USER CODE END USART2_IRQn 1 */
}
/**
* @brief This function handles UCPD1 interrupt / UCPD1 wake-up interrupt through EXTI line 43.
*/
void UCPD1_IRQHandler(void)
{
/* USER CODE BEGIN UCPD1_IRQn 0 */
/* USER CODE END UCPD1_IRQn 0 */
USBPD_PORT0_IRQHandler();
/* USER CODE BEGIN UCPD1_IRQn 1 */
/* USER CODE END UCPD1_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */