Redirecting printf to anywhere I want it to go.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
EdHa_4455331
Level 5
Level 5
25 replies posted 25 sign-ins 10 replies posted

I am working on a project that uses a CYBLE-416045 module. This particular module only brings out a relatively small number of I/O pins, and the system design has used them all up (plus needing an I/O expander IC). I do not have room to place a UART to use as the console port for printf(). But I really really want to be able to have a console output for when we are doing characterization and calibration of the sensors in the system. I have two solutions I can use:

1) I found a UART IC that I can hang on the I2C bus and could use it as the UART that would go to an external PC.

2) I can sometimes also redirect the output to the LCD that is in my system.

Now, if I understand the overall system correctly, this should be relatively easy to implement (or at least straight forward). All I have to do is replace the _write function in retarget.c with functions that would understand my system's hardware and send the input string to where ever I want it to go - through the I2C bus to the UART IC or to the LCD.

My first question is - Am I correct so far?

There is one other point I need to check on. Right now, retarget.c is down in the Generated_Source section of the project. I could modify the code in retarget.c itself, but that code would get wiped out by a clean/generate operation. So, do I move a copy of retarget.c from the Generated_Source to my source code folder and then modify it there? But if I do that, how do I prevent the build process from finding multiple definitions for _write()?

Thanks,

Ed H.

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Ed H.-san,

Very good question!

I should have thought of that, too.

> My first question is - Am I correct so far?

I think so.

But I have not tried it with other hardware, yet.

In my sample/memo below, I also dug a little (please refer to the case 3).

And I found that _write() was weak link,

if you write "_write()" function in your project,

it should have the precedence.

So you don't have to touch the generated code.

printf and float rhapsody (aka, yet another printf and floating topic)

Please teach us your result!

Best Regards,

18-Apr-2020

Motoo Tanaka

View solution in original post

0 Likes
1 Reply
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Ed H.-san,

Very good question!

I should have thought of that, too.

> My first question is - Am I correct so far?

I think so.

But I have not tried it with other hardware, yet.

In my sample/memo below, I also dug a little (please refer to the case 3).

And I found that _write() was weak link,

if you write "_write()" function in your project,

it should have the precedence.

So you don't have to touch the generated code.

printf and float rhapsody (aka, yet another printf and floating topic)

Please teach us your result!

Best Regards,

18-Apr-2020

Motoo Tanaka

0 Likes