Menu

#98 OpenOCD semihosting output in Eclipse console (custom project)

Version 1.x
closed
semihosting (2)
5
2015-02-07
2015-01-11
Justyn
No

Hi,

I have a custom (not created with the build plugin) STM32 project that uses newlib-nano and gcc-arm-embedded built-in printf and semihosting support.

I am debugging it with the OpenOCD debugging plugin (201412191510) in Eclipse Luna.

If I start OpenOCD in a separate terminal and then debug using the plugin (with local OpenOCD start disabled), I can see the printf (stdout) output in the terminal, amongst the general OpenOCD messages.

However, if I select "Start OpenOCD locally" and debug, I see only the general OpenOCD messages in the openocd console in Eclipse but not the actual printed statements.

Is it possible for me to see the semihosting output from within Eclipse using the plugin, for a project like this? I know it works when debugging a project created using the build plugin.
The automatic starting of OpenOCD is a great feature, I would very much like to use it.

Thanks for your help.

Discussion

  • Liviu Ionescu (ilg)

    • status: open --> accepted
    • assigned_to: Liviu Ionescu (ilg)
     
    • Justyn

      Justyn - 2015-01-11

      Thanks for the suggestions.

      I've just tried a separate project using the template system code, linker
      and trace_printf(), with an identical debugging setup.

      In both projects, if I run OpenOCD separately in a terminal and then step
      through the program, I can see the printed output in the terminal window.

      However if I have the plugin start OpenOCD in Eclipse, only the template
      project using trace_printf shows the semihosting printed output in the
      OpenOCD window in Eclipse. The other project only shows the other
      non-printed OpenOCD messages.

      The strings are terminated with a newline (backslash n).

      What is it that trace_printf does differently?
      Is it possible/sensible to add the trace_printf code to an existing project
      that is not based on the template without changing the linker script?

      Thanks for your help.

       

      Last edit: Justyn 2015-01-11
      • Justyn

        Justyn - 2015-01-11

        [deleted post]

         

        Last edit: Justyn 2015-01-11
      • Liviu Ionescu (ilg)

        Is it possible/sensible to add the trace_printf code to an existing project

        sure, everything is source code. just that you might need to tweak some details.

         
        • Justyn

          Justyn - 2015-01-12

          I found the problem, initialise_monitor_handles() wasn't being called before printf.

          OpenOCD was still picking up the strings sent by printf, which caused the confusion, but I think they weren't actually in the correct stream (stdout/stderr).

          I also tested your trace_printf and trace_puts functions. They are smaller than the gcc-arm-embedded builtin options (particularly trace_puts).

          For interest here's a quick size comparison I did on a very simple STM32F0 program, compiled with -Og optimisation and OS_USE_TRACE_SEMIHOSTING_DEBUG, and linked with --gc-sections --specs=nano.specs --specs=rdimon.specs.

          Function - Total size (dec)
          none - 4544
          trace_puts - 4772
          trace_printf - 7296
          printf - 8172
          puts - 8176
          scanf,printf - 12904

          The trace code could be very useful as a separate module, it integrated easily with my code.
          Would you consider allowing it to be put in a separate git repo and licensing it under BSD or something similar?

          Anyway, thanks for your help.

           
          • Liviu Ionescu (ilg)

            ... initialise_monitor_handles()

            ah, sorry, I forgot to tell you, this is a classical mistake

            separate module ... a separate git repo ... BSD license

            that code is part of another project (µOS++), released currently under MIT license.

            please keep a reference to the project and the original copyright notice.


            as a major change in GNU ARM Eclipse, I work on a component based template and build mechanism, and the trace code will probably be a separate component, but it'll take a while until this will be available.

             
            • Justyn

              Justyn - 2015-01-14

              Great, I put the code up here to make it easier for me to include it in my projects and where it may be useful to others:
              https://github.com/justyn/semihosting-cortexm-uos

              Thanks again for all your good work!

               
              • Liviu Ionescu (ilg)

                you have a small typo in README.md, trace_print should be trace_printf.

                as a suggestion, when you list the functions it might be useful to give not only the name, but the full prototype.

                some examples might also be useful, how to initialise everything, how to define the macros, etc.

                 
                • Justyn

                  Justyn - 2015-01-14

                  Thanks, I've corrected that and added some more info to the readme.

                   
  • Liviu Ionescu (ilg)

    If the 'Enable semihosting' button is checked in the Startup tab, the 'monitor arm enable semihosting' command is passed to openocd and semihosting is routed to the Eclipse console.

    It is very unusual to hear that this does not work.

    I suggest you create a project with the templates and check the differences between the use of semihosting.

    I would also check if the printf() lines have a \n at the end, otherwise the lines may not be flushed before a buffer gets full.

     

    Last edit: Liviu Ionescu (ilg) 2015-01-11
  • Liviu Ionescu (ilg)

     

    Last edit: Liviu Ionescu (ilg) 2015-01-11
    • Justyn

      Justyn - 2015-01-11

      Sorry about that, the email reply feature on Sourceforge was not kind to me.

       
  • Liviu Ionescu (ilg)

    If you are interested, there is a new OpenOCD plug-in and package:

    https://sourceforge.net/p/gnuarmeclipse/beta-versions/16/

    I would appreciate any feedback.

     
  • Liviu Ionescu (ilg)

    • status: accepted --> closed