Report
2 years, 5 months ago.

Embed hanged when use Serial attach(&fun) method

Hi,

i am reading a serial interrupt my code is as below. mbed hanged in the attach method. i am not able to figure out what is wrong here.

  1. include<mbed.h> RawSerial ella(PTC15, PTC14);TX, RX to connect ELLA pump

void rx_ella() { printf("....%c", ella.getc()); }

main() { ella.baud(115200); ella.attach(&rx_ella); }

Comment on this question

3 Answers

2 years, 5 months ago.

Hello,
Try do add a while loop to keep the application running while waiting for the serial interrupts:

#include<mbed.h>

RawSerial ella(PTC15, PTC14);   //TX, RX to connect ELLA pump

void rx_ella()
{
    printf("....%c", ella.getc());
}

main()
{
    ella.baud(115200);
    ella.attach(&rx_ella);
    while(true){}
}

NOTE: If you enclose a code here with <<code>> and <</code>> markers as below (each marker on its own separate line!) then it's going to be displayed as source code in a frame.

<<code>>
#include<mbed.h>

RawSerial ella(PTC15, PTC14);   //TX, RX to connect ELLA pump

void rx_ella()
{
    printf("....%c", ella.getc());
}

main()
{
    ella.baud(115200);
    ella.attach(&rx_ella);
    while(true){}
}
<</code>>

Sorry i forgot to copy while loop in the question but i had the same in my code. This works fine if i don't include the RTOS. After including the mbed-RTOS It didn't work for me. I have FRDM-K64F development board.

posted by Suraj Pal 22 Mar 2017

In that case can you show what you are actually using as code? Because apparently you are not using the code you shown above on several points. Are you for example actually using RawSerial, or normal Serial?

posted by Erik Olieman 23 Mar 2017

Hello,
It doesn't work also for me when I compile with the online compiler for the LPC1768 target. However, it works as expected when I compile offline for the same target using the GCC ARM toolchain. I haven't tested other targets yet.

posted by Zoltan Hudak 30 Mar 2017
2 years, 4 months ago.

There have been several recent reports of calls to the Serial attach function hanging some STM targets. I previously reported the problem for the NUCLEO-L432KC, NUCLEO-F303RE and NUCLEO-F303K8 boards, but my NUCLEO-F103RB and NUCLEO-F401RE boards did not appear to be affected. Other commenters corroborated my findings and also found the same problem with the NUCLEO-F411RE. I have not seen any reports of this problem with other target vendors, but this problem with the FRDM-K64F development board may be related.

I found that the Serial attach function call would fail to execute (hang up the target) if there was data present on the Serial Rx line at the time the function call is made. The same code executes successfully if there is no input to the Serial Rx line at the time of the Serial attach function call. I also found that this behavior appeared to have been introduced with mbed 2.0 Rev 125. The same code executed properly with or without data present at the Serial Rx line using mbed 2.0 Rev 124. Others reported the same result and Jan Jongboom submitted a bug report on it.

You can find my initial thread here:

https://developer.mbed.org/questions/74236/Possible-bug-in-Serial-attach-function-w/#answer11037

The bug report is here, but there appears to have been no action on it:

https://github.com/ARMmbed/mbed-os/issues/2670/

I was able to resolve the problem in my code by explicitly disabling the USART prior to calling the attach function, and then re-enabling the USART after the callback function is attached. The code for USART1 on the Nucleo L432KC is:

//  disable USART1
//  USART1 base address is defined in "stm32l432xx.h" 

(USART1)->CR1 &=  ~USART_CR1_UE; 

//  attach the callback function                           

pc.attach(&rx_callback,Serial::RxIrq);

//  re-enable USART1

(USART1)->CR1 |=  USART_CR1_UE;

Have you isolated the problem to the actual function call (eg. by printing diagnostic messages immediately before and after the Serial attach function call)? Does the function call only fail to execute when there is data present at Serial Rx line when you make the function call (eg. only when the Ella pump is connected)? If so, someone familiar with NXP boards may be able to supply the appropriate code to try the same fix for the FRDM-K64F development board.

2 years, 4 months ago.

Hi,

I am having the same issue with FRDM-K64F board and mbed-os. Callback is working with mbed 2.

Did anyone had a luck making serial interrupt to work on mbed-os?

Yes I did when I compiled offline for the LPC1768 target using the GCC ARM toolchain.

posted by Zoltan Hudak 30 Mar 2017

You exported mbed project to GCC (ARM embedded) and compiled it offline?

posted by Amar Mahmutbegovic 01 Apr 2017

I used GNU ARM Embedded Toolchain to compile off line. For mbed I downloaded the latest revision of mbed-os as zip archive.

posted by Zoltan Hudak 01 Apr 2017

If anyone interested in solution - I managed to solve the issue with RX interrupt on FRDM-K64F board by compiling code with offline compiler, I used GCC ARM.

posted by Amar Mahmutbegovic 06 May 2017

You need to log in to post a question