[SOLVED] HardwareSerial available() not reporting length of buffered data on Serial1

sajuukKahr
Wed Feb 15, 2017 11:06 pm
Hey guys,

I am trying to load a SPI memory module with some images. The process should be:

PC image convertor > Serial > STM32F1 raw write to SPI mem > SPI memory

the problem is that I am waiting for the buffer to get full or at least 256 so I can write the page.

Any ideas on the .available() ? It reports always 0

For now I will try another approach.


victor_pv
Thu Feb 16, 2017 12:08 am
sajuukKahr wrote:Hey guys,

I am trying to load a SPI memory module with some images. The process should be:

PC image convertor > Serial > STM32F1 raw write to SPI mem > SPI memory

the problem is that I am waiting for the buffer to get full or at least 256 so I can write the page.

Any ideas on the .available() ? It reports always 0

For now I will try another approach.


sajuukKahr
Thu Feb 16, 2017 12:45 am
Using USART
not sure how to answer the second question I got the STM32 Arduino from https://github.com/rogerclarkmelbourne/Arduino_STM32

I seems that these are the files used
hardware/Arduino_STM32/STM32F1/cores/maple/HardwareSerial.cpp
hardware/Arduino_STM32/STM32F1/cores/maple/libmaple/usart.c
hardware/Arduino_STM32/STM32F1/system/libmaple/include/libmaple/usart.h


victor_pv
Thu Feb 16, 2017 1:25 am
sajuukKahr wrote:Using USART
not sure how to answer the second question I got the STM32 Arduino from https://github.com/rogerclarkmelbourne/Arduino_STM32

I seems that these are the files used
hardware/Arduino_STM32/STM32F1/cores/maple/HardwareSerial.cpp
hardware/Arduino_STM32/STM32F1/cores/maple/libmaple/usart.c
hardware/Arduino_STM32/STM32F1/system/libmaple/include/libmaple/usart.h


sajuukKahr
Thu Feb 16, 2017 8:47 am
hey Victor, looked over the implementation also and it seems solid….
USB gets detected as Serial in the Arduino env.

Using a blue pill smt32F103C

I am using Serial1 which is PA9 PA10. The test is pretty simple:
setup
Serial1.begin(115200);

loop

while(1){
delay(200);
Serial1.println(Serial1.available());
}


stevestrong
Thu Feb 16, 2017 10:03 am
As far as I know the USART has a limited Rx buffer (64 bytes?), so you cannot receive more data than that at once.
Solution:
1. you read all available bytes from USART and copy them to your own (larger) buffer
or
2. change the Rx buffer size – yo have to look in the source files for that.

If always reports 0, then you have a reception problem. Check the wires.
Alternatively use serial USB, it should work with relative high throughput (around 600kbps for Rx).


sajuukKahr
Thu Feb 16, 2017 10:59 am
Hey, played around with the buffers but to no success…

The problem is that it is always displaying 0. Tried the same example on an Arduino uno and it works, I upload, then open the serial monitor and see a lot of 0s when I send something the value changes because we now have something in the buffer.

I have the STM32 connected via PA9, PA10 to a USB CP203x this is how I output data (program via USB output via Serial for debug).

The value on the STM32 never changes from 0. It should go up to 64 or the rx buffer size and stay there till read.


stevestrong
Thu Feb 16, 2017 12:26 pm
For testing, exchange Serial with Serial1: use Serial (USB) for data transfer and use Serial1 for debug output.
Of course, you have to send something to get no-zero number as received bytes count.

sajuukKahr
Thu Feb 16, 2017 12:37 pm
stevestrong wrote:For testing, exchange Serial with Serial1: user Serial (USB) for data transfer and use Serial1 for debug output.
Of course, you have to send something to get no-zero number as received bytes count.

stevestrong
Thu Feb 16, 2017 12:44 pm
sajuukKahr wrote:Serial1.println(Serial1.available());}

sajuukKahr
Thu Feb 16, 2017 12:47 pm
that example is pretty simple print the available data in the Serial1 waiting to be processed via read. does it matter I am outputting to Serial1? don’t think so…

Also like I said I am trying to use Serial1 for a raw flash of a spi memory via the mcu with the data coming from pc.


sajuukKahr
Thu Feb 16, 2017 12:47 pm
Not sure how to approach this.

1) one solution is get the spi connected to the Arduino uno and flash the chip via serial
2) the second is build a buffering mechanism to keep track of items as I can only write 256 bytes at a time so I need to buffer the rest
3) or split the “packets” of info into 256 and send one lump at the time….and wait for response back saying it was written

Will try with RX/TX2 and 3 for a quick available() check but it is the same class so there should not be any difference…


mrburnette
Thu Feb 16, 2017 12:47 pm
sajuukKahr wrote:
<…>
I hate the USB serial as the port gets closed when programming the board and I need to reopen the logging mechanism every time…

sajuukKahr
Thu Feb 16, 2017 12:49 pm
mrburnette wrote:sajuukKahr wrote:
<…>
I hate the USB serial as the port gets closed when programming the board and I need to reopen the logging mechanism every time…

mrburnette
Thu Feb 16, 2017 12:51 pm
sajuukKahr wrote:mrburnette wrote:sajuukKahr wrote:

And that is why I am not using it…I do not find any value in your joke/comment

stevestrong
Thu Feb 16, 2017 12:52 pm
Change the title of the thread to include “Serial1…”
Trying Serial2 is a good idea.

sajuukKahr
Thu Feb 16, 2017 12:55 pm
mrburnette wrote:sajuukKahr wrote:mrburnette wrote:

sajuukKahr
Thu Feb 16, 2017 12:56 pm
stevestrong wrote:Change the title of the thread to include “Serial1…”
Trying Serial2 is a good idea.

stevestrong
Thu Feb 16, 2017 1:02 pm
Serial is Serial USB on blue pill and is using different hardware and software than Serial1..2.

But if you have doubts about our advises you better find out the solution alone. I am out of this issue from now on.


sajuukKahr
Thu Feb 16, 2017 1:07 pm
stevestrong wrote:Serial is Serial USB on blue pill and is using different hardware and software than Serial1..2.

But if you have doubts about our advises you better find out the solution alone. I am out of this issue from now on.


mrburnette
Thu Feb 16, 2017 1:23 pm
On the ESP8266 core, I ran this sketch with the serial console configured to “No line ending”
void setup() {
Serial.begin(115200);
}

void loop() {
while (1) {
delay(200);
if ( Serial.available() ) {
Serial.println(Serial.read()) ;
}
}
}


sajuukKahr
Thu Feb 16, 2017 1:35 pm
if you really want to help upload this same sketch to a blue pill (if you have one)

sajuukKahr
Thu Feb 16, 2017 1:37 pm
depending on the length of the input serial buffer exactly this is what I want the value of bytes in the RX buffer !!!

it works for ESP, it works for Uno but not for STM32F1X….

I can do it myself in my sketch with some elbow grease …. but I thought it might be worth it to debug the actual cause and fix it in the repo :roll:


mrburnette
Thu Feb 16, 2017 1:46 pm
sajuukKahr wrote:depending on the length of the input serial buffer exactly this is what I want the value of bytes in the RX buffer !!!

it works for ESP, it works for Uno but not for STM32F1X….


sajuukKahr
Thu Feb 16, 2017 2:08 pm
I agree with you.

mrburnette wrote:
You are aware that the STM32duino core as inherited from Leaflabs has the USB code linked into the sketch code and uploaded into the “sketch” flash storage space?
Ray


mrburnette
Thu Feb 16, 2017 2:15 pm
Lookin’ around at home, I did find a STM32F103 BAITE Maple Mini clone with the 2.0 bootloader.

This sketch using USB DOES WORK THE SAME AS THE ESP8266 output above! SO, if USB serial is broken, it has happened since July 2016 which was the last time I updated the home /Arduino/hardware/STM32 core folder.

Ray

/*
ArduinoIDE 1.6.13 running on Linux Mint 17.3 with Maple Mini Clone Bootloader 2.0
STM32duino version: 19 July 2016
Sketch uses 13,124 bytes (10%) of program storage space. Maximum is 122,880 bytes.
Global variables use 2,560 bytes of dynamic memory.
*/

void setup() {
Serial.begin(115200);
}

void loop() {
while (1) {
delay(200);
Serial.println(Serial.available());
}
}


sajuukKahr
Thu Feb 16, 2017 2:17 pm
Would you please replace Serial with Serial1 and attach a USB-USART bridge on PA9, PA10 ? (at least I/we can confirm it is my hardware at fault or not)

mrburnette
Thu Feb 16, 2017 2:37 pm
sajuukKahr wrote:Would you please replace Serial with Serial1 and attach a USB-USART bridge on PA9, PA10 ? (at least I/we can confirm it is my hardware at fault or not)

mrburnette
Thu Feb 16, 2017 2:38 pm
sajuukKahr wrote:Would you please replace Serial with Serial1 and attach a USB-USART bridge on PA9, PA10 ? (at least I/we can confirm it is my hardware at fault or not)

victor_pv
Thu Feb 16, 2017 2:44 pm
sajuukKahr wrote:stevestrong wrote:Serial is Serial USB on blue pill and is using different hardware and software than Serial1..2.

But if you have doubts about our advises you better find out the solution alone. I am out of this issue from now on.


sajuukKahr
Thu Feb 16, 2017 2:59 pm
victor_pv wrote:
Other than that, I have said it many times in other threads, but get a debugger. An stlink clone cost 2 bucks and will save you lots of headaches.

mrburnette
Thu Feb 16, 2017 3:47 pm
… build this:

https://www.hackster.io/rayburne/the-qb … tor-ae7015

Ray


sajuukKahr
Sun Feb 19, 2017 9:10 pm
Hey guys, very sorry for the late reply I checked the repo I had and it was not tainted though a bit old. I check all other serial ports and the available had he same behaviour returning 0 all the time.

I just updated to the last commit and voila all worked as a charm. Lesson learned, update repo before posting stupid questions and wasting people’s time.

Thanks all of you for support.
@mrburnette
@stevestrong
@victor_pv

And a little treat, check the image attached.
it is a STM32, attached I have a 25q 64mbit flash and a ili9486. All raw data is uploaded to flash via a serial from a PHP script that parses gif files and writes a custom TOC 32bytesx128entries and then the actual data for the pictures. All images are stored in a gif like format, pallet-ed images (colors are stored in an array then in another array you only add the index of the pallet color to save space).

Currently I have the memory manager, which reads and writes to the flash, next is a UI manager that will keep track of images by layer so you can redraw only some parts of the screen and not the whole screen.


Leave a Reply

Your email address will not be published. Required fields are marked *