Skip to content

Commit dc39c39

Browse files
committed
Serial more generic
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 61a2fd8 commit dc39c39

File tree

17 files changed

+228
-3890
lines changed

17 files changed

+228
-3890
lines changed

cores/arduino/stm32/hal_uart_emul.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
*
9898
******************************************************************************
9999
*/
100-
100+
#if defined(TIM1_BASE) && defined(UART_EMUL_RX) && defined(UART_EMUL_TX)
101101
/* Includes ------------------------------------------------------------------*/
102102
#include "hal_uart_emul.h"
103103

@@ -687,7 +687,7 @@ static void UART_Emul_ReceiveFrame(UART_Emul_HandleTypeDef *huart, uint32_t *pDa
687687
uint32_t tmp_size =0;
688688
uint32_t tmp_arr =0;
689689

690-
tmp_arr = UART_EMUL_RX_TIMER_INSTANCE->ARR;
690+
tmp_arr = UART_EMUL_RX_TIMER_INSTANCE->ARR;
691691
tmp_ds = (uint32_t)pData;
692692
tmp_sr = (uint32_t) & (huart->RxPortName->IDR);
693693
tmp_size = __HAL_UART_EMUL_FRAME_LENGTH(huart);
@@ -698,6 +698,16 @@ static void UART_Emul_ReceiveFrame(UART_Emul_HandleTypeDef *huart, uint32_t *pDa
698698
/* Enable the transfer Error interrupt */
699699
__HAL_DMA_ENABLE_IT(&hdma_rx, DMA_IT_TE);
700700

701+
#if defined (STM32F0xx) || defined (STM32F3xx)
702+
/* Configure DMA Stream data length */
703+
hdma_rx.Instance->CNDTR = tmp_size;
704+
705+
/* Configure DMA Stream source address */
706+
hdma_rx.Instance->CPAR = tmp_sr;
707+
708+
/* Configure DMA Stream destination address */
709+
hdma_rx.Instance->CMAR = tmp_ds;
710+
#else
701711
/* Configure DMA Stream data length */
702712
hdma_rx.Instance->NDTR = tmp_size;
703713

@@ -706,7 +716,7 @@ static void UART_Emul_ReceiveFrame(UART_Emul_HandleTypeDef *huart, uint32_t *pDa
706716

707717
/* Configure DMA Stream destination address */
708718
hdma_rx.Instance->M0AR = tmp_ds;
709-
719+
#endif
710720
/* Enable the Peripheral */
711721
__HAL_DMA_ENABLE(&hdma_rx);
712722

@@ -795,18 +805,20 @@ static void UART_Emul_SetConfig_DMATx(void)
795805

796806
/*##-1- Configure DMA For UART Emulation TX #############################*/
797807
/* Set the parameters to be configured */
798-
hdma_tx.Init.Channel = DMA_Channel_Tx; /* Channel used */
799808
hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; /* Transfer mode */
800809
hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE; /* Peripheral increment mode Disable */
801810
hdma_tx.Init.MemInc = DMA_MINC_ENABLE; /* Memory increment mode Enable */
802811
hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD ; /* Peripheral data alignment : Word */
803812
hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD ; /* memory data alignment : Word */
804813
hdma_tx.Init.Mode = DMA_NORMAL; /* Normal DMA mode */
805814
hdma_tx.Init.Priority = DMA_PRIORITY_HIGH; /* Priority level : High */
815+
#ifdef STM32F4xx
816+
hdma_tx.Init.Channel = DMA_Channel_Tx; /* Channel used */
806817
hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; /* FIFO mode disable */
807818
hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; /* FIFO threshold level */
808819
hdma_tx.Init.MemBurst = DMA_MBURST_SINGLE; /* Memory Burst transfer */
809820
hdma_tx.Init.PeriphBurst = DMA_PBURST_SINGLE; /* Periph Burst transfer */
821+
#endif
810822

811823
/* Set hdma_tim instance */
812824
hdma_tx.Instance = DMA_Stream_Tx;
@@ -832,19 +844,20 @@ static void UART_Emul_SetConfig_DMARx(void)
832844
{
833845
/*##-1- Configure DMA For UART Emulation RX #############################*/
834846
/* Set the parameters to be configured */
835-
hdma_rx.Init.Channel = DMA_Channel_Rx; /* Channel used */
836847
hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; /* Transfer mode */
837848
hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE; /* Peripheral increment mode Disable */
838849
hdma_rx.Init.MemInc = DMA_MINC_ENABLE; /* Memory increment mode Enable */
839850
hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD ; /* Peripheral data alignment : Word */
840851
hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD ; /* memory data alignment : Word */
841852
hdma_rx.Init.Mode = DMA_NORMAL; /* Normal DMA mode */
842853
hdma_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH; /* Priority level : very High */
854+
#if defined(STM32F4xx)
855+
hdma_rx.Init.Channel = DMA_Channel_Rx; /* Channel used */
843856
hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; /* FIFO mode disable */
844857
hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; /* FIFO threshold level */
845858
hdma_rx.Init.MemBurst = DMA_MBURST_SINGLE; /* Memory Burst transfer */
846859
hdma_rx.Init.PeriphBurst = DMA_PBURST_SINGLE; /* Periph Burst transfer */
847-
860+
#endif
848861
/* Set hdma_tim instance */
849862
hdma_rx.Instance = DMA_Stream_Rx;
850863

@@ -1071,6 +1084,16 @@ static void UART_Emul_TransmitFrame(UART_Emul_HandleTypeDef *huart)
10711084

10721085
tmp_size = __HAL_UART_EMUL_FRAME_LENGTH(huart);
10731086

1087+
#if defined (STM32F0xx) || defined (STM32F3xx)
1088+
/* Configure DMA Stream data length */
1089+
hdma_rx.Instance->CNDTR = tmp_size;
1090+
1091+
/* Configure DMA Stream source address */
1092+
hdma_rx.Instance->CPAR = tmp_sr;
1093+
1094+
/* Configure DMA Stream destination address */
1095+
hdma_rx.Instance->CMAR = tmp_ds;
1096+
#else
10741097
/* Configure DMA Stream data length */
10751098
hdma_tx.Instance->NDTR = tmp_size;
10761099

@@ -1079,6 +1102,7 @@ static void UART_Emul_TransmitFrame(UART_Emul_HandleTypeDef *huart)
10791102

10801103
/* Configure DMA Stream source address */
10811104
hdma_tx.Instance->M0AR = tmp_sr;
1105+
#endif
10821106

10831107
/* Enable the transfer complete interrupt */
10841108
__HAL_DMA_ENABLE_IT(&hdma_tx, DMA_IT_TC);
@@ -1209,5 +1233,5 @@ __weak void HAL_UART_Emul_ErrorCallback(UART_Emul_HandleTypeDef *huart)
12091233
/**
12101234
* @}
12111235
*/
1212-
1236+
#endif //TIM1_BASE && UART_EMUL_RX && UART_EMUL_TX
12131237
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

cores/arduino/stm32/hal_uart_emul.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#ifndef __HAL_UART_EMUL_H
4141
#define __HAL_UART_EMUL_H
4242

43+
#if defined(TIM1_BASE)
4344
#ifdef __cplusplus
4445
extern "C" {
4546
#endif
@@ -109,8 +110,8 @@ typedef enum
109110
{
110111
HAL_UART_EMUL_ERROR_NONE = 0x00, /*!< No error */
111112
HAL_UART_EMUL_ERROR_FE = 0x01, /*!< frame error */
112-
HAL_UART_EMUL_ERROR_RE = 0x02, /*!< receiver error */
113-
HAL_UART_EMUL_ERROR_PE = 0x04 /*!< transfer error */
113+
HAL_UART_EMUL_ERROR_RE = 0x02, /*!< receiver error */
114+
HAL_UART_EMUL_ERROR_PE = 0x04 /*!< transfer error */
114115
}HAL_UART_Emul_ErrorTypeDef;
115116

116117
/**
@@ -132,7 +133,7 @@ typedef struct
132133

133134
UART_Emul_InitTypeDef Init; /* UART Emulation communication parameters */
134135

135-
uint8_t *pTxBuffPtr; /* Pointer to UART Emulation Tx transfer Buffer */
136+
uint8_t *pTxBuffPtr; /* Pointer to UART Emulation Tx transfer Buffer */
136137

137138
uint16_t TxXferSize; /* UART Emulation Tx Transfer size */
138139

@@ -144,9 +145,9 @@ typedef struct
144145

145146
uint16_t RxXferCount; /* UART Emulation Rx Transfer Counter */
146147

147-
GPIO_TypeDef *RxPortName; /* UART Emulation Rx port name */
148+
GPIO_TypeDef *RxPortName; /* UART Emulation Rx port name */
148149

149-
GPIO_TypeDef *TxPortName; /* UART Emulation Tx port name */
150+
GPIO_TypeDef *TxPortName; /* UART Emulation Tx port name */
150151

151152
__IO HAL_UART_Emul_StateTypeDef State; /* UART Emulation communication state */
152153

@@ -268,11 +269,26 @@ typedef struct
268269
#define TX_BUFFER_SIZE ((uint8_t)0x0C)
269270

270271
/* Definition Handler for UART Emulation receive mode */
272+
273+
#ifdef STM32F0xx
274+
#define UART_EMUL_TX_DMA_IRQHandler DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler
275+
#define UART_EMUL_RX_DMA_IRQHandler DMA1_Ch4_7_DMA2_Ch3_5_IRQHandler
276+
277+
#define UART_EMUL_TX_DMA_IRQn DMA1_Ch2_3_DMA2_Ch1_2_IRQn
278+
#define UART_EMUL_RX_DMA_IRQn DMA1_Ch4_7_DMA2_Ch3_5_IRQn
279+
#elif defined(STM32F3xx)
280+
#define UART_EMUL_TX_DMA_IRQHandler DMA2_Channel1_IRQHandler
281+
#define UART_EMUL_RX_DMA_IRQHandler DMA2_Channel3_IRQHandler
282+
283+
#define UART_EMUL_TX_DMA_IRQn DMA2_Channel1_IRQn
284+
#define UART_EMUL_RX_DMA_IRQn DMA2_Channel3_IRQn
285+
#elif defined(STM32F4xx)
271286
#define UART_EMUL_TX_DMA_IRQHandler DMA2_Stream1_IRQHandler
272287
#define UART_EMUL_RX_DMA_IRQHandler DMA2_Stream2_IRQHandler
273288

274289
#define UART_EMUL_TX_DMA_IRQn DMA2_Stream1_IRQn
275290
#define UART_EMUL_RX_DMA_IRQn DMA2_Stream2_IRQn
291+
#endif
276292

277293
/* Defenition of UART Emulation timer */
278294
#define UART_EMUL_TX_TIMER_INSTANCE TIM1
@@ -287,12 +303,18 @@ typedef struct
287303
#define TIM_DMA_source_Tx TIM_DMA_CC1
288304
#define TIM_DMA_source_Rx TIM_DMA_CC2
289305

306+
#ifdef STM32F4xx
290307
#define DMA_Channel_Tx DMA_CHANNEL_6
291308
#define DMA_Channel_Rx DMA_CHANNEL_6
309+
#endif
292310

311+
#ifdef DMA2_Stream1
293312
#define DMA_Stream_Tx DMA2_Stream1
294313
#define DMA_Stream_Rx DMA2_Stream2
295-
314+
#else
315+
#define DMA_Stream_Tx DMA2_Channel1
316+
#define DMA_Stream_Rx DMA2_Channel3
317+
#endif
296318
/* Exported macro ------------------------------------------------------------*/
297319

298320
/** @brief Checks whether the specified UART Emulation flag is set or not.
@@ -389,7 +411,7 @@ uint32_t HAL_UART_Emul_GetError(UART_Emul_HandleTypeDef *huart);
389411
#ifdef __cplusplus
390412
}
391413
#endif
392-
414+
#endif //TIM1_BASE
393415
#endif /* __HAL_UART_EMUL_H */
394416

395417
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

cores/arduino/stm32/stm32_def.h

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,28 @@
4646
#error "STM32YYxx chip series is not defined in boards.txt."
4747
#endif
4848

49+
// Here define some compatibility
4950
#ifdef STM32F0xx
50-
#ifndef __HAL_RCC_UART4_CLK_ENABLE
51-
#define __HAL_RCC_UART4_CLK_ENABLE __HAL_RCC_USART4_CLK_ENABLE
52-
#endif
53-
#ifndef __HAL_RCC_UART4_RELEASE_RESET
54-
#define __HAL_RCC_UART4_RELEASE_RESET __HAL_RCC_USART4_RELEASE_RESET
55-
#endif
56-
#ifndef __HAL_RCC_UART4_FORCE_RESET
57-
#define __HAL_RCC_UART4_FORCE_RESET __HAL_RCC_USART4_FORCE_RESET
58-
#endif
59-
#endif
51+
#define USART3_IRQn USART3_8_IRQn
52+
#define USART6_IRQn USART3_8_IRQn
53+
54+
#elif defined(STM32F1xx)
6055

61-
#ifdef STM32F3xx
62-
#ifndef EXTI2_IRQn
56+
#elif defined(STM32F2xx)
57+
58+
#elif defined(STM32F3xx)
6359
#define EXTI2_IRQn EXTI2_TSC_IRQn
60+
61+
#elif defined(STM32F4xx)
62+
63+
#elif defined(STM32F7xx)
64+
65+
#elif defined(STM32L0xx)
66+
67+
#elif defined(STM32L1xx)
68+
69+
#elif defined(STM32L4xx)
6470
#endif
65-
#endif
71+
72+
6673
#endif //_STM32_DEF_

cores/arduino/stm32/uart.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
522522
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
523523
{
524524
volatile uint32_t tmpval;
525-
525+
#ifdef STM32F4xx
526526
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
527527
tmpval = huart->Instance->DR; // Clear PE flag
528528
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
@@ -532,6 +532,17 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
532532
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
533533
tmpval = huart->Instance->DR; // Clear ORE flag
534534
}
535+
#else
536+
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
537+
tmpval = huart->Instance->RDR; // Clear PE flag
538+
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
539+
tmpval = huart->Instance->RDR; // Clear FE flag
540+
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
541+
tmpval = huart->Instance->RDR; // Clear NE flag
542+
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
543+
tmpval = huart->Instance->RDR; // Clear ORE flag
544+
}
545+
#endif
535546

536547
UNUSED(tmpval);
537548
}

0 commit comments

Comments
 (0)