Also can't get Serial to work...MCU hangs

Post here first, or if you can't find a relevant section!
Post Reply
phil bowles
Posts: 13
Joined: Mon May 25, 2020 10:15 am

Also can't get Serial to work...MCU hangs

Post by phil bowles »

What's up with Serial.print on NUCLEO-F429ZI ? Trying to put some diagnostics in code...90% of my Serial.print statements cause the MCU to hang. In one place, Serial.printf("012\n"); works fine...replace with Serial.printf("0123\n"); MCU hangs

Arduino 1.8.13
STM32 Core 1.9.0
Board NUCLEO-F429ZI
U(S)ART Support: "Enabled (generic Serial)
USB support: "None"

I'm using the STM32Ethernet library also: I raed somewhere else that someone had problems using Serial.print with this lib...

Code: Select all

void onMqttMessage(const char* topic, uint8_t* payload, struct PANGO_PROPS props, size_t len, size_t index, size_t total) {
  Serial.printf("0123\n"); // works when "0","01","012" hangs when == "0123"
}
...
15:16:14.765 -> IP: 192.168.1.177
15:16:15.750 -> MAC IS 00:80:e1:45:00:44
15:16:15.784 -> Connect to MQTT!
15:16:15.784 -> 01
15:26:28.442 -> IP: 192.168.1.177
15:26:29.461 -> MAC IS 00:80:e1:45:00:44
15:26:29.461 -> Connect to MQTT!
15:26:29.461 -> 012
15:27:06.942 -> IP:
What is going on? Its making my the whole thing unusable!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Also can't get Serial to work...MCU hangs

Post by fpiSTM »

Issue with Ethernet was link to the use of an USART pin which is also used for ETH which is not possible.
I don't think the hangs come from the Serial. Which optimization you used?
What is the full sketch?
phil bowles
Posts: 13
Joined: Mon May 25, 2020 10:15 am

Re: Also can't get Serial to work...MCU hangs

Post by phil bowles »

Full sketch use ther external libraries, so not practical to post - I have narrrowed it down to the "hang" after it outputs 64 characters...
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Also can't get Serial to work...MCU hangs

Post by fpiSTM »

So the best way is to debug to find the real cause (IRQ prio, deadlock...)
phil bowles
Posts: 13
Joined: Mon May 25, 2020 10:15 am

Re: Also can't get Serial to work...MCU hangs

Post by phil bowles »

I can't debug - because: I cant print anything betond 64 characters!!! That's how this started....BUT

I just found it only happens in startup. If startup prints nothing at all, then all my debug messages now come pouring out:

Code: Select all

CONNECT as nucleo-f429zi FH=30000
----> SEND CONNECT 79 bytes on wire
<---- FROM WIRE CONNACK 20009D8A len=4
DUMP ALL 0 POOL BLOX
TXQ EMPTY
RXQ EMPTY
DUMP ALL 0 PACKETS OUTBOUND
DUMP ALL 0 PACKETS INBOUND
DUMP ALL 0 FRAGMENTS

Auto-subscribed to PANGO
----> SEND SUBSCRIBE 12 bytes on wire
----> SEND SUBSCRIBE 12 bytes on wire
<---- FROM WIRE SUBACK 20009D8A len=5
----> SEND PUBLISH 27 bytes on wire
<---- FROM WIRE SUBACK 20009D8A len=5
<---- FROM WIRE PUBLISH 20009D8A len=27
INBOUND PUBLISH stm32 id=0 @ QoS0 R=false DUP=0 PL@20009D93 PLEN=18
1234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890
----> SEND PINGREQ 2 bytes on wire
<---- FROM WIRE PINGRESP 20009D8A len=2
----> SEND PINGREQ 2 bytes on wire
<---- FROM WIRE PINGRESP 20009D8A len=2
----> SEND PINGREQ 2 bytes on wire
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Also can't get Serial to work...MCU hangs

Post by fpiSTM »

And what did you expect with only your console output?
Without (at least) the sketch we can't help. Moreover you said you used external libraries which one? Probably the hangs come from one of them (for example if one of them disable the interrupt then as Serial use interrupt this will simply print nothing and wait until interrupt was reenabled).
You told this is linked to Serial but as said this is probably not the case. When I told debug, I didn't talk about print but using a real debugger to break, inspect and step.
I know with Arduino IDE this is not possible anyway, it is possible but for advanced user who use other IDE (VScode, eclipse, ...)
phil bowles
Posts: 13
Joined: Mon May 25, 2020 10:15 am

Re: Also can't get Serial to work...MCU hangs

Post by phil bowles »

Yes, I suspect is is something in those other libraries - the sketch only start every fourth of fifth attempt on reset. And if Serial has a 64-byte buffer which it can't clear because interrupts are disabled, then I guess we'd be seeing this behaviour

FWIW: here's the whole sketch:

Code: Select all

#include <LwIP.h>
#include <STM32Ethernet.h>
#include <PangolinMQTT.h>

IPAddress ip(192, 168, 1, 178);

PangolinMQTT mqttClient;

#define MQTT_HOST IPAddress(192, 168, 1, 21)
#define MQTT_PORT 1883

#define START_WITH_CLEAN_SESSION   true

void onMqttConnect(bool sessionPresent) {
//  Serial.printf("Connected to MQTT: Session=%d Max safe payload %u\n",sessionPresent,mqttClient.getMaxPayloadSize());
  mqttClient.subscribe("stm32",0);
  mqttClient.publish("stm32",0,false,std::string("Oh my god it works"));
}

void onMqttMessage(const char* topic, uint8_t* payload, struct PANGO_PROPS props, size_t len, size_t index, size_t total) {
  PANGO::dumphex(payload,len);
}

void onMqttDisconnect(int8_t reason) {
  Serial.printf("Disconnected from MQTT reason=%d\n",reason);
}
void setup() {
  Serial.begin(115200);
  Ethernet.begin(ip);
  Serial.print("IP: ");
  Serial.println(Ethernet.localIP());
  
  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onMessage(onMqttMessage);
  mqttClient.setServer(MQTT_HOST, MQTT_PORT);
  mqttClient.setWill("NUCLEO_DIED",2,false,"It's 'Alpha': probably sill some bugs");
  mqttClient.setCleanSession(START_WITH_CLEAN_SESSION);
  mqttClient.connect();
}


void loop() {}
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Also can't get Serial to work...MCU hangs

Post by fpiSTM »

Well quickly looking your libraries, without real debugging I guess this would be hard to find the root cause.
phil bowles
Posts: 13
Joined: Mon May 25, 2020 10:15 am

Re: Also can't get Serial to work...MCU hangs

Post by phil bowles »

I agree!
Post Reply

Return to “General discussion”