assign printf to bitbucket

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

assign printf to bitbucket

Jump to solution
1,783 Views
Cdn_aye
Senior Contributor I

Hi

I am getting debugging printf statements on the serial port I use for a BT connection. Which really confuses the BT module. Is there anyway to build the bsp to direct printf to a bitbucket or NULL device?

I tried assigning the default

#define BSP_DEFAULT_IO_CHANNEL              "ttyb:"         //  change so printf's not going on BT channel, ittya

but that didn't work.

I have read that termio.c has something to do with this, but I can't find it.

Under 3.8.1 I commented out all the printf's or I could make a dummy function printff and do a global change. But then this has to be done for every upgrade... which is a pain.

Any suggestions would be gratefully accepted.

Thanks

Robert

0 Kudos
1 Solution
1,095 Views
Martin_
NXP Employee
NXP Employee

Hi Robert,

at low level, printf() calls MQX serial IO driver or does it call C library printf() function (in your application) ? If it's MQX, you can use for example null device if you wish. Just make sure the driver is installed (_io_null_install()) and then you can direct stdout to the null device as shown in Martin's response.

View solution in original post

0 Kudos
11 Replies
1,096 Views
Martin_
NXP Employee
NXP Employee

Hi Robert,

at low level, printf() calls MQX serial IO driver or does it call C library printf() function (in your application) ? If it's MQX, you can use for example null device if you wish. Just make sure the driver is installed (_io_null_install()) and then you can direct stdout to the null device as shown in Martin's response.

0 Kudos
1,095 Views
Cdn_aye
Senior Contributor I

Hi Martin & Martin

I am using only MQX, I am not linking against any other libraries as far as I know.

I think I understand the principle but am unsure on how to implement.

Do I:

  1. define BSPCFG_ENABLE_IODEBUG in user_config.h? Then rebuild the BSP? Because the chapter pointed to refers to the IO_DEBUG driver. But I am wanting to change the printf, STDOUT function... are they related? Is the debug driver necessary to redirect printf?
  2. From what I understand in what you have pointed out, the best way is to install the null driver. Then redirect the STDOUT function to the null driver. To do this, do I install the NULL Driver, then do a file open of the null driver with a file block pointer fh_ptr, then using fh_ptr redirect STDOUT using;   _io_set_handle(IO_PROC_STDOUT, fh_ptr); Where fh_ptr is the ptr to the file block?
  3. Why would we use the method in (2) instead of this one? _io_set_handle(IO_PROC_STDOUT, fh_ptr);

Thank you for helping

Regards

Robert

0 Kudos
1,095 Views
Cdn_aye
Senior Contributor I

Hi Martin & Martin

This worked as you explained; I just installed the null driver, then redirected STDOUT to that driver and the printf statements stopped appearing on my default port. The IO_DEBUG was a red herring I guess.

Thank you for the help

Robert

Message was edited by: Robert Lewis here is the code in case someone else finds it useful MQX_FILE_PTR                                gs_NullDrv      = NULL; . . . .     _io_null_install("NULL_DRV:");                      // install null driver so we can redirect printf debug statements in mqx     gs_NullDrv = fopen("NULL_DRV:", NULL);;             // get the Null driver file descriptor block     _io_set_handle(IO_PROC_STDOUT, gs_NullDrv);         // sets std out to null driver

0 Kudos
1,095 Views
Teckna
Contributor V

Hi,

I have a similar problem.

In my system (MQX 3.8.1, CW 10.2 and a custom board based on K60) there is an unique serial port that is used for connection; sometimes I need to use it for debug (using printf).

I tried to use _io_set_handle function, but the IO_STDOUT flag set the handle only to the active task, all the other ones continue to work the old way.

Is there a way to set the handle to all the tasks in the system?

Many thanks

Teckna

0 Kudos
1,095 Views
Martin_
NXP Employee
NXP Employee

try _io_set_handle(IO_PROC_STDOUT, fh_ptr);

1,095 Views
Teckna
Contributor V

Many thanks Martin for your answer.

Using the statement you suggested set the global handle, that is copied to the task private handle when the task is created: once the task is started, it uses the private handle (copied from the global handle) and modifying the global handle doesn't modify the private handle, so the task continues to work with the old handle.

Any suggestion?

Many thanks

Teckna

0 Kudos
1,095 Views
Martin_
NXP Employee
NXP Employee

Hi Teckna,

try to call that function from _bsp_enable_card() in your BSP. For example just before return. _bsp_enable_card() is called during MQX startup (_mqx() function) before application/idle tasks are created.

0 Kudos
1,095 Views
Teckna
Contributor V


Hi Martin,

I need to switch the handle in runtime, during the normal work, not only at the startup time.

Is there a way to do this?

Many thanks

Teckna

0 Kudos
1,095 Views
Martin_
NXP Employee
NXP Employee

MQX printf() sends characters to a file returned by _io_get_handle(IO_STDOUT).

If we look into _io_get_handle() source code we will see

  

case IO_STDOUT:          return kernel_data->ACTIVE_PTR->STDOUT_STREAM;

so return value depends on the task specific data (active task). With this you can see that each task can have its own IO_STDOUT file.

For your specific application purposes you can customize your _io_get_handle() function to return for example

 

case IO_STDOUT:          return kernel_data->PROCESSOR_STDOUT;

that is one global handle across all tasks.

0 Kudos
1,095 Views
Teckna
Contributor V

Thanks for you suggestion, Martin

This can work, I will have to remeber to modify the library when I will update MQX...

For future MQX releases, it can be useful to implement a mechanism to do this work.

Many thanks

Teckna

0 Kudos
1,095 Views
c0170
Senior Contributor III

Hello Robert Lewis,

please check IO Debug (chapter 23) in IO MQX guide, There's example to redirect standard output using _io_set_handle function. I'll paste it here:

FILE_PTR fh_ptr;

if(NULL == (fh_ptr = fopen("iodebug:", NULL))) {

printf("Cannot open the debug output\n");

} else {

_io_set_handle(IO_STDOUT, fh_ptr);

printf("This is printed to the debug output\n");

}

fflush(stdout);

if (fh_ptr != NULL) {

fclose(fh_ptr);

}


Taken from comments which are above the function _io_set_handle:

*This function changes the address of a default I/O handle, and returns
*the previous one.  If an incorrect type is given, or the I/O handle was
*uninitialized, 0 is returned.


Function io_set_handle is located in source/io/io_shand.c.

Regards,

c0170