printf cannot work with MQX?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

printf cannot work with MQX?

3,017 次查看
zhangjay
Contributor II

Hi,

I have a KL25Z board in my hand, when I use the console component in code warrior, I can use "printf" function to print log with serial port into PC com port.

But when I add the MQXLite and write printf in my code, I cannot get message on my PC.

void Task1_task(uint32_t task_init_data) {

  int counter = 0;

  LDD_TDeviceData *blueLed = Bit1_Init(NULL);

  bool ledVal = 1;

  printf("count: %d\n", counter);

  while (1) {

  counter++;

  printf("count: %d\n", counter);

  ledVal = !ledVal;

  Bit1_PutVal(blueLed, ledVal);

  _time_delay_ticks(10);

  /* Write your code here ... */

  }

}

with these code, I can see my blue led blink, but I cannot get serial port message.

Why ?

Is there any where to set when using printf in MQX?

标记 (2)
0 项奖励
回复
6 回复数

1,795 次查看
abidesmail
Contributor II

Hi Martin and Zhang,

I have a very similar problem. I have a k20 processor expert project on codewarrior (10.6) with the terminal IO component set up for UART0. When I do a standard printf with no additional arguments, it prints fine, but when I printf with a variable I get a hard fault.

int testVal = 0;

testVal++;

printf("test \r\n"); //works fine

prinf("testval = %d \r\n", testVal); //causes a hard fault after it prints the value the first time

Thanks,

Abid.

0 项奖励
回复

1,795 次查看
DavidS
NXP Employee
NXP Employee

Hi Abid,

Are you using MQX or MQXLite?

If yes, please try increasing your stack size.

If no, please step into your printf and try to debug where it issue starts.

Regards,

David

0 项奖励
回复

1,795 次查看
abidesmail
Contributor II

Hi David,

I am using MQX lite. I tried changing the stack size from 512 bytes to 1024 bytes, but it didn't help.

I then tried to reduce the priority of the task (to the lowest priority of the whole system : 10) and it was worked - I was able to printf variables. Do you know if the terminal IO module is really slow or has a problem with MQX lite. Below is my task. As you can see, it is really simple:

testTaskCounter = 0;

void test_task(uint32_t task_init_data)

{

  while(1)

  {

       testTaskCounter++;

       printf("testTaskCounter %d \r\n", testTaskCounter);

       _time_delay_ticks(1000);

  }

}

Thanks,

Abid

0 项奖励
回复

1,795 次查看
DavidS
NXP Employee
NXP Employee

Hi Abid,

Can you ZIP and post your project?

Are you using the Console I/O Component?  If yes, there should be no slowness.

Regards,

David

0 项奖励
回复

1,795 次查看
Martin_
NXP Employee
NXP Employee

For MQX Lite, it is very easy. I refer to the tutorial on the link below:

http://mcuoneclipse.com/2013/02/07/tutorial-printf-with-and-without-processor-expert/


In CW 10.4, create New MQX-Lite project for KL25Z128 with I/O Support UART (default). Then add ConsoleIO component to the Processor Expert and configure Serial_LDD componet to use UART 0 on pins PTA1 and PTA2. Then I add printf("Hello World\n"); into my MQX Lite task, build, download, and I get the message on my Win7 terminal, on the Freedom board virtual COM port.

0 项奖励
回复

1,795 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

I was ever able to print to the console in MQX and CW10.2 by doing the following:

To be able to output printf to the console you need to open the psp for your board, locate file "fio.h" under PSP include and comment out

line 75: // #define  printf     _io_printf

then recompile the psp project as well as the bsp

0 项奖励
回复