Changeset 22 for trunk/fw_g473rct/Core
- Timestamp:
- Aug 29, 2025, 6:15:42 PM (33 hours ago)
- Location:
- trunk/fw_g473rct/Core
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/Core/Inc/main.h
r20 r22 70 70 #define ADC2_IN3_UBAT__Pin GPIO_PIN_6 71 71 #define ADC2_IN3_UBAT__GPIO_Port GPIOA 72 #define ADC2_IN4_UBAT__Pin GPIO_PIN_773 #define ADC2_IN4_UBAT__GPIO_Port GPIOA74 72 #define ADC3_IN12_MOSFET_TEMP_Pin GPIO_PIN_0 75 73 #define ADC3_IN12_MOSFET_TEMP_GPIO_Port GPIOB -
trunk/fw_g473rct/Core/Inc/stm32g4xx_it.h
r20 r22 61 61 void DMA1_Channel4_IRQHandler(void); 62 62 void DMA1_Channel5_IRQHandler(void); 63 void DMA1_Channel6_IRQHandler(void); 64 void USART1_IRQHandler(void); 65 void USART2_IRQHandler(void); 63 66 /* USER CODE BEGIN EFP */ 64 67 -
trunk/fw_g473rct/Core/Src/adc.c
r20 r22 59 59 hadc1.Init.GainCompensation = 0; 60 60 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 61 hadc1.Init.EOCSelection = ADC_EOC_S EQ_CONV;61 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 62 62 hadc1.Init.LowPowerAutoWait = DISABLE; 63 63 hadc1.Init.ContinuousConvMode = ENABLE; … … 68 68 hadc1.Init.DMAContinuousRequests = ENABLE; 69 69 hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; 70 hadc1.Init.OversamplingMode = DISABLE; 70 hadc1.Init.OversamplingMode = ENABLE; 71 hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; 72 hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4; 73 hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; 74 hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; 71 75 if (HAL_ADC_Init(&hadc1) != HAL_OK) 72 76 { … … 88 92 sConfig.Channel = ADC_CHANNEL_1; 89 93 sConfig.Rank = ADC_REGULAR_RANK_1; 90 sConfig.SamplingTime = ADC_SAMPLETIME_ 2CYCLES_5;94 sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5; 91 95 sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED; 92 96 sConfig.OffsetNumber = ADC_OFFSET_NONE; … … 123 127 hadc2.Init.GainCompensation = 0; 124 128 hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE; 125 hadc2.Init.EOCSelection = ADC_EOC_S EQ_CONV;129 hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 126 130 hadc2.Init.LowPowerAutoWait = DISABLE; 127 131 hadc2.Init.ContinuousConvMode = ENABLE; … … 130 134 hadc2.Init.DMAContinuousRequests = ENABLE; 131 135 hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; 132 hadc2.Init.OversamplingMode = DISABLE; 136 hadc2.Init.OversamplingMode = ENABLE; 137 hadc2.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256; 138 hadc2.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4; 139 hadc2.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER; 140 hadc2.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE; 133 141 if (HAL_ADC_Init(&hadc2) != HAL_OK) 134 142 { … … 140 148 sConfig.Channel = ADC_CHANNEL_3; 141 149 sConfig.Rank = ADC_REGULAR_RANK_1; 142 sConfig.SamplingTime = ADC_SAMPLETIME_ 2CYCLES_5;143 sConfig.SingleDiff = ADC_ DIFFERENTIAL_ENDED;150 sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5; 151 sConfig.SingleDiff = ADC_SINGLE_ENDED; 144 152 sConfig.OffsetNumber = ADC_OFFSET_NONE; 145 153 sConfig.Offset = 0; … … 396 404 hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; 397 405 hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; 398 hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_ HALFWORD;406 hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; 399 407 hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; 400 408 hdma_adc1.Init.Mode = DMA_CIRCULAR; … … 435 443 /**ADC2 GPIO Configuration 436 444 PA6 ------> ADC2_IN3 437 PA7 ------> ADC2_IN4 438 */ 439 GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin; 445 */ 446 GPIO_InitStruct.Pin = ADC2_IN3_UBAT__Pin; 440 447 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 441 448 GPIO_InitStruct.Pull = GPIO_NOPULL; 442 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct);449 HAL_GPIO_Init(ADC2_IN3_UBAT__GPIO_Port, &GPIO_InitStruct); 443 450 444 451 /* ADC2 DMA Init */ … … 449 456 hdma_adc2.Init.PeriphInc = DMA_PINC_DISABLE; 450 457 hdma_adc2.Init.MemInc = DMA_MINC_ENABLE; 451 hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_ HALFWORD;458 hdma_adc2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; 452 459 hdma_adc2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; 453 460 hdma_adc2.Init.Mode = DMA_CIRCULAR; … … 665 672 /**ADC2 GPIO Configuration 666 673 PA6 ------> ADC2_IN3 667 PA7 ------> ADC2_IN4 668 */ 669 HAL_GPIO_DeInit(GPIOA, ADC2_IN3_UBAT__Pin|ADC2_IN4_UBAT__Pin); 674 */ 675 HAL_GPIO_DeInit(ADC2_IN3_UBAT__GPIO_Port, ADC2_IN3_UBAT__Pin); 670 676 671 677 /* ADC2 DMA DeInit */ -
trunk/fw_g473rct/Core/Src/dma.c
r20 r22 60 60 HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0); 61 61 HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); 62 /* DMA1_Channel6_IRQn interrupt configuration */ 63 HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0); 64 HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); 62 65 63 66 } -
trunk/fw_g473rct/Core/Src/stm32g4xx_hal_msp.c
r20 r22 73 73 /* System interrupt init*/ 74 74 75 /** Configure the internal voltage reference buffer high impedance mode 76 */ 77 HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE); 78 79 /** Disable the Internal Voltage Reference buffer 80 */ 81 HAL_SYSCFG_DisableVREFBUF(); 82 75 83 /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral 76 84 */ -
trunk/fw_g473rct/Core/Src/stm32g4xx_it.c
r20 r22 23 23 /* Private includes ----------------------------------------------------------*/ 24 24 /* USER CODE BEGIN Includes */ 25 #include "modbus.h" 25 26 /* USER CODE END Includes */ 26 27 … … 61 62 extern DMA_HandleTypeDef hdma_adc4; 62 63 extern DMA_HandleTypeDef hdma_adc5; 64 extern DMA_HandleTypeDef hdma_usart2_rx; 65 extern UART_HandleTypeDef huart1; 66 extern UART_HandleTypeDef huart2; 63 67 /* USER CODE BEGIN EV */ 64 68 … … 273 277 } 274 278 279 /** 280 * @brief This function handles DMA1 channel6 global interrupt. 281 */ 282 void DMA1_Channel6_IRQHandler(void) 283 { 284 /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */ 285 286 /* USER CODE END DMA1_Channel6_IRQn 0 */ 287 HAL_DMA_IRQHandler(&hdma_usart2_rx); 288 /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */ 289 290 /* USER CODE END DMA1_Channel6_IRQn 1 */ 291 } 292 293 /** 294 * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25. 295 */ 296 void USART1_IRQHandler(void) 297 { 298 /* USER CODE BEGIN USART1_IRQn 0 */ 299 300 /* USER CODE END USART1_IRQn 0 */ 301 HAL_UART_IRQHandler(&huart1); 302 /* USER CODE BEGIN USART1_IRQn 1 */ 303 304 /* USER CODE END USART1_IRQn 1 */ 305 } 306 307 /** 308 * @brief This function handles USART2 global interrupt / USART2 wake-up interrupt through EXTI line 26. 309 */ 310 void USART2_IRQHandler(void) 311 { 312 /* USER CODE BEGIN USART2_IRQn 0 */ 313 314 /* USER CODE END USART2_IRQn 0 */ 315 HAL_UART_IRQHandler(&huart2); 316 /* USER CODE BEGIN USART2_IRQn 1 */ 317 //MODBUS_UART_IRQHandler(&huart2); 318 /* USER CODE END USART2_IRQn 1 */ 319 } 320 275 321 /* USER CODE BEGIN 1 */ 276 322 -
trunk/fw_g473rct/Core/Src/usart.c
r20 r22 27 27 UART_HandleTypeDef huart1; 28 28 UART_HandleTypeDef huart2; 29 DMA_HandleTypeDef hdma_usart2_rx; 29 30 30 31 /* USART1 init function */ … … 86 87 huart2.Instance = USART2; 87 88 huart2.Init.BaudRate = 115200; 88 huart2.Init.WordLength = UART_WORDLENGTH_ 8B;89 huart2.Init.WordLength = UART_WORDLENGTH_9B; 89 90 huart2.Init.StopBits = UART_STOPBITS_1; 90 huart2.Init.Parity = UART_PARITY_ NONE;91 huart2.Init.Parity = UART_PARITY_EVEN; 91 92 huart2.Init.Mode = UART_MODE_TX_RX; 92 93 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; … … 94 95 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 95 96 huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; 96 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 97 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT; 98 huart2.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE; 97 99 if (HAL_UART_Init(&huart2) != HAL_OK) 98 100 { … … 152 154 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 153 155 156 /* USART1 interrupt Init */ 157 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); 158 HAL_NVIC_EnableIRQ(USART1_IRQn); 154 159 /* USER CODE BEGIN USART1_MspInit 1 */ 155 160 … … 186 191 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 187 192 193 /* USART2 DMA Init */ 194 /* USART2_RX Init */ 195 hdma_usart2_rx.Instance = DMA1_Channel6; 196 hdma_usart2_rx.Init.Request = DMA_REQUEST_USART2_RX; 197 hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; 198 hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE; 199 hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE; 200 hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 201 hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 202 hdma_usart2_rx.Init.Mode = DMA_NORMAL; 203 hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW; 204 if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK) 205 { 206 Error_Handler(); 207 } 208 209 __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx); 210 211 /* USART2 interrupt Init */ 212 HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); 213 HAL_NVIC_EnableIRQ(USART2_IRQn); 188 214 /* USER CODE BEGIN USART2_MspInit 1 */ 189 215 … … 209 235 HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4|GPIO_PIN_5); 210 236 237 /* USART1 interrupt Deinit */ 238 HAL_NVIC_DisableIRQ(USART1_IRQn); 211 239 /* USER CODE BEGIN USART1_MspDeInit 1 */ 212 240 … … 227 255 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); 228 256 257 /* USART2 DMA DeInit */ 258 HAL_DMA_DeInit(uartHandle->hdmarx); 259 260 /* USART2 interrupt Deinit */ 261 HAL_NVIC_DisableIRQ(USART2_IRQn); 229 262 /* USER CODE BEGIN USART2_MspDeInit 1 */ 230 263
Note: See TracChangeset
for help on using the changeset viewer.