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
Solved! Go to Solution.
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.
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.
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:
Thank you for helping
Regards
Robert
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
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
try _io_set_handle(IO_PROC_STDOUT, fh_ptr);
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
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.
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
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.
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
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