Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial port RX problem with IAR compiler #749

Closed
mstevanovic opened this issue Dec 1, 2014 · 10 comments
Closed

Serial port RX problem with IAR compiler #749

mstevanovic opened this issue Dec 1, 2014 · 10 comments

Comments

@mstevanovic
Copy link

I am using ST Nucleo F103RB platfrom with IAR compiler 7.20.
printf to serial port is OK. But, if I want to read from serial port this is not possible.
I am using Serial_HelloWorld_Mbed example and function is blocked on getc

There is no problem with ARM or GCC compiler. Only with IAR...

Best regards
Milan

@GustavWi
Copy link
Contributor

GustavWi commented Dec 3, 2014

Can you post the exact program you are using? @mstevanovic
//Gustav

@mstevanovic
Copy link
Author

Hi,

I am using example from mbed. Serial_HelloWorld_Mbed...
This is a link:
https://developer.mbed.org/handbook/Serial

Code:
#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx

int main() {
pc.printf("Hello World!\n");
while(1) {
pc.putc(pc.getc() + 1);
}
}

Also, I noticed that mbed test faild for IAR compiler (serial echo test...):
+---------+---------------+-----------+-----------+---------------------------------------+--------------------+---------------+-------+
| Result | Target | Toolchain | Test ID | Test Description | Elapsed Time (sec) | Timeout (sec) | Loops |
+---------+---------------+-----------+-----------+---------------------------------------+--------------------+---------------+-------+
| FAIL | NUCLEO_F103RB | IAR | MBED_24 | Timeout Int us | 25.8 | 15 | 0/1 |
| TIMEOUT | NUCLEO_F103RB | IAR | MBED_A9 | Serial Echo at 115200 | 20.77 | 10 | 0/1 |
| OK | NUCLEO_F103RB | IAR | MBED_23 | Ticker Int us | 14.34 | 15 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_25 | Time us | 14.39 | 15 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_26 | Integer constant division | 4.44 | 10 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_34 | Ticker Two callbacks | 14.45 | 15 | 1/1 |
| OK | NUCLEO_F103RB | IAR | DTCT_1 | Simple detect test | 3.51 | 10 | 1/1 |
| FAIL | NUCLEO_F103RB | IAR | EXAMPLE_1 | /dev/null | 8.75 | 10 | 0/1 |
| OK | NUCLEO_F103RB | IAR | MBED_A1 | Basic | 4.29 | 10 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_A21 | Call function before main (mbed_main) | 4.39 | 10 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_10 | Hello World | 3.38 | 10 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_11 | Ticker Int | 14.44 | 20 | 1/1 |
| OK | NUCLEO_F103RB | IAR | MBED_12 | C++ | 4.43 | 10 | 1/1 |
| FAIL | NUCLEO_F103RB | IAR | MBED_16 | RTC | 13.48 | 15 | 0/1 |
| FAIL | NUCLEO_F103RB | IAR | MBED_2 | stdio | 13.49 | 20 | 0/1 |
+---------+---------------+-----------+-----------+---------------------------------------+--------------------+---------------+-------+

@mstevanovic
Copy link
Author

Also, I noticed, from retarget.cpp next function is called
extern "C" size_t __read (int fh, unsigned char *buffer, size_t length)

and length parameter is 512... but from main, getc is called...

regards
Milan

@GustavWi
Copy link
Contributor

GustavWi commented Dec 3, 2014

Yes regarding serial echo test. gets(buffer, buffer size) call never returns. __read that is overwritten never returns -1 because it reads a unsigned char. fgets (a dlib function for IAR) allocates pages of 512 bytes to store the stream. When it encounter EOF it stops and fills the input buffer with as much of the pages as it can contain. The problem is that __read never encounter EOF and therefore just more pages get filled.

@mstevanovic
Copy link
Author

OK. but in this example getc is called and in __read I see that length is 512... Why?
for gets and getc 512 bytes are allocated?

@mstevanovic
Copy link
Author

Hi Gustav,

I see some fix for on github for this problem. I take example and export to IAR and still have same problem. I am using next mbed revision: 92:4FC01DAAE5A5
This is from mbed online compiler and I did export to IAR. IAR compiler 7.20 is used.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 11, 2014

@mstevanovic Did you use mbed-src (replace mbed lib with mbed-src)? I believe the revision is for the mbed library.

@mstevanovic
Copy link
Author

OK. I will try with mbed-src. My fault, I used mbed lib.
Thanks....

@mstevanovic
Copy link
Author

Yes. It is OK. Thanks a lot.

@GustavWi
Copy link
Contributor

Glad to hear that. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants