Skip to content

Commit 465c3db

Browse files
committed
[UART] Clean up comments
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 05fb916 commit 465c3db

File tree

2 files changed

+55
-64
lines changed

2 files changed

+55
-64
lines changed

cores/arduino/stm32/uart.c

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
22
******************************************************************************
33
* @file uart.c
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
4+
* @author WI6LABS, fpistm
75
* @brief provide the UART interface
86
*
97
******************************************************************************
@@ -35,17 +33,6 @@
3533
*
3634
******************************************************************************
3735
*/
38-
/** @addtogroup CMSIS
39-
* @{
40-
*/
41-
42-
/** @addtogroup stm32f4xx_system
43-
* @{
44-
*/
45-
46-
/** @addtogroup STM32F4xx_System_Private_Includes
47-
* @{
48-
*/
4936
#include "uart.h"
5037
#include "Arduino.h"
5138
#include "PinAF_STM32F1.h"
@@ -55,14 +42,13 @@
5542
#endif
5643
#if defined(HAL_UART_MODULE_ENABLED)
5744

58-
// if DEBUG_UART is not defined assume this is the one
59-
// linked to PIN_SERIAL_TX
45+
/* If DEBUG_UART is not defined assume this is the one linked to PIN_SERIAL_TX */
6046
#if !defined(DEBUG_UART)
6147
#if defined(PIN_SERIAL_TX)
6248
#define DEBUG_UART pinmap_peripheral(digitalPinToPinName(PIN_SERIAL_TX), PinMap_UART_TX)
6349
#define DEBUG_PINNAME_TX digitalPinToPinName(PIN_SERIAL_TX)
6450
#else
65-
// No debug UART defined
51+
/* No debug UART defined */
6652
#define DEBUG_UART NP
6753
#define DEBUG_PINNAME_TX NC
6854
#endif
@@ -71,7 +57,7 @@
7157
#define DEBUG_UART_BAUDRATE 9600
7258
#endif
7359

74-
// @brief uart caracteristics
60+
/* @brief uart caracteristics */
7561
#if defined(STM32F4xx)
7662
#define UART_NUM (10)
7763
#elif defined(STM32F0xx) || defined(STM32F7xx)
@@ -109,25 +95,28 @@ void uart_init(serial_t *obj)
10995
GPIO_TypeDef *port;
11096
uint32_t function = (uint32_t)NC;
11197

112-
// Determine the UART to use (UART_1, UART_2, ...)
98+
/* Determine the U(S)ART peripheral to use (USART1, USART2, ...) */
11399
USART_TypeDef *uart_tx = pinmap_peripheral(obj->pin_tx, PinMap_UART_TX);
114100
USART_TypeDef *uart_rx = pinmap_peripheral(obj->pin_rx, PinMap_UART_RX);
115101

116-
//Pins Rx/Tx must not be NP
102+
/* Pins Rx/Tx must not be NP */
117103
if(uart_rx == NP || uart_tx == NP) {
118104
printf("ERROR: at least one UART pin has no peripheral\n");
119105
return;
120106
}
121107

122-
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
108+
/*
109+
* Get the peripheral name (USART1, USART2, ...) from the pin
110+
* and assign it to the object
111+
*/
123112
obj->uart = pinmap_merge_peripheral(uart_tx, uart_rx);
124113

125114
if(obj->uart == NP) {
126-
printf("ERROR: UART pins mismatch\n");
115+
printf("ERROR: U(S)ART pins mismatch\n");
127116
return;
128117
}
129118

130-
// Enable USART clock
119+
/* Enable USART clock */
131120
#if defined(USART1_BASE)
132121
else if(obj->uart == USART1) {
133122
__HAL_RCC_USART1_FORCE_RESET();
@@ -264,8 +253,8 @@ void uart_init(serial_t *obj)
264253
}
265254
#endif
266255

267-
//Configure GPIOs
268-
//RX
256+
/* Configure GPIOs */
257+
/* RX */
269258
port = set_GPIO_Port_Clock(STM_PORT(obj->pin_rx));
270259
function = pinmap_function(obj->pin_rx, PinMap_UART_RX);
271260
GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_rx);
@@ -284,7 +273,7 @@ void uart_init(serial_t *obj)
284273
#endif
285274
HAL_GPIO_Init(port, &GPIO_InitStruct);
286275

287-
//TX
276+
/* TX */
288277
port = set_GPIO_Port_Clock(STM_PORT(obj->pin_tx));
289278
function = pinmap_function(obj->pin_tx, PinMap_UART_TX);
290279
GPIO_InitStruct.Pin = STM_GPIO_PIN(obj->pin_tx);
@@ -293,7 +282,7 @@ void uart_init(serial_t *obj)
293282
HAL_GPIO_Init(port, &GPIO_InitStruct);
294283

295284

296-
//Configure uart
285+
/* Configure uart */
297286
uart_handlers[obj->index] = huart;
298287
huart->Instance = (USART_TypeDef *)(obj->uart);
299288
huart->Init.BaudRate = obj->baudrate;
@@ -312,7 +301,11 @@ void uart_init(serial_t *obj)
312301
#endif
313302

314303
#if defined(LPUART1_BASE)
315-
/* Note that LPUART clock source must be in the range [3 x baud rate, 4096 x baud rate], check Ref Manual */
304+
/*
305+
* Note that LPUART clock source must be in the range
306+
* [3 x baud rate, 4096 x baud rate]
307+
* check Reference Manual
308+
*/
316309
if(obj->uart == LPUART1) {
317310
if (obj->baudrate <= 9600) {
318311
HAL_UARTEx_EnableClockStopMode(huart);
@@ -362,7 +355,7 @@ void uart_init(serial_t *obj)
362355
*/
363356
void uart_deinit(serial_t *obj)
364357
{
365-
// Reset UART and disable clock
358+
/* Reset UART and disable clock */
366359
switch (obj->index) {
367360
#if defined(USART1_BASE)
368361
case 0:
@@ -659,11 +652,11 @@ int uart_getc(serial_t *obj, unsigned char* c)
659652
}
660653

661654
if (serial_rx_active(obj)) {
662-
return -1; // transaction ongoing
655+
return -1; /* Transaction ongoing */
663656
}
664657

665658
*c = (unsigned char)(obj->recv);
666-
// Restart RX irq
659+
/* Restart RX irq */
667660
UART_HandleTypeDef *huart = uart_handlers[obj->index];
668661
HAL_UART_Receive_IT(huart, &(obj->recv), 1);
669662

@@ -683,7 +676,7 @@ void uart_attach_rx_callback(serial_t *obj, void (*callback)(serial_t*))
683676
return;
684677
}
685678

686-
// Exit if a reception is already on-going
679+
/* Exit if a reception is already on-going */
687680
if (serial_rx_active(obj)) {
688681
return;
689682
}
@@ -715,11 +708,11 @@ void uart_attach_tx_callback(serial_t *obj, int (*callback)(serial_t*))
715708
tx_callback[obj->index] = callback;
716709
tx_callback_obj[obj->index] = obj;
717710

718-
// Enable interrupt
711+
/* Enable interrupt */
719712
HAL_NVIC_SetPriority(obj->irq, 0, 2);
720713
HAL_NVIC_EnableIRQ(obj->irq);
721714

722-
// the following function will enable UART_IT_TXE and error interrupts
715+
/* The following function will enable UART_IT_TXE and error interrupts */
723716
if (HAL_UART_Transmit_IT(uart_handlers[obj->index], &obj->tx_buff[obj->tx_tail], 1) != HAL_OK) {
724717
return;
725718
}
@@ -788,23 +781,23 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
788781
volatile uint32_t tmpval;
789782
#if defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32L1xx)
790783
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
791-
tmpval = huart->Instance->DR; // Clear PE flag
784+
tmpval = huart->Instance->DR; /* Clear PE flag */
792785
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
793-
tmpval = huart->Instance->DR; // Clear FE flag
786+
tmpval = huart->Instance->DR; /* Clear FE flag */
794787
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
795-
tmpval = huart->Instance->DR; // Clear NE flag
788+
tmpval = huart->Instance->DR; /* Clear NE flag */
796789
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
797-
tmpval = huart->Instance->DR; // Clear ORE flag
790+
tmpval = huart->Instance->DR; /* Clear ORE flag */
798791
}
799792
#else
800793
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_PE) != RESET) {
801-
tmpval = huart->Instance->RDR; // Clear PE flag
794+
tmpval = huart->Instance->RDR; /* Clear PE flag */
802795
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET) {
803-
tmpval = huart->Instance->RDR; // Clear FE flag
796+
tmpval = huart->Instance->RDR; /* Clear FE flag */
804797
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_NE) != RESET) {
805-
tmpval = huart->Instance->RDR; // Clear NE flag
798+
tmpval = huart->Instance->RDR; /* Clear NE flag */
806799
} else if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET) {
807-
tmpval = huart->Instance->RDR; // Clear ORE flag
800+
tmpval = huart->Instance->RDR; /* Clear ORE flag */
808801
}
809802
#endif
810803

@@ -876,7 +869,7 @@ void USART3_IRQHandler(void)
876869
HAL_UART_IRQHandler(uart_handlers[2]);
877870
}
878871
#if defined(STM32F0xx)
879-
// USART3_4_IRQn
872+
/* USART3_4_IRQn */
880873
if(uart_handlers[3] != NULL) {
881874
HAL_UART_IRQHandler(uart_handlers[3]);
882875
}
@@ -887,9 +880,9 @@ void USART3_IRQHandler(void)
887880
if(uart_handlers[5] != NULL) {
888881
HAL_UART_IRQHandler(uart_handlers[5]);
889882
}
890-
#endif // STM32F030xC
891-
#endif // STM32F0xx
892-
#endif // STM32F091xC || STM32F098xx
883+
#endif /* STM32F030xC */
884+
#endif /* STM32F0xx */
885+
#endif /* STM32F091xC || STM32F098xx */
893886
}
894887
#endif
895888

cores/arduino/stm32/uart.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
22
******************************************************************************
33
* @file uart.h
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
4+
* @author WI6LABS, fpistm
75
* @brief Header for uart module
86
******************************************************************************
97
* @attention
@@ -122,8 +120,8 @@
122120
#if !defined(Serial)
123121
#warning "No generic 'Serial' defined!"
124122
#endif
125-
#endif // SERIAL_UART_INSTANCE == x
126-
#endif // !HWSERIAL_NONE && SERIAL_UART_INSTANCE
123+
#endif /* SERIAL_UART_INSTANCE == x */
124+
#endif /* !HWSERIAL_NONE && SERIAL_UART_INSTANCE */
127125

128126
#if defined(ENABLE_HWSERIALLP1)
129127
#if defined(LPUART1_BASE)
@@ -219,60 +217,60 @@ struct serial_s {
219217
#define USART3_IRQn USART3_4_IRQn
220218
#define USART3_IRQHandler USART3_4_IRQHandler
221219

222-
#endif // STM32F091xC || STM32F098xx
223-
#endif // STM32F0xx
220+
#endif /* STM32F091xC || STM32F098xx */
221+
#endif /* STM32F0xx */
224222
#endif
225223

226224
#if defined(USART4_BASE) && !defined(USART4_IRQn)
227225
#if defined(STM32F0xx)
228-
// IRQHandler is mapped on USART3_IRQHandler for STM32F0xx
226+
/* IRQHandler is mapped on USART3_IRQHandler for STM32F0xx */
229227
#if defined(STM32F091xC) || defined (STM32F098xx)
230228
#define USART4_IRQn USART3_8_IRQn
231229
#elif defined(STM32F030xC)
232230
#define USART4_IRQn USART3_6_IRQn
233231
#else
234232
#define USART4_IRQn USART3_4_IRQn
235-
#endif // STM32F091xC || STM32F098xx
233+
#endif /* STM32F091xC || STM32F098xx */
236234
#elif defined(STM32L0xx)
237235
#define USART4_IRQn USART4_5_IRQn
238-
#endif // STM32F0xx
236+
#endif /* STM32F0xx */
239237
#endif
240238

241239
#if defined(USART5_BASE) && !defined(USART5_IRQn)
242240
#if defined(STM32F0xx)
243-
// IRQHandler is mapped on USART3_IRQHandler for STM32F0xx
241+
/* IRQHandler is mapped on USART3_IRQHandler for STM32F0xx */
244242
#if defined(STM32F091xC) || defined (STM32F098xx)
245243
#define USART5_IRQn USART3_8_IRQn
246244
#elif defined(STM32F030xC)
247245
#define USART5_IRQn USART3_6_IRQn
248-
#endif // STM32F091xC || STM32F098xx
246+
#endif /* STM32F091xC || STM32F098xx */
249247
#elif defined(STM32L0xx)
250248
#define USART5_IRQn USART4_5_IRQn
251-
#endif // STM32F0xx
249+
#endif /* STM32F0xx */
252250
#endif
253251

254252
#if defined (STM32F0xx)
255-
// IRQHandler is mapped on USART3_IRQHandler for STM32F0xx
253+
/* IRQHandler is mapped on USART3_IRQHandler for STM32F0xx */
256254
#if defined(USART6_BASE) && !defined(USART6_IRQn)
257255
#if defined(STM32F091xC) || defined (STM32F098xx)
258256
#define USART6_IRQn USART3_8_IRQn
259257
#elif defined(STM32F030xC)
260258
#define USART6_IRQn USART3_6_IRQn
261-
#endif // STM32F091xC || STM32F098xx
259+
#endif /* STM32F091xC || STM32F098xx */
262260
#endif
263261

264262
#if defined(USART7_BASE) && !defined(USART7_IRQn)
265263
#if defined(STM32F091xC) || defined (STM32F098xx)
266264
#define USART7_IRQn USART3_8_IRQn
267-
#endif // STM32F091xC || STM32F098xx
265+
#endif /* STM32F091xC || STM32F098xx */
268266
#endif
269267

270268
#if defined(USART8_BASE) && !defined(USART8_IRQn)
271269
#if defined(STM32F091xC) || defined (STM32F098xx)
272270
#define USART8_IRQn USART3_8_IRQn
273-
#endif // STM32F091xC || STM32F098xx
271+
#endif /* STM32F091xC || STM32F098xx */
274272
#endif
275-
#endif // STM32F0xx
273+
#endif /* STM32F0xx */
276274

277275
/* Exported macro ------------------------------------------------------------*/
278276
/* Exported functions ------------------------------------------------------- */

0 commit comments

Comments
 (0)