Changeset 23
- Timestamp:
- Aug 29, 2025, 7:18:36 PM (10 hours ago)
- Location:
- trunk/fw_g473rct
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/Core/Inc/stm32g4xx_it.h
r22 r23 62 62 void DMA1_Channel5_IRQHandler(void); 63 63 void DMA1_Channel6_IRQHandler(void); 64 void DMA1_Channel7_IRQHandler(void); 64 65 void USART1_IRQHandler(void); 65 66 void USART2_IRQHandler(void); -
trunk/fw_g473rct/Core/Src/dma.c
r22 r23 63 63 HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0); 64 64 HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); 65 /* DMA1_Channel7_IRQn interrupt configuration */ 66 HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0); 67 HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); 65 68 66 69 } -
trunk/fw_g473rct/Core/Src/stm32g4xx_it.c
r22 r23 63 63 extern DMA_HandleTypeDef hdma_adc5; 64 64 extern DMA_HandleTypeDef hdma_usart2_rx; 65 extern DMA_HandleTypeDef hdma_usart2_tx; 65 66 extern UART_HandleTypeDef huart1; 66 67 extern UART_HandleTypeDef huart2; … … 292 293 293 294 /** 295 * @brief This function handles DMA1 channel7 global interrupt. 296 */ 297 void DMA1_Channel7_IRQHandler(void) 298 { 299 /* USER CODE BEGIN DMA1_Channel7_IRQn 0 */ 300 301 /* USER CODE END DMA1_Channel7_IRQn 0 */ 302 HAL_DMA_IRQHandler(&hdma_usart2_tx); 303 /* USER CODE BEGIN DMA1_Channel7_IRQn 1 */ 304 305 /* USER CODE END DMA1_Channel7_IRQn 1 */ 306 } 307 308 /** 294 309 * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25. 295 310 */ -
trunk/fw_g473rct/Core/Src/usart.c
r22 r23 28 28 UART_HandleTypeDef huart2; 29 29 DMA_HandleTypeDef hdma_usart2_rx; 30 DMA_HandleTypeDef hdma_usart2_tx; 30 31 31 32 /* USART1 init function */ … … 86 87 /* USER CODE END USART2_Init 1 */ 87 88 huart2.Instance = USART2; 88 huart2.Init.BaudRate = 1 15200;89 huart2.Init.BaudRate = 19200; 89 90 huart2.Init.WordLength = UART_WORDLENGTH_9B; 90 91 huart2.Init.StopBits = UART_STOPBITS_1; … … 209 210 __HAL_LINKDMA(uartHandle,hdmarx,hdma_usart2_rx); 210 211 212 /* USART2_TX Init */ 213 hdma_usart2_tx.Instance = DMA1_Channel7; 214 hdma_usart2_tx.Init.Request = DMA_REQUEST_USART2_TX; 215 hdma_usart2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; 216 hdma_usart2_tx.Init.PeriphInc = DMA_PINC_DISABLE; 217 hdma_usart2_tx.Init.MemInc = DMA_MINC_ENABLE; 218 hdma_usart2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 219 hdma_usart2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 220 hdma_usart2_tx.Init.Mode = DMA_NORMAL; 221 hdma_usart2_tx.Init.Priority = DMA_PRIORITY_LOW; 222 if (HAL_DMA_Init(&hdma_usart2_tx) != HAL_OK) 223 { 224 Error_Handler(); 225 } 226 227 __HAL_LINKDMA(uartHandle,hdmatx,hdma_usart2_tx); 228 211 229 /* USART2 interrupt Init */ 212 230 HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); … … 257 275 /* USART2 DMA DeInit */ 258 276 HAL_DMA_DeInit(uartHandle->hdmarx); 277 HAL_DMA_DeInit(uartHandle->hdmatx); 259 278 260 279 /* USART2 interrupt Deinit */ -
trunk/fw_g473rct/SES/inc/sysdata.h
r22 r23 33 33 //------------------------------------------------------------------------------ 34 34 // This structure must be aligned to 4-byte address 35 volatiletypedef struct35 typedef struct 36 36 { 37 37 // Device spezifisch / Einstellungsbereich -
trunk/fw_g473rct/SES/src/main.c
r22 r23 202 202 203 203 204 204 if(sys_data.s.parameter.command != 0) 205 205 { 206 206 if (modbusData.current_query == MB_QUERY_NOTHING) -
trunk/fw_g473rct/SES/src/modbus.c
r22 r23 67 67 #define FAST_BAUDRATE_INTERFRAME_DELAY_us (1750UL) 68 68 // --- Externe Variablen -------------------------------------------- 69 extern volatilemodbus_t modbusData;70 extern volatilesys_data_t sys_data;69 extern modbus_t modbusData; 70 extern sys_data_t sys_data; 71 71 72 72 … … 109 109 if (stopBits < 1U || stopBits > 2U) stopBits = 1U; 110 110 111 // Berechne Stop Bits 112 /*if ((parityMode== MODBUS_UART_PARITY_EVEN) || (parityMode == MODBUS_UART_PARITY_ODD)) 113 { 114 stopBits = 1; 115 } 116 else 117 { 118 stopBits = 2; 119 }*/ 120 111 121 112 // Berechne Anzahl der Bits per Char 122 113 numberOfBitsPerChar = NUMBER_OF_STARTBITS + NUMBER_OF_DATABITS + stopBits; … … 157 148 mb_data->uart = usart; 158 149 159 // Init aus Cube160 mb_data->uart->Instance = USART2;161 mb_data->uart->Init.BaudRate = baudrate;162 mb_data->uart->Init.WordLength = UART_WORDLENGTH_9B;163 mb_data->uart->Init.StopBits = UART_STOPBITS_1;164 mb_data->uart->Init.Parity = UART_PARITY_EVEN;165 mb_data->uart->Init.Mode = UART_MODE_TX_RX;166 mb_data->uart->Init.HwFlowCtl = UART_HWCONTROL_NONE;167 mb_data->uart->Init.OverSampling = UART_OVERSAMPLING_16;168 mb_data->uart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;169 mb_data->uart->Init.ClockPrescaler = UART_PRESCALER_DIV1;170 mb_data->uart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;171 mb_data->uart->AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;172 173 // Init änderungen174 175 150 // Baudrate 176 151 mb_data->uart->Init.BaudRate = baudrate; 152 177 153 // Parity Mode // Word length 178 154 if(parityMode == MODBUS_UART_PARITY_EVEN) … … 191 167 mb_data->uart->Init.WordLength = UART_WORDLENGTH_8B; 192 168 } 169 193 170 // Stopbits 194 171 if (stopBits == 1) … … 200 177 mb_data->uart->Init.StopBits = UART_STOPBITS_2; 201 178 } 202 // Init 203 // if (RS485_ModbusEx_Init(mb_data->uart, UART_DE_POLARITY_HIGH, 0, 0,TIMEOUT_FRAME_COMPLETE*nrOfBitsPerChar) != HAL_OK) 204 // { 205 // Error_Handler(); 206 // } 207 // if (HAL_UARTEx_DisableFifoMode(mb_data->uart) != HAL_OK) 208 // { 209 // Error_Handler(); 210 // } 179 180 if (HAL_UART_Init(mb_data->uart) != HAL_OK) 181 { 182 Error_Handler(); 183 } 184 211 185 uint32_t fixedDelayInBitDurations = (FAST_BAUDRATE_INTERFRAME_DELAY_us * baudrate) / 1000000UL + 1UL; 212 186 // HAL_UART_EnableReceiverTimeout( usart); … … 226 200 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) 227 201 { 202 modbusData.mb_rx_frame_complete = 1; 203 modbusData.setRxLed = false; 204 modbusData.rx_head= 0; 205 206 228 207 if (huart->ErrorCode == HAL_UART_ERROR_RTO) 229 208 { 230 modbusData.mb_rx_frame_complete = 1;231 modbusData.setRxLed = true;232 modbusData.rx_head= 8;233 209 printf("MB RTO Event! \n\r"); 234 210 } 211 if (huart->ErrorCode == HAL_UART_ERROR_FE) 212 { 213 printf("MB FE Error! \n\r"); 214 } 215 216 if (huart->ErrorCode == HAL_UART_ERROR_PE) 217 { 218 printf("MB PE Error! \n\r"); 219 } 220 221 if (huart->ErrorCode == HAL_UART_ERROR_NE) 222 { 223 printf("MB NE Error! \n\r"); 224 } 225 226 if (huart->ErrorCode == HAL_UART_ERROR_DMA) 227 { 228 printf("MB DMA Error! \n\r"); 229 } 230 231 if (huart->ErrorCode == HAL_UART_ERROR_DMA) 232 { 233 printf("MB DMA Error! \n\r"); 234 } 235 236 if (huart->ErrorCode == HAL_UART_ERROR_ORE) 237 { 238 printf("MB ORE Error! \n\r"); 239 } 240 241 242 if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK) 243 { 244 printf("Uart Error bei neustart nach Fehler \n\r"); 245 // while(1) 246 // { 247 // } 248 } 249 250 } 251 252 void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) 253 { 254 //printf("MB rxEvent!RX=%d \n\r",Size); 255 modbusData.setRxLed = true; 256 257 modbusData.mb_rx_frame_complete = 1; 258 modbusData.rx_head= Size +1; 235 259 236 260 if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK) … … 242 266 } 243 267 268 244 269 } 245 270 246 void HAL_UART Ex_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)271 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) 247 272 { 248 printf("MB rxEvent!RX=%d \n\r",Size); 249 modbusData.setRxLed = true; 250 251 modbusData.mb_rx_frame_complete = 1; 252 modbusData.rx_head= Size +1; 253 254 if(HAL_UARTEx_ReceiveToIdle_DMA(huart, huart->pRxBuffPtr, RXBUFFERSIZE) != HAL_OK) 255 { 256 printf("uart error \n\r"); 257 // while(1) 258 // { 259 // } 260 } 261 273 //printf("uart complete \n\r"); 274 modbusData.current_query = MB_QUERY_NOTHING; 262 275 263 276 } … … 286 299 { 287 300 mb_data->current_query = MB_QUERY_SEND_DATA; 288 HAL_UART_Transmit_ IT(mb_data->uart, mb_data->tx_buffer, mb_data->tx_head);301 HAL_UART_Transmit_DMA(mb_data->uart, mb_data->tx_buffer, mb_data->tx_head); 289 302 } 290 303 -
trunk/fw_g473rct/SES/src/sysdata.c
r22 r23 7 7 #include "sysdata.h" 8 8 9 volatilesys_data_t sys_data;9 sys_data_t sys_data; 10 10 11 11 void SYS_DATA_Init(void) -
trunk/fw_g473rct/fw_g473rct.ioc
r22 r23 175 175 Dma.Request4=ADC5 176 176 Dma.Request5=USART2_RX 177 Dma.RequestsNb=6 177 Dma.Request6=USART2_TX 178 Dma.RequestsNb=7 178 179 Dma.USART2_RX.5.Direction=DMA_PERIPH_TO_MEMORY 179 180 Dma.USART2_RX.5.EventEnable=DISABLE … … 193 194 Dma.USART2_RX.5.SyncRequestNumber=1 194 195 Dma.USART2_RX.5.SyncSignalID=NONE 196 Dma.USART2_TX.6.Direction=DMA_MEMORY_TO_PERIPH 197 Dma.USART2_TX.6.EventEnable=DISABLE 198 Dma.USART2_TX.6.Instance=DMA1_Channel7 199 Dma.USART2_TX.6.MemDataAlignment=DMA_MDATAALIGN_BYTE 200 Dma.USART2_TX.6.MemInc=DMA_MINC_ENABLE 201 Dma.USART2_TX.6.Mode=DMA_NORMAL 202 Dma.USART2_TX.6.PeriphDataAlignment=DMA_PDATAALIGN_BYTE 203 Dma.USART2_TX.6.PeriphInc=DMA_PINC_DISABLE 204 Dma.USART2_TX.6.Polarity=HAL_DMAMUX_REQ_GEN_RISING 205 Dma.USART2_TX.6.Priority=DMA_PRIORITY_LOW 206 Dma.USART2_TX.6.RequestNumber=1 207 Dma.USART2_TX.6.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber 208 Dma.USART2_TX.6.SignalID=NONE 209 Dma.USART2_TX.6.SyncEnable=DISABLE 210 Dma.USART2_TX.6.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT 211 Dma.USART2_TX.6.SyncRequestNumber=1 212 Dma.USART2_TX.6.SyncSignalID=NONE 195 213 FDCAN2.CalculateBaudRateNominal=2083333 196 214 FDCAN2.CalculateTimeBitNominal=480 … … 297 315 NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 298 316 NVIC.DMA1_Channel6_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 317 NVIC.DMA1_Channel7_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true 299 318 NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false 300 319 NVIC.ForceEnableDMAVector=true … … 545 564 USART1.Parity=PARITY_EVEN 546 565 USART1.VirtualMode-Asynchronous=VM_ASYNC 547 USART2.BaudRate=1 15200566 USART2.BaudRate=19200 548 567 USART2.IPParameters=VirtualMode-Asynchronous,Parity,BaudRate,SwapParam,WordLength 549 568 USART2.Parity=PARITY_EVEN
Note: See TracChangeset
for help on using the changeset viewer.