Skip to content

Commit d30610c

Browse files
author
Kei
committed
Test code for USART(None-DMA), USB(Increase QUEUE size, etc...)
1 parent ced5125 commit d30610c

File tree

9 files changed

+265
-9
lines changed

9 files changed

+265
-9
lines changed

cores/arduino/HardwareSerial.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ void serialEventLP1() __attribute__((weak));
105105
#endif
106106
#endif // HAVE_HWSERIALx
107107

108+
#if defined(ARDUINO_CommXEL)
109+
// const uint8_t UART_CH_MAX = 4;
110+
// uint8_t buffer_idx = 0;
111+
// uint8_t _rx_buffer[UART_CH_MAX][SERIAL_RX_BUFFER_SIZE] __attribute__((section(".NoneCacheableMem")));
112+
#endif
113+
108114
// Constructors ////////////////////////////////////////////////////////////////
109115
HardwareSerial::HardwareSerial(uint32_t _rx, uint32_t _tx)
110116
{
@@ -271,7 +277,14 @@ void HardwareSerial::init(PinName _rx, PinName _tx)
271277
_serial.pin_rx = _rx;
272278
}
273279
_serial.pin_tx = _tx;
280+
#if defined(ARDUINO_CommXEL)
281+
// if(buffer_idx < UART_CH_MAX){
282+
// _serial.rx_buff = _rx_buffer[buffer_idx++];
283+
// }
284+
_serial.rx_buff = _rx_buffer;
285+
#else
274286
_serial.rx_buff = _rx_buffer;
287+
#endif
275288
_serial.rx_head = 0;
276289
_serial.rx_tail = 0;
277290
_serial.tx_buff = _tx_buffer;
@@ -390,7 +403,7 @@ void HardwareSerial::begin(unsigned long baud, byte config)
390403
uart_init(&_serial, (uint32_t)baud, databits, parity, stopbits);
391404
enableHalfDuplexRx();
392405
#if defined(ARDUINO_SensorXEL) || defined(ARDUINO_SensorXEL_revE)\
393-
|| defined(ARDUINO_PowerXEL) || defined(ARDUINO_CommXEL)
406+
|| defined(ARDUINO_PowerXEL) //|| defined(ARDUINO_CommXEL)
394407

395408
#else
396409
uart_attach_rx_callback(&_serial, _rx_complete_irq);
@@ -411,7 +424,7 @@ void HardwareSerial::end()
411424
int HardwareSerial::available(void)
412425
{
413426
#if defined(ARDUINO_SensorXEL) || defined(ARDUINO_SensorXEL_revE)\
414-
|| defined(ARDUINO_PowerXEL) || defined(ARDUINO_CommXEL)
427+
|| defined(ARDUINO_PowerXEL) //|| defined(ARDUINO_CommXEL)
415428
#if defined(ARDUINO_CommXEL)
416429
uint16_t cndtr = _serial.handle.hdmarx->Instance->NDTR;
417430
#else

cores/arduino/HardwareSerial.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ class HardwareSerial : public Stream {
9595
// Don't put any members after these buffers, since only the first
9696
// 32 bytes of this struct can be accessed quickly using the ldd
9797
// instruction.
98+
// #if !defined(ARDUINO_CommXEL)
9899
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
100+
// #endif
99101
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
100102

103+
101104
serial_t _serial;
102105

103106
public:

cores/arduino/USBSerial.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ void USBSerial::flush(void)
157157

158158
uint32_t USBSerial::baud()
159159
{
160+
#if defined(ARDUINO_CommXEL)
161+
return CDC_get_baudrate();
162+
#else
160163
return 115200;
164+
#endif
161165
}
162166

163167
uint8_t USBSerial::stopbits()

cores/arduino/stm32/usb/cdc/cdc_queue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ extern "C" {
5353
#else
5454
#define CDC_QUEUE_MAX_PACKET_SIZE USB_FS_MAX_PACKET_SIZE
5555
#endif
56-
#define CDC_TRANSMIT_QUEUE_BUFFER_SIZE ((uint16_t)(CDC_QUEUE_MAX_PACKET_SIZE * 2))
57-
#define CDC_RECEIVE_QUEUE_BUFFER_SIZE ((uint16_t)(CDC_QUEUE_MAX_PACKET_SIZE * 3))
56+
#define CDC_TRANSMIT_QUEUE_BUFFER_SIZE ((uint16_t)(CDC_QUEUE_MAX_PACKET_SIZE * 2*10))
57+
#define CDC_RECEIVE_QUEUE_BUFFER_SIZE ((uint16_t)(CDC_QUEUE_MAX_PACKET_SIZE * 3*10))
5858

5959
typedef struct {
6060
uint8_t buffer[CDC_TRANSMIT_QUEUE_BUFFER_SIZE];

cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
199199
break;
200200

201201
case CDC_SET_CONTROL_LINE_STATE:
202-
lineState =
203-
(((USBD_SetupReqTypedef *)pbuf)->wValue & 0x01) != 0; // Check DTR state
202+
lineState = 1;
203+
// (((USBD_SetupReqTypedef *)pbuf)->wValue & 0x01) != 0; // Check DTR state
204204
if (lineState) { // Reset the transmit timeout when the port is connected
205205
transmitStart = 0;
206206
}
@@ -376,6 +376,68 @@ bool CDC_resume_receive(void)
376376
return false;
377377
}
378378

379+
#if defined(ARDUINO_CommXEL)
380+
uint32_t CDC_get_baudrate()
381+
{
382+
return linecoding.bitrate;
383+
}
384+
385+
386+
void CDC_Itf_TxISR(void *arg)
387+
{
388+
// uint32_t buffsize;
389+
// USBD_CDC_HandleTypeDef *hcdc = USBD_Device.pClassData;
390+
391+
392+
// if(hcdc == NULL)
393+
// {
394+
// return;
395+
// }
396+
// if(hcdc->TxState != 0)
397+
// {
398+
// return;
399+
// }
400+
401+
// buffsize = CDC_Itf_TxBufLengh();
402+
403+
// if (buffsize == 0)
404+
// {
405+
// return;
406+
// }
407+
408+
// if (buffsize%CDC_DATA_FS_MAX_PACKET_SIZE == 0)
409+
// {
410+
// buffsize -= 1;
411+
// }
412+
413+
// for (int i=0; i<buffsize; i++)
414+
// {
415+
// UserTxBufferForUSB[i] = CDC_Itf_TxRead();
416+
// }
417+
418+
// USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBufferForUSB, buffsize);
419+
// USBD_CDC_TransmitPacket(&USBD_Device);
420+
}
421+
422+
void CDC_Itf_SofISR(void)
423+
{
424+
// uint32_t rx_buf_length;
425+
426+
// rx_buf_length = APP_RX_DATA_SIZE - CDC_Itf_RxAvailable() - 1;
427+
428+
// if (usb_rx_full == true)
429+
// {
430+
// if (rx_buf_length > CDC_DATA_FS_MAX_PACKET_SIZE)
431+
// {
432+
// USBD_CDC_ReceivePacket(&USBD_Device);
433+
// usb_rx_full = false;
434+
// }
435+
// }
436+
// CDC_Itf_TxISR(NULL);
437+
}
438+
439+
#endif
440+
379441
#endif /* USBD_USE_CDC */
380442
#endif /* USBCON */
381443
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

cores/arduino/stm32/usb/cdc/usbd_cdc_if.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bool CDC_resume_receive(void);
5151
void CDC_init(void);
5252
void CDC_deInit(void);
5353
bool CDC_connected(void);
54+
uint32_t CDC_get_baudrate(void);
5455

5556
#ifdef __cplusplus
5657
}

cores/arduino/stm32/usb/usbd_conf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,15 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
261261
* @param hpcd: PCD handle
262262
* @retval None
263263
*/
264+
#if defined(ARDUINO_CommXEL)
265+
extern void CDC_Itf_SofISR(void);
266+
#endif
264267
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
265268
{
266269
USBD_LL_SOF(hpcd->pData);
270+
#if defined(ARDUINO_CommXEL)
271+
CDC_Itf_SofISR();
272+
#endif
267273
}
268274

269275
/**

libraries/SrcWrapper/src/stm32/uart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
379379
return;
380380
}
381381
#if defined(ARDUINO_SensorXEL) || defined(ARDUINO_SensorXEL_revE)\
382-
|| defined(ARDUINO_PowerXEL) || defined(ARDUINO_CommXEL)
382+
|| defined(ARDUINO_PowerXEL) //|| defined(ARDUINO_CommXEL)
383383
HAL_UART_Receive_DMA(huart, obj->rx_buff, SERIAL_RX_BUFFER_SIZE);
384384
#endif
385385
}
@@ -862,7 +862,7 @@ void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
862862
serial_t *obj = get_serial_obj(huart);
863863
if (obj && !serial_rx_active(obj)) {
864864
#if defined(ARDUINO_SensorXEL) || defined(ARDUINO_SensorXEL_revE)\
865-
|| defined(ARDUINO_PowerXEL) || defined(ARDUINO_CommXEL)
865+
|| defined(ARDUINO_PowerXEL) //|| defined(ARDUINO_CommXEL)
866866
if(huart->Instance == USART1 || huart->Instance == USART2){
867867
#if defined(ARDUINO_CommXEL)
868868
obj->rx_head = SERIAL_RX_BUFFER_SIZE - obj->handle.hdmarx->Instance->NDTR;
@@ -1089,7 +1089,7 @@ void UART10_IRQHandler(void)
10891089
void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart)
10901090
{
10911091
#if defined(ARDUINO_SensorXEL) || defined(ARDUINO_SensorXEL_revE)\
1092-
|| defined(ARDUINO_PowerXEL) || defined(ARDUINO_CommXEL)
1092+
|| defined(ARDUINO_PowerXEL) //|| defined(ARDUINO_CommXEL)
10931093
(void)huart;
10941094
#else
10951095
serial_t *obj = get_serial_obj(huart);

variants/XELNetwork_CommXEL/variant.cpp

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,173 @@ void SystemClock_Config(void)
135135
}
136136
}
137137

138+
139+
#if 0
140+
DMA_HandleTypeDef huart1dmatx, huart1dmarx;
141+
DMA_HandleTypeDef huart2dmatx, huart2dmarx;
142+
143+
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
144+
{
145+
if (huart->Instance == USART1)
146+
{
147+
__HAL_RCC_USART1_CLK_ENABLE();
148+
/* Enable DMA clock */
149+
__HAL_RCC_DMA2_CLK_ENABLE();
150+
151+
// /* Configure the DMA handler for Transmission process */
152+
// huart1dmatx.Instance = DMA2_Stream7;
153+
// huart1dmatx.Init.Channel = DMA_CHANNEL_4;
154+
// huart1dmatx.Init.Direction = DMA_MEMORY_TO_PERIPH;
155+
// huart1dmatx.Init.PeriphInc = DMA_PINC_DISABLE;
156+
// huart1dmatx.Init.MemInc = DMA_MINC_ENABLE;
157+
// huart1dmatx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
158+
// huart1dmatx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
159+
// huart1dmatx.Init.Mode = DMA_NORMAL;
160+
// huart1dmatx.Init.Priority = DMA_PRIORITY_LOW;
161+
// huart1dmatx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
162+
// huart1dmatx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
163+
// huart1dmatx.Init.MemBurst = DMA_MBURST_INC4;
164+
// huart1dmatx.Init.PeriphBurst = DMA_PBURST_INC4;
165+
166+
// HAL_DMA_Init(&huart1dmatx);
167+
168+
// /* Associate the initialized DMA handle to the the UART handle */
169+
// __HAL_LINKDMA(huart, hdmatx, (huart1dmatx));
170+
171+
/* Configure the DMA handler for reception process */
172+
huart1dmarx.Instance = DMA2_Stream5;
173+
huart1dmarx.Init.Channel = DMA_CHANNEL_4;
174+
huart1dmarx.Init.Direction = DMA_PERIPH_TO_MEMORY;
175+
huart1dmarx.Init.PeriphInc = DMA_PINC_DISABLE;
176+
huart1dmarx.Init.MemInc = DMA_MINC_ENABLE;
177+
huart1dmarx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
178+
huart1dmarx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
179+
huart1dmarx.Init.Mode = DMA_CIRCULAR;
180+
huart1dmarx.Init.Priority = DMA_PRIORITY_HIGH;
181+
huart1dmarx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
182+
huart1dmarx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
183+
huart1dmarx.Init.MemBurst = DMA_MBURST_INC4;
184+
huart1dmarx.Init.PeriphBurst = DMA_PBURST_INC4;
185+
186+
HAL_DMA_Init(&huart1dmarx);
187+
188+
/* Associate the initialized DMA handle to the the UART handle */
189+
__HAL_LINKDMA(huart, hdmarx, huart1dmarx);
190+
191+
/*##-4- Configure the NVIC for DMA #########################################*/
192+
// HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 0, 1);
193+
// HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn);
194+
195+
HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 1);
196+
HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
197+
198+
HAL_NVIC_SetPriority(USART1_IRQn, 10, 1);
199+
HAL_NVIC_EnableIRQ(USART1_IRQn);
200+
}
201+
202+
if (huart->Instance == USART2)
203+
{
204+
__HAL_RCC_USART2_CLK_ENABLE();
205+
/* Enable DMA clock */
206+
__HAL_RCC_DMA1_CLK_ENABLE();
207+
208+
// /* Configure the DMA handler for Transmission process */
209+
// huart2dmatx.Instance = DMA1_Stream6;
210+
// huart2dmatx.Init.Channel = DMA_CHANNEL_4;
211+
// huart2dmatx.Init.Direction = DMA_MEMORY_TO_PERIPH;
212+
// huart2dmatx.Init.PeriphInc = DMA_PINC_DISABLE;
213+
// huart2dmatx.Init.MemInc = DMA_MINC_ENABLE;
214+
// huart2dmatx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
215+
// huart2dmatx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
216+
// huart2dmatx.Init.Mode = DMA_NORMAL;
217+
// huart2dmatx.Init.Priority = DMA_PRIORITY_LOW;
218+
// huart2dmatx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
219+
// huart2dmatx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
220+
// huart2dmatx.Init.MemBurst = DMA_MBURST_INC4;
221+
// huart2dmatx.Init.PeriphBurst = DMA_PBURST_INC4;
222+
223+
// HAL_DMA_Init(&huart2dmatx);
224+
225+
// /* Associate the initialized DMA handle to the the UART handle */
226+
// __HAL_LINKDMA(huart, hdmatx, (huart2dmatx));
227+
228+
/* Configure the DMA handler for reception process */
229+
huart2dmarx.Instance = DMA1_Stream5;
230+
huart2dmarx.Init.Channel = DMA_CHANNEL_4;
231+
huart2dmarx.Init.Direction = DMA_PERIPH_TO_MEMORY;
232+
huart2dmarx.Init.PeriphInc = DMA_PINC_DISABLE;
233+
huart2dmarx.Init.MemInc = DMA_MINC_ENABLE;
234+
huart2dmarx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
235+
huart2dmarx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
236+
huart2dmarx.Init.Mode = DMA_CIRCULAR;
237+
huart2dmarx.Init.Priority = DMA_PRIORITY_HIGH;
238+
huart2dmatx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
239+
huart2dmatx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
240+
huart2dmatx.Init.MemBurst = DMA_MBURST_INC4;
241+
huart2dmatx.Init.PeriphBurst = DMA_PBURST_INC4;
242+
243+
HAL_DMA_Init(&huart2dmarx);
244+
245+
/* Associate the initialized DMA handle to the the UART handle */
246+
__HAL_LINKDMA(huart, hdmarx, huart2dmarx);
247+
248+
/*##-4- Configure the NVIC for DMA #########################################*/
249+
// HAL_NVIC_SetPriority(DMA1_Stream6_IRQn, 0, 1);
250+
// HAL_NVIC_EnableIRQ(DMA1_Stream6_IRQn);
251+
252+
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 1);
253+
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
254+
255+
HAL_NVIC_SetPriority(USART2_IRQn, 10, 1);
256+
HAL_NVIC_EnableIRQ(USART2_IRQn);
257+
}
258+
}
259+
260+
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
261+
{
262+
263+
if (huart->Instance == USART1)
264+
{
265+
__HAL_RCC_USART1_FORCE_RESET();
266+
__HAL_RCC_USART1_RELEASE_RESET();
267+
268+
HAL_NVIC_DisableIRQ(USART1_IRQn);
269+
HAL_NVIC_DisableIRQ(DMA2_Stream5_IRQn);
270+
HAL_NVIC_DisableIRQ(DMA2_Stream7_IRQn);
271+
}
272+
273+
if (huart->Instance == USART2)
274+
{
275+
__HAL_RCC_USART2_FORCE_RESET();
276+
__HAL_RCC_USART2_RELEASE_RESET();
277+
278+
HAL_NVIC_DisableIRQ(USART2_IRQn);
279+
HAL_NVIC_DisableIRQ(DMA1_Stream5_IRQn);
280+
HAL_NVIC_DisableIRQ(DMA1_Stream6_IRQn);
281+
}
282+
}
283+
284+
void DMA2_Channel7_IRQHandler(void)
285+
{
286+
HAL_DMA_IRQHandler(&huart1dmatx);
287+
}
288+
289+
void DMA2_Channel5_IRQHandler(void)
290+
{
291+
HAL_DMA_IRQHandler(&huart1dmarx);
292+
}
293+
294+
void DMA1_Channel6_IRQHandler(void)
295+
{
296+
HAL_DMA_IRQHandler(&huart2dmatx);
297+
}
298+
299+
void DMA1_Channel5_IRQHandler(void)
300+
{
301+
HAL_DMA_IRQHandler(&huart2dmarx);
302+
}
303+
#endif
304+
138305
#ifdef __cplusplus
139306
}
140307
#endif

0 commit comments

Comments
 (0)