Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Grand Central M4, Serial2 tx hangs, bit rate dependent
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Grand Central M4, Serial2 tx hangs, bit rate dependent

by tomjennings on Sat Jul 04, 2020 5:38 pm

OK, another GC M4 problem! I'm nothing but trouble.

I need two hardware serial ports, in addition to the USB serial port. I followed the example in this thread viewtopic.php?f=63&t=164889&p=818225#p818225, modifying variant.cpp and variant.h to add Serial2 and Serial3. That compiles OK but I'm getting hangs on writing to Serial2.

Exact same failure using Serial3.

The symptom is *bit rate dependent*, in a way that makes me think the problem is with transmit-buffer-empty-interrupt. See code below. In setup, I send a string of 50 ASCII characters to Serial2, then print out the written count to Serial (USB), each time. It gets further along at lower Serial2 bit rates.

At high bit rates (115200) the USB count halts (hangs) at 5 or so. At 38400, it counts to 13. At 300 bits/sec, it prints out all 50, loop() code runs and prints, then it dies. So it's not in-line code that's fouled up but something time dependent, and since it depends on Serial2 tx write completion, suuuuuure smells of interrupt foulup.

But don't believe me! Here's code!

PS: My board is really old, Dec 2018. It has the latest boot loader installed. It's taken me this long to get around to moving my Mega2560 stuff to new hardware.

Code: Select all | TOGGLE FULL SIZE
long CCC;
char buff[] = "12345678901234567890123456789012345678901234567890";

void setup() {

  Serial.begin (115200);
  while (! Serial);
  Serial.println ("\nsetup");

  Serial2.begin (38400);           // vary this */
 
  Serial.print ("Serial2.print \"");
  Serial.print (buff);
  Serial.println ("\"");

  for (char *p= buff; *p;) {
    Serial.print (++CCC); Serial.print (",");
    Serial2.write (*p++);
  }
  Serial.println (" done");
}


void loop() {
  Serial.print ("loop ");
  Serial.println (millis());
  delay (500);
}

tomjennings
 
Posts: 78
Joined: Thu Aug 17, 2006 1:21 am

Re: Grand Central M4, Serial2 tx hangs, bit rate dependent

by tomjennings on Sat Jul 04, 2020 9:26 pm

More research and testing has made me even more confused.

I made an assumption (oops) that "Serial2" et al in the variants.* files for Grand Central M4 Express aligned with the board markings and implementation of the old Mega 2560 pinouts. I was of course wrong! My I/O hardware "shield" uses the old Serial2 and Serial3 pins which according to the variants.cpp file seem to be as follows:


Code: Select all | TOGGLE FULL SIZE
PIN       MEGA/DUE       GRAND CENTRAL variants.h
14           TX3          PIN_SERIAL4_TX
15           RX3          PIN_SERIAL4_RX
16           TX2          PIN_SERIAL3_TX
17           RX2          PIN_SERIAL3_RX


Obviously I don't care what they're called but I need UARTs on those electrical pins. Would this simply be defined as:

In file variant.h
Code: Select all | TOGGLE FULL SIZE
extern Uart Serial1;
extern Uart Serial3;   // tomj
extern Uart Serial4;   // tomj


In file variant.cpp
Code: Select all | TOGGLE FULL SIZE
// tomj
Uart Serial3( &SERCOM_SERIAL3, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX ) ;
Uart Serial4( &SERCOM_SERIAL4, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX ) ;


The only guide I can find to this stuff is the 'learn' page for a Feather board using a SAMD21 and different pin assignments, and it's old, and do I really have to mess around in Atmel SERCOM pin assignments to config these serial ports? That doesn't seem right...


Also I now get a compile error/warning, not mine:
Code: Select all | TOGGLE FULL SIZE
/Users/tomic/Library/Arduino15/packages/adafruit/hardware/samd/1.5.14/cores/arduino/WInterrupts.c: In function 'InterruptHandler':
/Users/tomic/Library/Arduino15/packages/adafruit/hardware/samd/1.5.14/cores/arduino/WInterrupts.c:253:32: warning: unused parameter 'i' [-Wunused-parameter]
 void InterruptHandler(uint32_t i)
                                ^

tomjennings
 
Posts: 78
Joined: Thu Aug 17, 2006 1:21 am

Re: Grand Central M4, Serial2 tx hangs, bit rate dependent

by tomjennings on Tue Jul 07, 2020 7:18 pm

Should I open this as a product bug report? I simply cannot get the SERCOMs to implement additional UART devices. It's a "board killer". The whole point of Grand Central M4 Express is PINS and approximate Mega 2560 pinout compatibility.

I'm perfectly willing to accept that I am making some trivial or other blunder here. But it would seem reasonable that Adafruit might deliver example code for common functions.

This is kinda messed up.

tomjennings
 
Posts: 78
Joined: Thu Aug 17, 2006 1:21 am

Please be positive and constructive with your questions and comments.