• AVR Freaks

Helpful ReplyHot!Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console

Author
GrahamH
Junior Member
  • Total Posts : 102
  • Reward points : 0
  • Joined: 2010/04/23 20:37:12
  • Location: Austin, TX
  • Status: offline
2019/04/27 09:58:51 (permalink)
0

Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console

I am bringing up an application on Harmony 2.04, but I also tried Harmony 2.06 and it has the same problem.
PIC32MZ2048EFM100 processor, latest MPLABX IDE 2.15, MHC 2, XC-32, etc.
 
I am trying to use the system console and command Service built into Harmony with Serial IO on USART.
 
Both for printf debugging, and extensive use of command line.
 
It will only work with USART configured for (Static) Byte Model Support, Blocking.
Seems to work fine, except it is so slow and blocking, it is trashing the real time requirements of the core program.
 
I would like to transfer the Output into a buffer, so that the real time program does not block, and let either interrupts or polling from the main loop empty out the buffer. 
 
I assume that is what the "Buffer Queue Support" configuration option is for, and is supposed to do.
 
When I disable Byte Model Support and enable Buffer Queue Support, then rebuild the code, the program will not compile, giving errors of 
in "sys_console_static.c", undefined references to
    `DRV_USART0_ReceiverBufferIsEmpty'
    `DRV_USART0_ReadByte'
    `DRV_USART0_WriteByte'
 
So, how do I fix this?
Is there some header file missing? (That lets the buffer imitate the USART interface?)
The documentation does not tell me how to call into the buffer structure.
 
Thanks,
--- Graham
 
==
#1
Paul PortSol
Super Member
  • Total Posts : 430
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/04/29 06:10:20 (permalink)
0
My solution (PIC32MX and PIC32MZ) was to:
a) write my own ring buffer code (set buf size at compile time according to your needs, or have fun with alloc).
b) redirect printf to write to ring by writing a custom:  void _mon_putc(char cByte);
Using this allows redirecting printf to any UART or other device you choose.
c) Configure USART in MHC as: STATIC, Interrupt, Byte Model, Callback (non-blocking)
d) I find using receive callbacks much cleaner than messing with the interrupts, but if you are really tied for speed you can minimize the interrupt to directly write to the ring buf
e) For Tx I simply fill UART FIFO once each pass from my ring bufs (calling once each start of a() in Harmony's Tasking State Machine). I found this easier than messing with TX Interrupts and handling restarts when ran out of Tx data.
 
 
===========
void _mon_putc(char cByte)//STDOUT/STDERR via Ringbuffer or Direct output (allows XC32 format checking of normal printf)
{ // Ref: http://microchipdeveloper.com/xc32:redirect-stdout
if(sUart.bInitOK)//Check if UART RingBuffers Initialized
{
vUartTxByte(EuDiag, cByte);//All to EuDiag
if(sUart.eStdPrintf == ESTDERR)//STDERR also buffered to line
{
bRingBufA8_add(&s_STDERR, cByte);//Overflow sets flag for handling elsewhere (protected when sUart.eStdPrintf set)
}
}
else //Direct Output to port
{
while(DRV_USART_TransmitBufferIsFull(D_DG_InitHandle)){/*wait*/} //Wait Till Space (Blocking)
DRV_USART_WriteByte(D_DG_InitHandle, cByte); //Direct Output Data to EuDiag
}
}
===========
 
Paul
 
 
#2
Paul PortSol
Super Member
  • Total Posts : 430
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/04/29 06:11:29 (permalink)
0
See also: \\FS03\Pkgs\Microchip_MPLABX_XC32_Harmony\HarmonyNotes
 
#3
GrahamH
Junior Member
  • Total Posts : 102
  • Reward points : 0
  • Joined: 2010/04/23 20:37:12
  • Location: Austin, TX
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/04/29 07:33:27 (permalink)
0
Paul:
 
Thank you.
Good stuff.
Pretty much where I expected to end up.
Since I am using both printf debugging and the command/console service, I'll have to figure out how to get the command/cosole routed to the same output print buffer.
I think the compile error shows me where to attack that.
 
Thanks,
--- Graham
 
==
#4
Paul PortSol
Super Member
  • Total Posts : 430
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/04/29 11:24:03 (permalink)
0
Stuff under /apps/ is often written for older Harmony Versions. 
 
If you want to use the "Buffer Queue Support"
then I suggest starting a fresh project and using the options under MHC-Apps-"generate application code" to generate real code for your chosen PIC. I recommend not using BSP (disable it if example enables it).
 
See notes in attached for "generate application code" examples: MHC_CreatingProjectWithoutBSP_v00PR.txt
 
 
Paul
#5
GrahamH
Junior Member
  • Total Posts : 102
  • Reward points : 0
  • Joined: 2010/04/23 20:37:12
  • Location: Austin, TX
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/04/29 14:22:34 (permalink)
0
The documentation is not clear, but reading the code implies that Buffer Queue Support does not implement the simple circular buffer in front of the USART that I am looking for, but instead expects the application side to create and stuff a separate buffer for each message you want to transmit, then hand each buffer to the Buffer Queue Support functions which will then send the contents of the buffer. 
 
As usual, if there is a simple and a complicated way to do something, Harmony will do it the complicated way.
 
In this case, it is anticipating having multiple USARTs that use a common interface. The reference to "Buffer Queue Support" is that it can queue up multiple buffers, each potentially going somewhere different, not that it will queue up the information (individual characters) you send it in a buffer that it manages. 
 
All I want to do is get my command line / printf info out of the PIC32MZ without blocking the whole CPU.
 
--- Graham
 
==
#6
Paul PortSol
Super Member
  • Total Posts : 430
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/04/30 05:21:22 (permalink)
0
Possibly useful reference...
Attached my RingBuf and UART IO.
- RingBuf_Uart_20190430PR.zip
- It is loaded with extras for diagnostics and older code, feel free to strip it down
- If you strip it down to something cleaner please send back a copy.
- anything D_ is a macro, and D_printf_*** is just an easy to comment out printf for diagnostics.
 
Paul
 
 
#7
GrahamH
Junior Member
  • Total Posts : 102
  • Reward points : 0
  • Joined: 2010/04/23 20:37:12
  • Location: Austin, TX
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/05/01 17:11:11 (permalink)
0
Paul:
Thanks again.
--- Graham
 
==
#8
GrahamH
Junior Member
  • Total Posts : 102
  • Reward points : 0
  • Joined: 2010/04/23 20:37:12
  • Location: Austin, TX
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/05/02 19:50:37 (permalink) ☄ Helpfulby Paul PortSol 2019/05/03 03:48:28
5 (1)
Paul:
It turns out I took the USART/circular-buffer code from MCC for an eight bit PIC and modified it for the PIC32MZ using PLIB calls. Then spliced it in place of the Harmony MHC provided blocking USART handler. I still let Harmony initialize the USART and ISRs.
 
A command line print of timing analysis for my application, about 20 lines, 20 characters per line, (about 400 characters at 115200 baud) dropped from using 37000 us of CPU time to less than 300 us, while still using the standard printf() libraries.
 
I could speed it up more, by writing a simplified printf, but 300 us will work fine for me.
 
--- Graham
 
 
#9
Paul PortSol
Super Member
  • Total Posts : 430
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/05/03 03:48:15 (permalink)
0
Sounds good. Survive to fight another day
#10
krbvroc1
New Member
  • Total Posts : 29
  • Reward points : 0
  • Joined: 2016/05/10 16:18:59
  • Location: 0
  • Status: offline
Re: Harmony 2.04, 2.06, USART Buffer Queue incompatible with System Console 2019/05/13 06:08:14 (permalink)
0
GrahamH
When I disable Byte Model Support and enable Buffer Queue Support, then rebuild the code, the program will not compile, giving errors of 
in "sys_console_static.c", undefined references to
    `DRV_USART0_ReceiverBufferIsEmpty'
    `DRV_USART0_ReadByte'
    `DRV_USART0_WriteByte'
 
So, how do I fix this?

 
It have run into this confusion too...If you look in the harmony 'sys_console.hconfig' file that is used to generate the code based on the MHC settings, it only generates code for Buffer Queue Support if your USART are set to 'dynamic'. If set to 'static' it only generates the above code that doesn't compile.
#11
Jump to:
© 2019 APG vNext Commercial Version 4.5