Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 8 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.
- 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); }
3 Answers
7 years, 8 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 22 Mar 20177 years, 7 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.
7 years, 7 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 30 Mar 2017I used GNU ARM Embedded Toolchain to compile off line. For mbed I downloaded the latest revision of mbed-os as zip archive.
posted by 01 Apr 2017