1
1
/*
2
- * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2
+ * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
16
16
extern "C" {
17
17
#endif
18
18
19
- //TODO: [ESP32H21] IDF-11618
20
-
21
19
/** \defgroup uart_apis, uart configuration and communication related apis
22
20
* @brief uart apis
23
21
*/
@@ -26,34 +24,38 @@ extern "C" {
26
24
* @{
27
25
*/
28
26
27
+ /*It is found that when the buf is only 0x400, and the baud rate is set to 921600, the download is likely to fail */
28
+ #define RX_BUFF_SIZE 0x800
29
+ #define TX_BUFF_SIZE 100
30
+
29
31
//uart int enable register ctrl bits
30
- #define UART_RCV_INTEN BIT0
31
- #define UART_TRX_INTEN BIT1
32
- #define UART_LINE_STATUS_INTEN BIT2
32
+ #define UART_RCV_INTEN BIT0
33
+ #define UART_TRX_INTEN BIT1
34
+ #define UART_LINE_STATUS_INTEN BIT2
33
35
34
36
//uart int identification ctrl bits
35
- #define UART_INT_FLAG_MASK 0x0E
37
+ #define UART_INT_FLAG_MASK 0x0E
36
38
37
39
//uart fifo ctrl bits
38
- #define UART_CLR_RCV_FIFO BIT1
39
- #define UART_CLR_TRX_FIFO BIT2
40
- #define UART_RCVFIFO_TRG_LVL_BITS BIT6
40
+ #define UART_CLR_RCV_FIFO BIT1
41
+ #define UART_CLR_TRX_FIFO BIT2
42
+ #define UART_RCVFIFO_TRG_LVL_BITS BIT6
41
43
42
44
//uart line control bits
43
- #define UART_DIV_LATCH_ACCESS_BIT BIT7
45
+ #define UART_DIV_LATCH_ACCESS_BIT BIT7
44
46
45
47
//uart line status bits
46
- #define UART_RCV_DATA_RDY_FLAG BIT0
47
- #define UART_RCV_OVER_FLOW_FLAG BIT1
48
- #define UART_RCV_PARITY_ERR_FLAG BIT2
49
- #define UART_RCV_FRAME_ERR_FLAG BIT3
50
- #define UART_BRK_INT_FLAG BIT4
51
- #define UART_TRX_FIFO_EMPTY_FLAG BIT5
52
- #define UART_TRX_ALL_EMPTY_FLAG BIT6 // include fifo and shift reg
53
- #define UART_RCV_ERR_FLAG BIT7
48
+ #define UART_RCV_DATA_RDY_FLAG BIT0
49
+ #define UART_RCV_OVER_FLOW_FLAG BIT1
50
+ #define UART_RCV_PARITY_ERR_FLAG BIT2
51
+ #define UART_RCV_FRAME_ERR_FLAG BIT3
52
+ #define UART_BRK_INT_FLAG BIT4
53
+ #define UART_TRX_FIFO_EMPTY_FLAG BIT5
54
+ #define UART_TRX_ALL_EMPTY_FLAG BIT6 // include fifo and shift reg
55
+ #define UART_RCV_ERR_FLAG BIT7
54
56
55
57
//send and receive message frame head
56
- #define FRAME_FLAG 0x7E
58
+ #define FRAME_FLAG 0x7E
57
59
58
60
typedef enum {
59
61
UART_LINE_STATUS_INT_FLAG = 0x06 ,
@@ -86,7 +88,6 @@ typedef enum {
86
88
NONE_BITS = 0 ,
87
89
ODD_BITS = 2 ,
88
90
EVEN_BITS = 3
89
-
90
91
} UartParityMode ;
91
92
92
93
typedef enum {
@@ -139,7 +140,7 @@ typedef enum {
139
140
} RcvMsgState ;
140
141
141
142
typedef struct {
142
- UartBautRate baut_rate ;
143
+ UartBautRate baud_rate ;
143
144
UartBitsNum4Char data_bits ;
144
145
UartExistParity exist_parity ;
145
146
UartParityMode parity ; // chip size in byte
@@ -168,11 +169,9 @@ void uartAttach(void *rxBuffer);
168
169
*
169
170
* @param uint8_t uart_no : 0 for UART0, else for UART1.
170
171
*
171
- * @param uint32_t clock : clock used by uart module, to adjust baudrate.
172
- *
173
172
* @return None
174
173
*/
175
- void Uart_Init (uint8_t uart_no , uint32_t clock );
174
+ void Uart_Init (uint8_t uart_no );
176
175
177
176
/**
178
177
* @brief Modify uart baudrate.
@@ -186,6 +185,19 @@ void Uart_Init(uint8_t uart_no, uint32_t clock);
186
185
*/
187
186
void uart_div_modify (uint8_t uart_no , uint32_t DivLatchValue );
188
187
188
+ /**
189
+ * @brief Init uart0 or uart1 for UART download booting mode.
190
+ * Please do not call this function in SDK.
191
+ *
192
+ * @param uint8_t uart_no : 0 for UART0, 1 for UART1.
193
+ *
194
+ * @param uint8_t is_sync : 0, only one UART module, easy to detect, wait until detected;
195
+ * 1, two UART modules, hard to detect, detect and return.
196
+ *
197
+ * @return None
198
+ */
199
+ int uart_baudrate_detect (uint8_t uart_no , uint8_t is_sync );
200
+
189
201
/**
190
202
* @brief Switch printf channel of uart_tx_one_char.
191
203
* Please do not call this function when printf.
@@ -196,14 +208,24 @@ void uart_div_modify(uint8_t uart_no, uint32_t DivLatchValue);
196
208
*/
197
209
void uart_tx_switch (uint8_t uart_no );
198
210
211
+ /**
212
+ * @brief Switch message exchange channel for UART download booting.
213
+ * Please do not call this function in SDK.
214
+ *
215
+ * @param uint8_t uart_no : 0 for UART0, 1 for UART1.
216
+ *
217
+ * @return None
218
+ */
219
+ void uart_buff_switch (uint8_t uart_no );
220
+
199
221
/**
200
222
* @brief Output a char to printf channel, wait until fifo not full.
201
223
*
202
224
* @param None
203
225
*
204
226
* @return OK.
205
227
*/
206
- ETS_STATUS uart_tx_one_char (uint8_t TxChar );
228
+ ETS_STATUS uart_tx_one_char (uint8_t txchar );
207
229
208
230
/**
209
231
* @brief Output a char to message exchange channel, wait until fifo not full.
@@ -213,7 +235,17 @@ ETS_STATUS uart_tx_one_char(uint8_t TxChar);
213
235
*
214
236
* @return OK.
215
237
*/
216
- ETS_STATUS uart_tx_one_char2 (uint8_t TxChar );
238
+ ETS_STATUS uart_tx_one_char2 (uint8_t txchar );
239
+
240
+ /**
241
+ * @brief Output a char to usb-serial channel, wait until fifo not full.
242
+ * Please do not call this function in SDK.
243
+ *
244
+ * @param None
245
+ *
246
+ * @return OK.
247
+ */
248
+ ETS_STATUS uart_tx_one_char3 (uint8_t txchar );
217
249
218
250
/**
219
251
* @brief Wait until uart tx full empty.
@@ -288,7 +320,7 @@ void uart_rx_intr_handler(void *para);
288
320
* @return OK for successful.
289
321
* FAIL for failed.
290
322
*/
291
- ETS_STATUS uart_rx_readbuff ( RcvMsgBuff * pRxBuff , uint8_t * pRxByte );
323
+ ETS_STATUS uart_rx_readbuff (RcvMsgBuff * pRxBuff , uint8_t * pRxByte );
292
324
293
325
/**
294
326
* @brief Get all chars from receive buffer.
@@ -338,6 +370,60 @@ void send_packet(uint8_t *p, int len);
338
370
*/
339
371
int recv_packet (uint8_t * p , int len , uint8_t is_sync );
340
372
373
+ /**
374
+ * @brief Send an packet to download tool, with SLIP escaping.
375
+ * Please do not call this function in SDK.
376
+ *
377
+ * @param uint8_t *pData : the pointer to input string.
378
+ *
379
+ * @param uint16_t DataLen : the string length.
380
+ *
381
+ * @return OK for successful.
382
+ * FAIL for failed.
383
+ */
384
+ ETS_STATUS SendMsg (uint8_t * pData , uint16_t DataLen );
385
+
386
+ /**
387
+ * @brief Receive an packet from download tool, with SLIP escaping.
388
+ * Please do not call this function in SDK.
389
+ *
390
+ * @param uint8_t *pData : the pointer to input string.
391
+ *
392
+ * @param uint16_t MaxDataLen : If string length > MaxDataLen, the string will be truncated.
393
+ *
394
+ * @param uint8_t is_sync : 0, only one UART module;
395
+ * 1, two UART modules.
396
+ *
397
+ * @return OK for successful.
398
+ * FAIL for failed.
399
+ */
400
+ ETS_STATUS RcvMsg (uint8_t * pData , uint16_t MaxDataLen , uint8_t is_sync );
401
+
402
+ /**
403
+ * @brief Check if this UART is in download connection.
404
+ * Please do not call this function in SDK.
405
+ *
406
+ * @param uint8_t uart_no : 0 for UART0, 1 for UART1.
407
+ *
408
+ * @return ETS_NO_BOOT = 0 for no.
409
+ * SEL_UART_BOOT = BIT(1) for yes.
410
+ */
411
+ uint8_t UartConnCheck (uint8_t uart_no );
412
+
413
+ /**
414
+ * @brief Initialize the USB ACM UART
415
+ * Needs to be fed a buffer of at least 128 bytes, plus any rx buffer you may want to have.
416
+ *
417
+ * @param cdc_acm_work_mem Pointer to work mem for CDC-ACM code
418
+ * @param cdc_acm_work_mem_len Length of work mem
419
+ */
420
+ void Uart_Init_USB (void * cdc_acm_work_mem , int cdc_acm_work_mem_len );
421
+
422
+ /**
423
+ * @brief Install handler to reset the chip when a RTS change has been detected on the CDC-ACM 'UART'.
424
+ */
425
+ void usb_serial_otg_enable_reset_on_rts (void );
426
+
341
427
extern UartDevice UartDev ;
342
428
343
429
/**
0 commit comments