Serial monitor hangs as well as entire IDE soon after starting

Phono
Mon Sep 12, 2016 7:44 pm
Hi,
The Arduino 1.6.9 IDE is installed on windows 10.
I have inserted in a sketch a few serial.print statements to monitor the progress of the processing in the setup function.
here is an excerpt of the code :

#define SERIAL Serial

void setup() {

// pin mode and such….

#ifdef SERIAL
SERIAL.begin(115200);
delay(2000);
SERIAL.println(“Impression debug activee”) ;
#else
CANSetup() ;
#endif

Ethernet.begin(mac,ip);
#ifdef SERIAL
SERIAL.println(“Initialisation Client Ethernet”) ;
#endif

// Initialisation de l’I2C
MaitreI2C.begin() ;
#ifdef SERIAL
delay(100);
SERIAL.print(“Initialisation I2C “) ;
if ( MPU6050_Init() ) // Initialisation du gyroscope
SERIAL.println(“reussie”) ;
else
SERIAL.println(“echouee”) ;
#else
MPU6050_Init() ; // Initialisation du gyroscope
#endif

// etc.
}

When the sketch starts, only the first two prints show on the monitor window, then the IDE hangs. If I try to close the monitor window, it does not and the IDE does not respond any more, until I press the Reset button on the Olimexion STM32 board.

Any idea?

This does not occur if I use a physical serial port on the Olimexino board.


martinayotte
Mon Sep 12, 2016 8:05 pm
Do you mean that the first Serial prints before the I2C.begin() are working but not the one after ?
Your MaitreI2C is probably not working and hanging. Is it a nick name for the STM32 Wire library ?
Do you have PullUps on your I2C bus ?

Phono
Mon Sep 12, 2016 9:09 pm
Actually I am attempting to use the hardwire library, with :

#include <HardWire.h>

// ………

HardWire MaitreI2C ( 1, I2C_FAST_MODE ) ;

but so far with no success.

I understand what you suggest : the I2C initialisation would cause the system hang. To check for this, I have changed the code :

SERIAL.println(“Initialisation I2C “) ;
delay(1000);
MaitreI2C.begin() ;
if ( MPU6050_Init() ) // Initialisation du gyroscope
SERIAL.println(“reussie”) ;
else
SERIAL.println(“echouee”) ;

So whatever the result of the initialisation of the I2C, the first print would normally work. But it does not.


Phono
Mon Sep 12, 2016 9:14 pm
In addition, if I change the code above like this :

#ifdef SERIAL
SERIAL.begin(9600);
delay(2000);
SERIAL.println(“Impression debug activee”) ;
#else
CANSetup() ;
#endif

Ethernet.begin(mac,ip);
#ifdef SERIAL
SERIAL.print(“Initialisation Client Ethernet, “) ;
SERIAL.print(“Initialisation Client Ethernet 2, “) ;
SERIAL.println(“Initialisation Client Ethernet 3”) ;
#endif

only the first println and the first print show on the serial monitor, and it hangs after the comma :

Impression debug activee
Initialisation Client Ethernet,


martinayotte
Mon Sep 12, 2016 9:24 pm
I could barely believe it …
Several consecutive Serial.print() and it hangs after the second ?
I’ve never seen that …
Your installation is kind of weird !
Did you tried other serial communication software ?

RogerClark
Mon Sep 12, 2016 9:56 pm
I wonder if this is a biproduct of the nee Tx Buffering ?

martinayotte
Mon Sep 12, 2016 10:03 pm
It is a possibility,I didn’t merged it yet in my environment.

But according to the code above, it would hang with 58 characters …

@Phono, could you try to print a single very long print such as the following to see if hang at specific position ?

Serial.println("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789")


edogaldo
Tue Sep 13, 2016 6:45 am
Hi Phono, a couple of questions:

  • are you using Serial over USART1 (using a usb2serial stick) or SerialUSB (direct connection with the board’s usb)
  • which board are you using?

Phono
Tue Sep 13, 2016 6:51 am
Following your advice, I have changed the code as follows :

#ifdef SERIAL
SERIAL.begin(9600);
delay(2000);
Serial.println(“012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789”);
SERIAL.println(“Impression debug activee”) ;
#else
CANSetup() ;
#endif

Ethernet.begin(mac,ip);
#ifdef SERIAL
SERIAL.print(“Initialisation Client Ethernet, “) ;
SERIAL.print(“Initialisation Client Ethernet 2, “) ;
SERIAL.println(“Initialisation Client Ethernet 3”) ;
#endif

I get the following printout :
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
Impression debug activee
Initialisation Client Ethernet,

note : there is a space after the last comma.
It does the same thing if I change

SERIAL.print(“Initialisation Client Ethernet, “) ;

to a println.
I checked wether it was related to the serial monitor. For so, I launched Teraterm and configured it for the port the maple board is on (COM4). I get exactly the same printout as above.

So I suppose that the problem stands in the usb part of the STM32 core.


edogaldo
Tue Sep 13, 2016 7:12 am
Hi Phono, few questions:

  • which board are you using?
  • are you using Serial over USART1 (using a usb2serial stick) or SerialUSB (direct connection with the board’s usb)?
  • if you make a very simple sketch like:
    begin() {
    Serial.begin(9600);
    delay(2000);
    Serial.println("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
    Serial.println("Impression debug activee") ;
    Serial.print("Initialisation Client Ethernet, ") ;
    Serial.print("Initialisation Client Ethernet 2, ") ;
    Serial.println("Initialisation Client Ethernet 3") ;
    }

stevestrong
Tue Sep 13, 2016 8:50 am
I suspect the Ethernet lib. What kind of Ethernet controller is used? ENC28 or other type?

Phono
Tue Sep 13, 2016 9:02 pm
I am using a Olimex STM32 maple-like board.
I am connecting on Serial, that is, the built-in USB-serial channel.
I have added a W5200 shield from SEEED.
The suspicion on the Ethernet.begin() statement was right. If I move it elsewhere, the problem disappears.
I am currently testing the Ethernet library that I have modified to be FreeRTOS-aware. Unfortunately it worked pretty well some time ago, but now I am stuck with a regression I cannot find so far.
I will let you know when I succeed, for I will provide you with this library for possible inclusion in the STM32 package.
Thanks for your help, often asking the wrong questions bring the right answers.

Phono
Fri Sep 16, 2016 7:05 am
I have now solved the problem. However, I do not know what was wrong and why it is better now.
The problem came from two initialisations :
– the ethernet.begin()
– the TwoWire::begin().
In both cases, putting these statements in the Setup() function, before the tasks are created and the scheduler launched, lead to trouble.
I have put them at the beginning of two different tasks, before the while(true) statement, and no problem now.
As far as the ethernet library, this could make sense, since I modified it so that delay() is replaced by vTaskDelay() when used in a multitasking environment, though I carefully checked that begin() does not call delay().
For TwoWire::begin() I am at my wit’s end, since this function does very little :

void TwoWire::begin(uint8 self_addr) {
tx_buf_idx = 0;
tx_buf_overflow = false;
rx_buf_idx = 0;
rx_buf_len = 0;
pinMode(this->scl_pin, OUTPUT_OPEN_DRAIN);
pinMode(this->sda_pin, OUTPUT_OPEN_DRAIN);
set_scl(HIGH);
set_sda(HIGH);
}

Of course, the wire object had been correctly defined :
TwoWire MaitreI2C(I2C_SCL, I2C_SDA) ;
I tried to insert into the Setup() the last four statements directly, and no problem arose:

pinMode(I2C_SCL, OUTPUT_OPEN_DRAIN);
pinMode(I2C_SDA, OUTPUT_OPEN_DRAIN);
TwoWire.set_scl(HIGH);
TwoWire.set_sda(HIGH);

The effect of putting the MaitreI2C.begin() in the Setup() was that one of my two tasks that handle the ethernet shield would not communicate any more.
Specifically, one task connects to an external TCP server, and the other task is a Webserver. This was the Web server that would not respond to connection attempts from my browser, though the task that handles it still ran.

I am glad it works now, but still nervous as to what was the problem, and how to manage so that it does not show again later?


Leave a Reply

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