@@ -290,6 +290,7 @@ int SoftwareSerial::begin(uint32_t baudrate, uint32_t sconfig, bool inverted)
290
290
if (fsp_tim_config (&tx_descr.tim , config.baudrate , false ) != 0 ) {
291
291
return 0 ;
292
292
}
293
+
293
294
if (fsp_dma_config (&tx_descr.dma , SS_DMA_CHANNEL_TX,
294
295
fsp_tim_to_elc_event (tx_descr.tim .get_channel ()), tx_descr.dmabuf [0 ],
295
296
(void *) &tx_port->PCNTR3 , config.nsamples , dma_tx_callback, this ) != 0 ) {
@@ -301,6 +302,7 @@ int SoftwareSerial::begin(uint32_t baudrate, uint32_t sconfig, bool inverted)
301
302
if (fsp_tim_config (&rx_descr.tim , config.baudrate , true ) != 0 ) {
302
303
return 0 ;
303
304
}
305
+
304
306
if (fsp_dma_config (&rx_descr.dma , SS_DMA_CHANNEL_RX,
305
307
fsp_tim_to_elc_event (rx_descr.tim .get_channel ()), rx_descr.dmabuf [0 ],
306
308
(void *) &rx_port->PCNTR2 , config.nsamples , dma_rx_callback, this ) != 0 ) {
@@ -359,17 +361,20 @@ size_t __attribute__((optimize("O2"))) SoftwareSerial::write(uint8_t byte)
359
361
tx_descr.dmabuf [0 ][config.databits + 1 ] = parity;
360
362
}
361
363
362
- // Reconfigure DMA transfer.
363
- R_DMAC_Reconfigure (&tx_descr.dma .ctrl , tx_descr.dma .cfg .p_info );
364
+ // Restart DMA transfer.
365
+ R_DMAC_Reset (&tx_descr.dma .ctrl , tx_descr.dma .cfg .p_info ->p_src ,
366
+ tx_descr.dma .cfg .p_info ->p_dest , tx_descr.dma .cfg .p_info ->length );
364
367
365
368
// Start the DMA transfer.
366
369
tx_descr.tim .reset ();
367
370
tx_descr.tim .start ();
368
371
369
- // TODO check if transfer is running on next write .
372
+ // Wait for the DMA transfer to finish .
370
373
while (tx_descr.dma .ctrl .p_reg ->DMCNT ) {
371
- // Wait for DMA transfer to finish.
372
374
}
375
+
376
+ // Stop the trigger timer.
377
+ tx_descr.tim .stop ();
373
378
return 1 ;
374
379
}
375
380
@@ -382,9 +387,10 @@ void __attribute__((optimize("O2"))) SoftwareSerial::rx_process()
382
387
{
383
388
static uint32_t bufidx = 0 ;
384
389
385
- // Reconfigure DMA transfer.
390
+ // Restart DMA transfer.
386
391
rx_descr.dma .cfg .p_info ->p_dest = rx_descr.dmabuf [bufidx ^ 1 ];
387
- R_DMAC_Reconfigure (&rx_descr.dma .ctrl , rx_descr.dma .cfg .p_info );
392
+ R_DMAC_Reset (&rx_descr.dma .ctrl , rx_descr.dma .cfg .p_info ->p_src ,
393
+ rx_descr.dma .cfg .p_info ->p_dest , rx_descr.dma .cfg .p_info ->length );
388
394
389
395
// Process the current DMA buffer.
390
396
uint8_t data = 0 ;
@@ -434,9 +440,12 @@ void __attribute__((optimize("O2"))) SoftwareSerial::rx_process()
434
440
435
441
void dma_tx_callback (dmac_callback_args_t *args)
436
442
{
437
- // Disable the DMA trigger timer as soon as the transfer is complete.
438
- // Note the timer will be cleared and restarted on next write.
439
- ((SoftwareSerial *) args->p_context )->tx_descr .tim .stop ();
443
+ // Wait for a while cycle to keep the GPIO high enough for the last stop bit.
444
+ fsp_tim_t *tim = &(((SoftwareSerial *) args->p_context )->tx_descr .tim );
445
+ volatile R_GPT0_Type *regs = R_GPT0 + (tim->get_channel () * (R_GPT1 - R_GPT0));
446
+ regs->GTST_b .TCFPO = 0 ;
447
+ while (!regs->GTST_b .TCFPO ) {
448
+ }
440
449
}
441
450
442
451
void dma_rx_callback (dmac_callback_args_t *args)
0 commit comments