cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 application while(1) loop stops after 60 seconds only when UART running

harinath
Associate III
Posted on September 11, 2013 at 15:20

Hello,

I'm developing firmware(FW) for STM32F103RE mcu, an USB & UART bluetooth module (PAN1321i) connected to mcu. Application has 4 working modes. In all the FOUR modes FW supposed to send & receive data to USB or bluetooth or to both. Computer initiates connection to the device via USB virtual COM port or Bluetooth COM port.

1. FW works fine when USB virtual COM port opened in PC.

2. FW does work fine when USB virtual COM port & Bluetooth COM port opened in PC.

3. FW stops executing while(1) loop after 60 seconds when only Bluetooth COM port opened in PC.

4. FW works fine (doesn't sends & receives data if USB or Bluetooth ports are not opened)

In hardware the UART2 of STM32 connected to Bluetooth module. When I open Bluetooth COM port in PC and send some bytes, I can see the data received in USART2 Rx interrupt handler when debugging the FW using breakpoints in IAR EWARM. But the while(1) loop is not running. Now If I open USB virtual COM port, again the FW sends & receives data via Bluetooth. 

Now If I close the USB virtual COM port, again the while(1) loop stops running after 60sec.

What is this behavior ? Is the STM32 going into sleep mode when USB not connected ?

I do not have any code which will place STM32 into sleep mode.

Thanks in advance.

#stm32f103 #time-to-start-debugging #60-seconds #don''t-just-sit-there---debug!
12 REPLIES 12
Posted on September 11, 2013 at 17:15

Okay, so if the program is not running in the while(1) loop, can you determine where does it run? Can you break the program in that state and, using the IAR tools, have a look where does the program counter point?

JW

jpeacock2399
Associate II
Posted on September 11, 2013 at 21:30

<< When mode 1 and mode 2 are working fine for more than 10 hours properly, why doesn't the mode 3 work ? The described problem is repeatable. >>

In a sense you just answered your own question.  Your program fails on a certain event, ''mode 3''.  The while() loop not running is a symptom, not the disease.  Somewhere in your mode 3 code there's a bug that stops control from returning to your while loop.  You need to trace through the event that fails.

This is more about basic debugging and programming skills rather than anything to do with the STM32.  You might want to consult with a senor level embedded programmer for some help.

  Jack Peacock
harinath
Associate III
Posted on September 12, 2013 at 06:47

Dear all,

I thank you all of your comments and suggestions. I traced out the bug.

The FW was sending some bytes to USB virtual COM in Mode 3 which are received from Bluetooth Rx buffer. This piece of code was written for Bluetooth Rx data debugging purposes, but forgot to remove.  I thank you once again all the genius people here.

Is it a problem writing to USB virtual COM port when the port it is not opened in PC ?

Why did the FW while(1) loop freeze after 60 sec ? 

Though I solved the problem. These two questions are still mystery for me.