Page 1 of 1

Inverter firmware and putchar

Posted: Thu May 18, 2023 5:00 pm
by Pete9008
A question on the inverter firmware. I'm just trying to get the binary logging working on my F405 port but have been having problems in that the last few bytes of a string sent to the UART using printf() are missing. Having debugged this what I found was that printf calls putchar() which then fills a ping pong buffer and then calls SendCurrentBuffer() to transmit whenever one of the buffers is full. This then triggers a DMA to actually transmit the data.

The problem I have is that Putchar() only triggers the DMA when the outgoing DMA buffer is full. The last bit of the string is correctly written to the ping pong output buffer but because it never fills the last few bytes are never sent.

I've fixed it by adding a FlushOutput() function which forces the buffer to be sent but I can't help but think that this effect should cause problems elsewhere but can't see why it hasn't been??

What am I missing? :?

Edit - I'm being dim again, it's because my string doesn't end with a '\n' (newline) - flush removed and newline added!

Re: Inverter firmware and putchar

Posted: Fri May 19, 2023 7:51 am
by johu
Thou shall use Terminal::SendBinary() for sending binary data

PutChar is intended for \n delimited lines, whenever an \n occurs the buffer is sent - or when it's full.

EDIT: maybe this hasn't made it into the F4 branch, just copy it over from the F1 branch

Re: Inverter firmware and putchar

Posted: Fri May 19, 2023 7:55 am
by Pete9008
I am (well a modified version of it to make better use of the DMA buffer).

It was the json headers causing the problem (ascii).

Edit - still need to add an extra buffer layer though as it occasionally loses a message when the 10ms interrupt runs.