Mercurial > public > ostc4
comparison Small_CPU/Src/uart_Internal.c @ 1000:c386ae6635e4 GasConsumption
Improve GNSS operation:
during OSTC 4/5 code merge a problem with the wakeup of the gnss module showed up which has been fixed with the new verion. In addition a compile switch has been added which activated the synchronization of time between OSTC and gnss module. This my cause problems if the time is not accurate => deactivated at the moment.
| author | Ideenmodellierer |
|---|---|
| date | Mon, 28 Apr 2025 19:51:36 +0200 |
| parents | 0b81ac558e89 |
| children |
comparison
equal
deleted
inserted
replaced
| 999:ac25c35a3c97 | 1000:c386ae6635e4 |
|---|---|
| 62 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | 62 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
| 63 GPIO_InitStruct.Pull = GPIO_NOPULL; | 63 GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 64 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; | 64 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; |
| 65 GPIO_InitStruct.Alternate = GPIO_AF8_USART6; | 65 GPIO_InitStruct.Alternate = GPIO_AF8_USART6; |
| 66 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | 66 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 67 } | |
| 68 | |
| 69 void MX_USART6_DMA_Init() { | |
| 70 /* DMA controller clock enable */ | |
| 71 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 72 | |
| 73 /* DMA interrupt init */ | |
| 74 /* DMA2_Stream2_IRQn interrupt configuration */ | |
| 75 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); | |
| 76 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); | |
| 77 /* DMA2_Stream6_IRQn interrupt configuration */ | |
| 78 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0); | |
| 79 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn); | |
| 80 } | |
| 81 | |
| 82 | |
| 83 void MX_USART6_UART_DeInit(void) | |
| 84 { | |
| 85 HAL_DMA_Abort(&hdma_usart6_rx); | |
| 86 HAL_DMA_DeInit(&hdma_usart6_rx); | |
| 87 HAL_DMA_Abort(&hdma_usart6_tx); | |
| 88 HAL_DMA_DeInit(&hdma_usart6_tx); | |
| 89 HAL_UART_DeInit(&huart6); | |
| 90 //HAL_UART_DeInit(&huart6); | |
| 91 Uart6Ctrl.dmaRxActive = 0; | |
| 92 Uart6Ctrl.dmaTxActive = 0; | |
| 93 } | |
| 94 | |
| 95 void MX_USART6_UART_Init(void) { | |
| 96 huart6.Instance = USART6; | |
| 97 huart6.Init.BaudRate = 9600; | |
| 98 huart6.Init.WordLength = UART_WORDLENGTH_8B; | |
| 99 huart6.Init.StopBits = UART_STOPBITS_1; | |
| 100 huart6.Init.Parity = UART_PARITY_NONE; | |
| 101 huart6.Init.Mode = UART_MODE_TX_RX; | |
| 102 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 103 huart6.Init.OverSampling = UART_OVERSAMPLING_16; | |
| 104 HAL_UART_Init(&huart6); | |
| 105 | |
| 106 Uart6Ctrl.pHandle = &huart6; | |
| 107 Uart6Ctrl.dmaRxActive = 0; | |
| 108 Uart6Ctrl.dmaTxActive = 0; | |
| 109 Uart6Ctrl.pRxBuffer = rxBufferUart6; | |
| 110 Uart6Ctrl.pTxBuffer = txBufferUart6; | |
| 111 Uart6Ctrl.rxReadIndex = 0; | |
| 112 Uart6Ctrl.rxWriteIndex = 0; | |
| 113 Uart6Ctrl.txBufferQueLen = 0; | |
| 114 | |
| 115 UART_clearRxBuffer(&Uart6Ctrl); | |
| 116 UART_SetGnssCtrl(&Uart6Ctrl); | |
| 67 | 117 |
| 68 /* USART6 DMA Init */ | 118 /* USART6 DMA Init */ |
| 69 /* USART6_RX Init */ | 119 /* USART6_RX Init */ |
| 70 hdma_usart6_rx.Instance = DMA2_Stream2; | 120 hdma_usart6_rx.Instance = DMA2_Stream2; |
| 71 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5; | 121 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5; |
| 99 /* USART6 interrupt Init */ | 149 /* USART6 interrupt Init */ |
| 100 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0); | 150 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0); |
| 101 HAL_NVIC_EnableIRQ(USART6_IRQn); | 151 HAL_NVIC_EnableIRQ(USART6_IRQn); |
| 102 | 152 |
| 103 MX_USART6_DMA_Init(); | 153 MX_USART6_DMA_Init(); |
| 104 | |
| 105 } | |
| 106 | |
| 107 void MX_USART6_DMA_Init() { | |
| 108 /* DMA controller clock enable */ | |
| 109 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 110 | |
| 111 /* DMA interrupt init */ | |
| 112 /* DMA2_Stream2_IRQn interrupt configuration */ | |
| 113 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); | |
| 114 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); | |
| 115 /* DMA2_Stream6_IRQn interrupt configuration */ | |
| 116 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0); | |
| 117 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn); | |
| 118 } | |
| 119 | |
| 120 | |
| 121 void MX_USART6_UART_DeInit(void) | |
| 122 { | |
| 123 HAL_DMA_Abort(&hdma_usart6_rx); | |
| 124 HAL_DMA_DeInit(&hdma_usart6_rx); | |
| 125 HAL_DMA_Abort(&hdma_usart6_tx); | |
| 126 HAL_DMA_DeInit(&hdma_usart6_tx); | |
| 127 HAL_UART_DeInit(&huart6); | |
| 128 HAL_UART_DeInit(&huart6); | |
| 129 } | |
| 130 | |
| 131 void MX_USART6_UART_Init(void) { | |
| 132 huart6.Instance = USART6; | |
| 133 huart6.Init.BaudRate = 9600; | |
| 134 huart6.Init.WordLength = UART_WORDLENGTH_8B; | |
| 135 huart6.Init.StopBits = UART_STOPBITS_1; | |
| 136 huart6.Init.Parity = UART_PARITY_NONE; | |
| 137 huart6.Init.Mode = UART_MODE_TX_RX; | |
| 138 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 139 huart6.Init.OverSampling = UART_OVERSAMPLING_16; | |
| 140 HAL_UART_Init(&huart6); | |
| 141 | |
| 142 UART_clearRxBuffer(&Uart6Ctrl); | |
| 143 | |
| 144 Uart6Ctrl.pHandle = &huart6; | |
| 145 Uart6Ctrl.dmaRxActive = 0; | |
| 146 Uart6Ctrl.dmaTxActive = 0; | |
| 147 Uart6Ctrl.pRxBuffer = rxBufferUart6; | |
| 148 Uart6Ctrl.pTxBuffer = txBufferUart6; | |
| 149 Uart6Ctrl.rxReadIndex = 0; | |
| 150 Uart6Ctrl.rxWriteIndex = 0; | |
| 151 Uart6Ctrl.txBufferQueLen = 0; | |
| 152 | |
| 153 UART_SetGnssCtrl(&Uart6Ctrl); | |
| 154 } | 154 } |
| 155 | 155 |
| 156 void UART6_HandleUART() | 156 void UART6_HandleUART() |
| 157 { | 157 { |
| 158 static uint8_t retryRequest = 0; | 158 static uint8_t retryRequest = 0; |
| 161 static uint16_t timeToTrigger = 0; | 161 static uint16_t timeToTrigger = 0; |
| 162 uint32_t tick = HAL_GetTick(); | 162 uint32_t tick = HAL_GetTick(); |
| 163 | 163 |
| 164 uartGnssStatus_t gnssState = uartGnss_GetState(); | 164 uartGnssStatus_t gnssState = uartGnss_GetState(); |
| 165 | 165 |
| 166 if(gnssState != UART_GNSS_INIT) | 166 if(Uart6Ctrl.pHandle != 0) |
| 167 { | |
| 168 if((gnssState != UART_GNSS_INIT) && (gnssState != UART_GNSS_PWRUP)) | |
| 167 { | 169 { |
| 168 UART_ReadData(SENSOR_GNSS, 0); | 170 UART_ReadData(SENSOR_GNSS, 0); |
| 169 UART_WriteData(&Uart6Ctrl); | 171 UART_WriteData(&Uart6Ctrl); |
| 170 } | 172 } |
| 171 if(gnssState == UART_GNSS_INIT) | 173 if(gnssState == UART_GNSS_INIT) |
| 184 lastRequestTick = tick; | 186 lastRequestTick = tick; |
| 185 gnssState = UART_GNSS_PWRUP; | 187 gnssState = UART_GNSS_PWRUP; |
| 186 uartGnss_SetState(gnssState); | 188 uartGnss_SetState(gnssState); |
| 187 } | 189 } |
| 188 else if(((retryRequest == 0) /* timeout or error */ | 190 else if(((retryRequest == 0) /* timeout or error */ |
| 189 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (gnssState != UART_GNSS_IDLE)) /* retry if no answer after half request interval */ | 191 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (gnssState != UART_GNSS_IDLE) && (gnssState != UART_GNSS_PWRUP)) /* retry if no answer after half request interval */ |
| 190 || (gnssState == UART_GNSS_ERROR)))) | 192 || (gnssState == UART_GNSS_ERROR)))) |
| 191 { | 193 { |
| 192 /* The channel switch will cause the sensor to respond with an error message. */ | 194 /* The channel switch will cause the sensor to respond with an error message. */ |
| 193 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */ | 195 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */ |
| 194 | 196 |
| 214 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger)) | 216 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger)) |
| 215 { | 217 { |
| 216 timeToTrigger = 0; | 218 timeToTrigger = 0; |
| 217 uartGnss_Control(); | 219 uartGnss_Control(); |
| 218 } | 220 } |
| 219 | 221 } |
| 220 } | 222 } |
| 221 | 223 |
| 222 | 224 |
| 223 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | 225 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
