Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12745 Discussions

segmentation fault with nios2-terminal and printf/alt_printf statements

BeB
Beginner
1,243 Views

Hello,

I am running into segmentation faults using either alt_printf or printf to output debug messages from a nios 2 application via the nios2-terminal application.

The code runs fine without the debug print messages, and also runs fine with the debug print messages in debug mode with breakpoints at the troublesome debug print statements.

I will add that some debug print messages are printed normally, so it is not a systematic issue with printf / alt_printf. Changing the messages that fail still leads to a segmentation fault (reducing the size of the message or the nature of it - integer vs string for example).

It cannot be a code issue since it's running fine in debug mode. I am a bit lost here.

 

My RAM should be more than large enough:

$ nios2-elf-size nios_app.elf
text data bss dec hex filename
34892 884 376 36152 8d38 nios_app.elf

$ nios2-stackreport nios_app.elf
Info: (nios_app.elf) 35 KBytes program size (code + initialized data).
Info: 91 KBytes free for stack + heap.

 

I have the feeling that the issue comes from the JTAG uart. I have seen suggestions online to flush the stdout with fflush, but Eclipse fails to resolve the reference to fflush although stdio.h is included. Could be because I am running the economical Nios implementation?

 

Increasing the JTAG uart buffer size or decreasing it does not seem to make a difference.

 

Thank you for any suggestions!

 

Bertrand

 

 

0 Kudos
10 Replies
JingyangTeh_Altera
1,161 Views

Hi


This is a weird behaviour.

In the BSP setting did you select the JTAG Uart as the stdout for the print function?


Regards

Jingyang, Teh


0 Kudos
BeB
Beginner
1,126 Views

Hello,

 

Yes, stdout is the JTAG uart.

 

Thank you,

Bertrand

0 Kudos
JingyangTeh_Altera
1,063 Views

Hi


That is very weird.

One thing could you try is to run just a simple hello world to see if it is working?

https://community.intel.com/t5/Nios-V-II-Embedded-Design-Suite/Nios-V-Processor-Installation-and-Hello-World-Execution-Part-1/m-p/1552554


If it is fine with you could you share your project and I can try to have a look at it?


Regards

Jingyang, Teh


0 Kudos
BeB
Beginner
878 Views

Hello,

 

Sorry for the late reply.

 

A simple 'hello world' works fine. 

 

It seems that changing the size of the stdout uart buffer solved the problem. A too large buffer causes the segmentation fault. Reducing the buffer size eliminated the issue (with the exact same code otherwise!).

 

Thank you,

Bertrand

0 Kudos
JingyangTeh_Altera
1,032 Views

Hi 


Do you have any update on this case?


Regards

​​​​​​​Jingyang, Teh


0 Kudos
BeB
Beginner
878 Views

Hello,

 

Sorry for the late reply.

 

It seems that changing the size of the stdout uart buffer solved the problem. A too large buffer causes the segmentation fault. Reducing the buffer size eliminated the issue (with the exact same code otherwise!).

 

Thank you,

Bertrand

0 Kudos
JingyangTeh_Altera
1,010 Views

Hi


As we do not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


Regards

Jingyang, Teh



0 Kudos
JingyangTeh_Altera
833 Views

Hi


If you mind sharing, what was the buffer size that you use initially? and what was the reduced size that managed to get it to work?


Regards

Jingyang, Teh


0 Kudos
JingyangTeh_Altera
704 Views

Hi


Do you have any update from the previous comment?


Regards

Jingyang, Teh


0 Kudos
JingyangTeh_Altera
638 Views

Hi


As we did not receive any response from you on the previous question/reply/answer that we have provided. Please login to ‘https://supporttickets.intel.com/s/?language=en_US’, view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions.


Regards

Jingyang, Teh


0 Kudos
Reply