changeset 890:651d21777b61 Evo_2_23

cleanup and disable function for GNSS uart and DMA
author heinrichsweikamp
date Fri, 06 Sep 2024 18:43:30 +0200
parents cf3967fe6924
children a7f4451ba69e 9e2f9b91e827
files Small_CPU/Inc/uart.h Small_CPU/Src/baseCPU2.c Small_CPU/Src/uart.c
diffstat 3 files changed, 58 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Small_CPU/Inc/uart.h	Fri Sep 06 16:46:22 2024 +0200
+++ b/Small_CPU/Inc/uart.h	Fri Sep 06 18:43:30 2024 +0200
@@ -37,6 +37,7 @@
 
 void MX_USART6_UART_Init(void);
 void MX_USART6_DMA_Init(void);
+void MX_USART6_UART_DeInit(void);
 void GNSS_IO_init(void);
 
 uint8_t UART_ButtonAdjust(uint8_t *array);
--- a/Small_CPU/Src/baseCPU2.c	Fri Sep 06 16:46:22 2024 +0200
+++ b/Small_CPU/Src/baseCPU2.c	Fri Sep 06 18:43:30 2024 +0200
@@ -436,13 +436,39 @@
 			GNSS_Init(&GNSS_Handle, &huart6);
 			HAL_Delay(1000);
 			GNSS_LoadConfig(&GNSS_Handle);
-			HAL_Delay(10);
+			HAL_Delay(250);
 			GNSS_GetUniqID(&GNSS_Handle);
 			GNSS_ParseBuffer(&GNSS_Handle);
-			HAL_Delay(10);
+			HAL_Delay(250);
 			GNSS_GetPVTData(&GNSS_Handle);
 			GNSS_ParseBuffer(&GNSS_Handle);
 
+/*
+ * Demo code from SimpleMethod
+ * called 1/second
+			while (1) {
+
+				if ((HAL_GetTick() - Timer) > 1000) {
+					GNSS_GetUniqID(&GNSS_Handle);
+					GNSS_ParseBuffer(&GNSS_Handle);
+					HAL_Delay(250);
+					GNSS_GetPVTData(&GNSS_Handle);
+					GNSS_ParseBuffer(&GNSS_Handle);
+					printf("Day: %d-%d-%d \r\n", GNSS_Handle.day, GNSS_Handle.month,GNSS_Handle.year);
+					printf("Time: %d:%d:%d \r\n", GNSS_Handle.hour, GNSS_Handle.min,GNSS_Handle.sec);
+					printf("Status of fix: %d \r\n", GNSS_Handle.fixType);
+					printf("Latitude: %f \r\n", GNSS_Handle.fLat);
+					printf("Longitude: %f \r\n",(float) GNSS_Handle.lon / 10000000.0);
+					printf("Height above ellipsoid: %d \r\n", GNSS_Handle.height);
+					printf("Height above mean sea level: %d \r\n", GNSS_Handle.hMSL);
+					printf("Ground Speed (2-D): %d \r\n", GNSS_Handle.gSpeed);
+					printf("Unique ID: %04X %04X %04X %04X %04X \n\r",
+							GNSS_Handle.uniqueID[0], GNSS_Handle.uniqueID[1],
+							GNSS_Handle.uniqueID[2], GNSS_Handle.uniqueID[3],
+							GNSS_Handle.uniqueID[4], GNSS_Handle.uniqueID[5]);
+					Timer = HAL_GetTick();
+				}
+*/
 
 			global.mode = MODE_SURFACE;
 			break;
@@ -1003,6 +1029,7 @@
 	GPIO_GPS_BCKP_ON();			// mH : costs 100µA in sleep - beware
 	GPIO_GPS_OFF();
 
+	MX_USART6_UART_DeInit();
 
 #ifndef DEBUGMODE
 	__HAL_RCC_GPIOB_CLK_DISABLE();
--- a/Small_CPU/Src/uart.c	Fri Sep 06 16:46:22 2024 +0200
+++ b/Small_CPU/Src/uart.c	Fri Sep 06 18:43:30 2024 +0200
@@ -39,13 +39,13 @@
 
 DMA_HandleTypeDef  hdma_usart1_rx, hdma_usart6_rx, hdma_usart6_tx;
 
-uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER];		/* The complete buffer has a X * chunk size to allow fariations in buffer read time */
-uint8_t rxBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER];		/* The complete buffer has a X * chunk size to allow fariations in buffer read time */
-uint8_t txBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER];		/* The complete buffer has a X * chunk size to allow fariations in buffer read time */
+uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER];		/* The complete buffer has a X * chunk size to allow variations in buffer read time */
+uint8_t rxBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER];		/* The complete buffer has a X * chunk size to allow variations in buffer read time */
+uint8_t txBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER];		/* The complete buffer has a X * chunk size to allow variations in buffer read time */
 
 static uint8_t rxWriteIndex;							/* Index of the data item which is analysed */
 static uint8_t rxReadIndex;								/* Index at which new data is stared */
-static uint8_t lastCmdIndex;							/* Index of last command which has not been completly received */
+static uint8_t lastCmdIndex;							/* Index of last command which has not been completely received */
 static uint8_t dmaActive;								/* Indicator if DMA reception needs to be started */
 
 
@@ -113,13 +113,16 @@
   HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
 }
 
+
 void GNSS_IO_init() {
 
 	GPIO_InitTypeDef GPIO_InitStruct = { 0 };
 	/* Peripheral clock enable */
-	__HAL_RCC_USART6_CLK_ENABLE();
+	__HAL_RCC_USART6_CLK_ENABLE()
+	;
 
-	__HAL_RCC_GPIOA_CLK_ENABLE();
+	__HAL_RCC_GPIOA_CLK_ENABLE()
+	;
 	/**USART6 GPIO Configuration
 	 PA11     ------> USART6_TX
 	 PA12     ------> USART6_RX
@@ -165,9 +168,6 @@
 	/* USART6 interrupt Init */
 	HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
 	HAL_NVIC_EnableIRQ(USART6_IRQn);
-	/* USER CODE BEGIN USART6_MspInit 1 */
-
-	/* USER CODE END USART6_MspInit 1 */
 
 	MX_USART6_DMA_Init();
 
@@ -186,33 +186,27 @@
 	  HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
 }
 
-/**
-  * @brief USART6 Initialization Function
-  * @param None
-  * @retval None
-  */
-void MX_USART6_UART_Init(void)
+
+void MX_USART6_UART_DeInit(void)
 {
-  /* USER CODE BEGIN USART6_Init 0 */
-
-  /* USER CODE END USART6_Init 0 */
-
-  /* USER CODE BEGIN USART6_Init 1 */
+	HAL_DMA_Abort(&hdma_usart6_rx);
+	HAL_DMA_DeInit(&hdma_usart6_rx);
+	HAL_DMA_Abort(&hdma_usart6_tx);
+	HAL_DMA_DeInit(&hdma_usart6_tx);
+	HAL_UART_DeInit(&huart6);
+	HAL_UART_DeInit(&huart6);
+}
 
-  /* USER CODE END USART6_Init 1 */
-  huart6.Instance = USART6;
-  huart6.Init.BaudRate = 9600;
-  huart6.Init.WordLength = UART_WORDLENGTH_8B;
-  huart6.Init.StopBits = UART_STOPBITS_1;
-  huart6.Init.Parity = UART_PARITY_NONE;
-  huart6.Init.Mode = UART_MODE_TX_RX;
-  huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
-  huart6.Init.OverSampling = UART_OVERSAMPLING_16;
-  HAL_UART_Init(&huart6);
-
-  /* USER CODE BEGIN USART6_Init 2 */
-
-  /* USER CODE END USART6_Init 2 */
+void MX_USART6_UART_Init(void) {
+	huart6.Instance = USART6;
+	huart6.Init.BaudRate = 9600;
+	huart6.Init.WordLength = UART_WORDLENGTH_8B;
+	huart6.Init.StopBits = UART_STOPBITS_1;
+	huart6.Init.Parity = UART_PARITY_NONE;
+	huart6.Init.Mode = UART_MODE_TX_RX;
+	huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+	huart6.Init.OverSampling = UART_OVERSAMPLING_16;
+	HAL_UART_Init(&huart6);
 }
 
 void  UART_MUX_SelectAddress(uint8_t muxAddress)