Skip to content

Commit c4bd01b

Browse files
committed
UART work
1 parent e44e1d2 commit c4bd01b

11 files changed

Lines changed: 394 additions & 106 deletions

File tree

DASH/.mxproject

Lines changed: 41 additions & 39 deletions
Large diffs are not rendered by default.

DASH/Core/Inc/dma.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file dma.h
5+
* @brief This file contains all the function prototypes for
6+
* the dma.c file
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2026 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef __DMA_H__
22+
#define __DMA_H__
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/* Includes ------------------------------------------------------------------*/
29+
#include "main.h"
30+
31+
/* DMA memory to memory transfer handles -------------------------------------*/
32+
33+
/* USER CODE BEGIN Includes */
34+
35+
/* USER CODE END Includes */
36+
37+
/* USER CODE BEGIN Private defines */
38+
39+
/* USER CODE END Private defines */
40+
41+
void MX_DMA_Init(void);
42+
43+
/* USER CODE BEGIN Prototypes */
44+
45+
/* USER CODE END Prototypes */
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /* __DMA_H__ */
52+

DASH/Core/Inc/stm32f4xx_it.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ void MemManage_Handler(void);
5252
void BusFault_Handler(void);
5353
void UsageFault_Handler(void);
5454
void DebugMon_Handler(void);
55+
void DMA1_Stream1_IRQHandler(void);
56+
void DMA1_Stream3_IRQHandler(void);
5557
void CAN1_TX_IRQHandler(void);
5658
void CAN1_RX0_IRQHandler(void);
5759
void CAN1_RX1_IRQHandler(void);
5860
void CAN1_SCE_IRQHandler(void);
61+
void USART3_IRQHandler(void);
5962
void TIM6_DAC_IRQHandler(void);
6063
void LTDC_IRQHandler(void);
6164
void DMA2D_IRQHandler(void);

DASH/Core/Src/dma.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file dma.c
5+
* @brief This file provides code for the configuration
6+
* of all the requested memory to memory DMA transfers.
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2026 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
21+
/* Includes ------------------------------------------------------------------*/
22+
#include "dma.h"
23+
24+
/* USER CODE BEGIN 0 */
25+
26+
/* USER CODE END 0 */
27+
28+
/*----------------------------------------------------------------------------*/
29+
/* Configure DMA */
30+
/*----------------------------------------------------------------------------*/
31+
32+
/* USER CODE BEGIN 1 */
33+
34+
/* USER CODE END 1 */
35+
36+
/**
37+
* Enable DMA controller clock
38+
*/
39+
void MX_DMA_Init(void)
40+
{
41+
42+
/* DMA controller clock enable */
43+
__HAL_RCC_DMA1_CLK_ENABLE();
44+
45+
/* DMA interrupt init */
46+
/* DMA1_Stream1_IRQn interrupt configuration */
47+
HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0);
48+
HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
49+
/* DMA1_Stream3_IRQn interrupt configuration */
50+
HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 5, 0);
51+
HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn);
52+
53+
}
54+
55+
/* USER CODE BEGIN 2 */
56+
57+
/* USER CODE END 2 */
58+

DASH/Core/Src/freertos.c

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ const osThreadAttr_t displayTask_attributes = {
6363
.stack_size = 1024 * 4,
6464
.priority = (osPriority_t) osPriorityHigh,
6565
};
66-
/* Definitions for FEB_I2C_Mutex */
67-
osMutexId_t FEB_I2C_MutexHandle;
68-
const osMutexAttr_t FEB_I2C_Mutex_attributes = {
69-
.name = "FEB_I2C_Mutex"
70-
};
7166
/* Definitions for uartRxTask */
7267
osThreadId_t uartRxTaskHandle;
7368
const osThreadAttr_t uartRxTask_attributes = {
@@ -96,17 +91,23 @@ const osThreadAttr_t DASHTaskTx_attributes = {
9691
.stack_size = 512 * 4,
9792
.priority = (osPriority_t) osPriorityLow,
9893
};
94+
/* Definitions for FEB_I2C_Mutex */
95+
osMutexId_t FEB_I2C_MutexHandle;
96+
const osMutexAttr_t FEB_I2C_Mutex_attributes = {
97+
.name = "FEB_I2C_Mutex"
98+
};
9999

100100
/* Private function prototypes -----------------------------------------------*/
101101
/* USER CODE BEGIN FunctionPrototypes */
102-
void StartUartRxTask(void *argument);
103-
void StartUartTxTask(void *argument);
104-
void StartDASHTaskRx(void *argument);
105-
void StartDASHTaskTx(void *argument);
102+
106103
/* USER CODE END FunctionPrototypes */
107104

108105
void StartBtnTxLoop(void *argument);
109106
void StartDisplayTask(void *argument);
107+
void StartUartRxTask(void *argument);
108+
void StartUartTxTask(void *argument);
109+
void StartDASHTaskRx(void *argument);
110+
void StartDASHTaskTx(void *argument);
110111

111112
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
112113

@@ -191,7 +192,6 @@ void MX_FREERTOS_Init(void) {
191192
/* creation of displayTask */
192193
displayTaskHandle = osThreadNew(StartDisplayTask, NULL, &displayTask_attributes);
193194

194-
/* USER CODE BEGIN RTOS_THREADS */
195195
/* creation of uartRxTask */
196196
uartRxTaskHandle = osThreadNew(StartUartRxTask, NULL, &uartRxTask_attributes);
197197

@@ -203,6 +203,9 @@ void MX_FREERTOS_Init(void) {
203203

204204
/* creation of DASHTaskTx */
205205
DASHTaskTxHandle = osThreadNew(StartDASHTaskTx, NULL, &DASHTaskTx_attributes);
206+
207+
/* USER CODE BEGIN RTOS_THREADS */
208+
206209
/* USER CODE END RTOS_THREADS */
207210

208211
/* USER CODE BEGIN RTOS_EVENTS */
@@ -247,42 +250,80 @@ __weak void StartDisplayTask(void *argument)
247250
/* USER CODE END StartDisplayTask */
248251
}
249252

250-
/* Private application code --------------------------------------------------*/
251-
/* USER CODE BEGIN Application */
253+
/* USER CODE BEGIN Header_StartUartRxTask */
254+
/**
255+
* @brief Function implementing the uartRxTask thread.
256+
* @param argument: Not used
257+
* @retval None
258+
*/
259+
/* USER CODE END Header_StartUartRxTask */
252260
__weak void StartUartRxTask(void *argument)
253261
{
254-
(void)argument;
255-
for (;;)
262+
/* USER CODE BEGIN StartUartRxTask */
263+
/* Infinite loop */
264+
for(;;)
256265
{
257266
osDelay(1);
258267
}
268+
/* USER CODE END StartUartRxTask */
259269
}
260270

271+
/* USER CODE BEGIN Header_StartUartTxTask */
272+
/**
273+
* @brief Function implementing the uartTxTask thread.
274+
* @param argument: Not used
275+
* @retval None
276+
*/
277+
/* USER CODE END Header_StartUartTxTask */
261278
__weak void StartUartTxTask(void *argument)
262279
{
263-
(void)argument;
264-
for (;;)
280+
/* USER CODE BEGIN StartUartTxTask */
281+
/* Infinite loop */
282+
for(;;)
265283
{
266-
osDelay(100);
284+
osDelay(1);
267285
}
286+
/* USER CODE END StartUartTxTask */
268287
}
269288

289+
/* USER CODE BEGIN Header_StartDASHTaskRx */
290+
/**
291+
* @brief Function implementing the DASHTaskRx thread.
292+
* @param argument: Not used
293+
* @retval None
294+
*/
295+
/* USER CODE END Header_StartDASHTaskRx */
270296
__weak void StartDASHTaskRx(void *argument)
271297
{
272-
(void)argument;
273-
for (;;)
298+
/* USER CODE BEGIN StartDASHTaskRx */
299+
/* Infinite loop */
300+
for(;;)
274301
{
275302
osDelay(1);
276303
}
304+
/* USER CODE END StartDASHTaskRx */
277305
}
278306

307+
/* USER CODE BEGIN Header_StartDASHTaskTx */
308+
/**
309+
* @brief Function implementing the DASHTaskTx thread.
310+
* @param argument: Not used
311+
* @retval None
312+
*/
313+
/* USER CODE END Header_StartDASHTaskTx */
279314
__weak void StartDASHTaskTx(void *argument)
280315
{
281-
(void)argument;
282-
for (;;)
316+
/* USER CODE BEGIN StartDASHTaskTx */
317+
/* Infinite loop */
318+
for(;;)
283319
{
284320
osDelay(1);
285321
}
322+
/* USER CODE END StartDASHTaskTx */
286323
}
324+
325+
/* Private application code --------------------------------------------------*/
326+
/* USER CODE BEGIN Application */
327+
287328
/* USER CODE END Application */
288329

DASH/Core/Src/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "cmsis_os.h"
2222
#include "can.h"
2323
#include "crc.h"
24+
#include "dma.h"
2425
#include "dma2d.h"
2526
#include "dsihost.h"
2627
#include "fatfs.h"
@@ -107,6 +108,7 @@ int main(void)
107108

108109
/* Initialize all configured peripherals */
109110
MX_GPIO_Init();
111+
MX_DMA_Init();
110112
MX_CAN1_Init();
111113
MX_CRC_Init();
112114
MX_DMA2D_Init();

DASH/Core/Src/stm32f4xx_it.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "stm32f4xx_it.h"
2323
/* Private includes ----------------------------------------------------------*/
2424
/* USER CODE BEGIN Includes */
25+
#include "feb_uart.h"
2526
/* USER CODE END Includes */
2627

2728
/* Private typedef -----------------------------------------------------------*/
@@ -59,10 +60,13 @@ extern CAN_HandleTypeDef hcan1;
5960
extern DMA2D_HandleTypeDef hdma2d;
6061
extern DSI_HandleTypeDef hdsi;
6162
extern LTDC_HandleTypeDef hltdc;
63+
extern DMA_HandleTypeDef hdma_usart3_rx;
64+
extern DMA_HandleTypeDef hdma_usart3_tx;
65+
extern UART_HandleTypeDef huart3;
6266
extern TIM_HandleTypeDef htim6;
6367

6468
/* USER CODE BEGIN EV */
65-
69+
extern UART_HandleTypeDef huart3;
6670
/* USER CODE END EV */
6771

6872
/******************************************************************************/
@@ -163,6 +167,34 @@ void DebugMon_Handler(void)
163167
/* please refer to the startup file (startup_stm32f4xx.s). */
164168
/******************************************************************************/
165169

170+
/**
171+
* @brief This function handles DMA1 stream1 global interrupt.
172+
*/
173+
void DMA1_Stream1_IRQHandler(void)
174+
{
175+
/* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
176+
177+
/* USER CODE END DMA1_Stream1_IRQn 0 */
178+
HAL_DMA_IRQHandler(&hdma_usart3_rx);
179+
/* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
180+
181+
/* USER CODE END DMA1_Stream1_IRQn 1 */
182+
}
183+
184+
/**
185+
* @brief This function handles DMA1 stream3 global interrupt.
186+
*/
187+
void DMA1_Stream3_IRQHandler(void)
188+
{
189+
/* USER CODE BEGIN DMA1_Stream3_IRQn 0 */
190+
191+
/* USER CODE END DMA1_Stream3_IRQn 0 */
192+
HAL_DMA_IRQHandler(&hdma_usart3_tx);
193+
/* USER CODE BEGIN DMA1_Stream3_IRQn 1 */
194+
195+
/* USER CODE END DMA1_Stream3_IRQn 1 */
196+
}
197+
166198
/**
167199
* @brief This function handles CAN1 TX interrupts.
168200
*/
@@ -219,6 +251,20 @@ void CAN1_SCE_IRQHandler(void)
219251
/* USER CODE END CAN1_SCE_IRQn 1 */
220252
}
221253

254+
/**
255+
* @brief This function handles USART3 global interrupt.
256+
*/
257+
void USART3_IRQHandler(void)
258+
{
259+
/* USER CODE BEGIN USART3_IRQn 0 */
260+
FEB_UART_IDLE_Callback(&huart3);
261+
/* USER CODE END USART3_IRQn 0 */
262+
HAL_UART_IRQHandler(&huart3);
263+
/* USER CODE BEGIN USART3_IRQn 1 */
264+
265+
/* USER CODE END USART3_IRQn 1 */
266+
}
267+
222268
/**
223269
* @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts.
224270
*/
@@ -276,5 +322,13 @@ void DSI_IRQHandler(void)
276322
}
277323

278324
/* USER CODE BEGIN 1 */
325+
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
326+
{
327+
FEB_UART_TxCpltCallback(huart);
328+
}
279329

330+
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
331+
{
332+
FEB_UART_RxEventCallback(huart, Size);
333+
}
280334
/* USER CODE END 1 */

0 commit comments

Comments
 (0)