Hot!Debugging: Can I redirect printf or putchar to the MPLAB X console?

Page: 12 > Showing page 1 of 2
Author
user2x
Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
2018/02/07 16:52:03 (permalink)
0

Debugging: Can I redirect printf or putchar to the MPLAB X console?

Instead of going through a UART, can I go through the debugger and have output ending up in some window?
I ask because I have no spare uarts when I have the debugger connected to the dsPIC33EP512MU810.
 ICD3 debugger
It would be great to debug AND have console output.
 
They have an example like this 

 
#include <xc.h>
 
 

 
// set up config bits

 
#pragma config FWDTEN = OFF

 
 

 
// initialize variables

 
unsigned int val;

 
int i;

 
unsigned int oval;

 
 

 
int main(void)

 
{

 
   while(1)

 
   {

 
    if(APPSbits.APIFUL)    // APPI is full?

 
      {

 
       val = _APPIN;       // Read User Input

 
       for(i=0; i<4; i++)

 
         {

 
          while(APPSbits.APOFUL); // APPO is full?

 
          oval =  val&0xFF;

 
          if(oval < 0x20)

 
             oval = 0x20;

 
          oval |= 0x20202000;

 
          _APPO = oval;           // Send to MPLAB X IDE

 
          val >>= 8;

 
         }

 
      }

 
   }

 
   return 0;

 
}

 

 
But none of those registers seem to exist here nor can I find them in the datasheet.
They sate that this example is used with the XC16 compiler on a dsPIC33EP256GP506.
I cannot find these registers in that DS either.
 
 
The debugging tool list shows
 
App/IO as 
Yes:RI-N/A:ICD3
 
for all these devices.
???
 
Regards
X
post edited by user2x - 2018/02/07 17:30:43
#1

29 Replies Related Threads

    qɥb
    Monolothic Member
    • Total Posts : 1290
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: online
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 17:20:51 (permalink)
    0
    Microchip call this feature "App IO".
    They only support it with the "Real ICE" debugger.
     
    Personally, this seems like a marketing ploy, I'm sure they could implement it on the cheaper debuggers.
     

    PicForum "it just works"
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 15515
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 17:29:19 (permalink)
    0
    Some PICs and Debuggers support "APPIO" which will do what you want.  But you need the right PIC with the Right debugger, and it appears to be hard to setup and poorly documented (last I checked).
     
    So Maybe.
    #3
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 17:38:50 (permalink)
    0
    Hmm, the example they mention states they used an ICD3.
    And the MPLAB X with ICD3 has a APP IO window. I just checked and it is not greyed out.
     
     
    post edited by user2x - 2018/02/07 17:40:30
    #4
    qɥb
    Monolothic Member
    • Total Posts : 1290
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: online
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 17:43:19 (permalink)
    +1 (1)
    Search this page for dsPIC33EP512MU810
    http://ww1.microchip.com/downloads/en/DeviceDoc/HWToolDebugFeatures.pdf
     
    In the "App IO" column, it says:


    Yes:RI
    N/A:ICD4
    N/A:ICD3

    "RI" means Real ICE.
     

    PicForum "it just works"
    #5
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 17:47:18 (permalink)
    0
    Oh crapola. Is that what that N/A:ICD3 means.
    I made a mistake then. My apologies.
     
    That sucks though as I really need that output for this comms stuff I work on.
     
     
    #6
    du00000001
    Just Some Member
    • Total Posts : 1581
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 18:08:09 (permalink)
    0
    Why not use a USB hub to get more possible vcom ports?

    Most times the bug is in front of the keyboard.
    #7
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 18:10:36 (permalink)
    0
    No USB on this PIC and every other port is used for stuff.
     
    The logging / debug com port output is on the same pins as the ICD3. So If I use the logging output, I loose the debugger connectivity and vice versa.
    post edited by user2x - 2018/02/07 18:12:14
    #8
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 19:17:32 (permalink)
    0
    I just obtained a Real ICE (this place has all sorts of stuff lying around) and it is the same.
    Still none of the registers mentioned in the example above are available and there is no tick box to enable APP IO as mentioned in the documentation.
     
     
     
     
    #9
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 19:17:32 (permalink)
    0
    I just obtained a Real ICE (this place has all sorts of stuff lying around) and it is the same.
    Still none of the registers mentioned in the example above are available and there is no tick box to enable APP IO as mentioned in the documentation.
     
     
     
     
    #10
    qɥb
    Monolothic Member
    • Total Posts : 1290
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: online
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 20:29:24 (permalink)
    0
    Have a look at this topic: http://www.microchip.com/forums/m996669.aspx
     

    PicForum "it just works"
    #11
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 20:44:21 (permalink)
    0
    Intersting but it does not work for me.
     
    He upgraded to XC16 1.31 from an earlier version and the registers in question became available.
    I am running XC16 1.33 and they are not available.
     
    Far out, how can there be registers that are not described ion the datasheet !
    #12
    qɥb
    Monolothic Member
    • Total Posts : 1290
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: online
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 20:52:52 (permalink)
    0
    Are you sure you're including xc.h?
    That will be pulling in C:\Program Files (x86)\Microchip\xc16\v1.33\support\dsPIC33E\h\p33EP512MU810.h
    and that header file most certainly does contain the definition for the APPSbits structure.
     
    How exactly are you determining that they are not available?
     
    post edited by qɥb - 2018/02/07 20:54:03

    PicForum "it just works"
    #13
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/07 21:39:25 (permalink)
    0
    Yes,
    see here:

     
     
     
     
     
     
     
    #include <xc.h>
    #include <commonincludes.h>
    #include <StackTsk.h>
    #include <communicatorStates.h>
     
     
     
     
     
     
     

     
    And they are not available by the compiler telling that they are not.
    Also, when I try and go to the source / definition of one, nothing and also a search in projects finds nothing.
     
    Strange.
     
    Even stranger, searching the datasheet finds nothing either.
     
    Edit: I have checked the <xh.h> and it includes the file "p33EP512MU810.h"
    whej I open that file and search for APPIN, or APPSbits or APPS, I find nothing.
     
    Edit2: I think I foudn the problem. my header file is a local copy in the project. I will now need to see why they did that  and what the differences are. Hopefully none and I can use the new one as is.
    post edited by user2x - 2018/02/07 22:06:34
    #14
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/08 15:01:37 (permalink)
    0
    Yikes, it is still a problem.
     
    I had to sort out issues with the new version .h file as a lot of stuff was not compatible. I am finally up and running again.
     
    The .h file DOES have these application io registers defined like this:
     

    typedef struct tagAPPSBITS {
    uint16_t APIFUL:1;
    uint16_t APIOV:1;
    uint16_t APOFUL:1;
    uint16_t APOOV:1;
    uint16_t STRFUL:1;
    } APPSBITS;
    extern volatile APPSBITS APPSbits __attribute__((__sfr__));

     
    but when I compile, the linker pipes up with 

    build/default/debug/_ext/1360937237/main.o(.text+0x216): In function `test1':
    ../src/main.c:927: undefined reference to `_APPSbits'
    build/default/debug/_ext/1360937237/main.o(.text+0x21a):../src/main.c:929: undefined reference to `__APPIN'
    build/default/debug/_ext/1360937237/main.o(.text+0x220):../src/main.c:932: undefined reference to `_APPSbits'
    build/default/debug/_ext/1360937237/main.o(.text+0x232):../src/main.c:937: undefined reference to `__APPO'

     
    When I click on the registers in the test code and navigate to declaration/definition, it ends up in the correct place in that .h file. 
     
    I noticed that these regs are declared as extern in that h file but where are they then supposed to be defined? 
     
    Regards
    X
     
     
    #15
    qɥb
    Monolothic Member
    • Total Posts : 1290
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: online
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/08 15:09:07 (permalink)
    +1 (1)
    Are you using a custom linker file?
     

    PicForum "it just works"
    #16
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/08 15:13:27 (permalink)
    0
    It is possible but I hope not.
    How do I check / find out? 
     
    This is the linker command line:
     

    --local-stack --check-sections --data-init --pack-data --handles --isr --no-gc-sections --fill-upper=0 --stackguard=16 --library-path="../linker",--library-path="." --no-force-link --smart-io -Map="${DISTDIR}/sncnave.X.${IMAGE_TYPE}.map" --report-mem --warn-section-align

     
    post edited by user2x - 2018/02/08 15:15:36
    #17
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/08 15:28:37 (permalink)
    +1 (1)
    You were correct, they are using a local copy of the linker file. I just replaced it and voila, registers are now resolved.
    Thanks!
    post edited by user2x - 2018/02/08 15:39:56
    #18
    user2x
    Senior Member
    • Total Posts : 122
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/08 17:04:56 (permalink)
    0
    But, I still cannot get this working correctly.
     
    Working yes, correctly no.
    As in that sample code (up top)
     
    Firstly one has to press Enter to get any input going from the Appp IO window. that is already weird as a terminal input should be sent as it is typed.
     
    So, when I press type say H and Enter, I do get the APPSbits.APIFUL set.
    However, the _APPIN register always just contains 0x6473. Does not matter what I actually type.
    For 'H', I would expect a 0x48 in there somewhere.
     
    Similarly, I am not sure what that code is actually supposed to do with oval |= 0x20202000. The oval itself is defined as a 16 bit so no idea what they were trying to do.
    But never mind, when I force oval = 0x48 and then _APPO = oval, I do get 'H' on the IDE app io window output!
     
    Summary:
    Input not wiorking
    Code dubious
    Output can work
     
     
     
     
    #19
    qɥb
    Monolothic Member
    • Total Posts : 1290
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: online
    Re: Debugging: Can I redirect printf or putchar to the MPLAB X console? 2018/02/08 17:28:03 (permalink)
    0
    user2x
    However, the _APPIN register always just contains 0x6473. Does not matter what I actually type.

    "ds"
    strange

    Similarly, I am not sure what that code is actually supposed to do with oval |= 0x20202000. The oval itself is defined as a 16 bit so no idea what they were trying to do.

    The lazy buggers have just copied the 32 bit example.
    Plainly they are only 16 bit registers in your PIC.
    Always take Microchip "example code" with a grain of salt (and common sense!)
     

    PicForum "it just works"
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5