How to use printf in NHS3100 project?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to use printf in NHS3100 project?

ソリューションへジャンプ
1,833件の閲覧回数
aresmarser
Contributor III
Hi Sir,
I read "LPCXpresso_IDE_User_Guide.pdf" which talks about printf as below:
---------------------------
Semihosting C Project
• Creates a simple “Hello World” project, with the main() routine containing a printf() call, which will cause the text to be displayed within the Console View of the LPCXpresso IDE. This is implemented using “semihosting” functionality. For more details, please see the FAQ at
http://www.lpcware.com/content/faq/lpcxpresso/using-printf
---------------------------
But when I click the link above, the content is NOT available and it is linked to another web address "https://www.nxp.com/products/processors-and-microcontrollers/arm-based-processors-and-mcus/lpc-corte...".
Could you advice how I can access the link "http://www.lpcware.com/content/faq/lpcxpresso/using-printf" for the content?
I want to use printf function to trace the routine but I met problem.
For example, I tried as below:
---
#include<stdio.h>
// ...
printf("LED Toggle\r\n");
--------------
But the compiling errors happened:
*******
12:43:23 **** Incremental Build of configuration Debug for project app_demo_dp_blinky ****
make -r all
Building file: ../src/mainblinky.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -std=c99 -DDEBUG -D__CODE_RED -DCORE_M0PLUS -D__REDLIB__ -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_chip_nss" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_board_dp" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\app_demo_dp_blinky\inc" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_board_dp\inc" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_chip_nss\inc" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\mods" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\app_demo_dp_blinky\mods" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_board_dp\mods" -I"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_chip_nss\mods" -include"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_chip_nss\mods\chip_sel.h" -include"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_board_dp\mods\board_sel.h" -include"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\app_demo_dp_blinky\mods\app_sel.h" -O0 -g3 -pedantic -Wall -Wextra -Wconversion -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m0plus -mthumb -D__REDLIB__ -specs=redlib.specs -MMD -MP -MF"src/mainblinky.d" -MT"src/mainblinky.o" -MT"src/mainblinky.d" -o "src/mainblinky.o" "../src/mainblinky.c"
Finished building: ../src/mainblinky.c
 
Building target: app_demo_dp_blinky.axf
Invoking: MCU Linker
arm-none-eabi-gcc -nostdlib -L"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_board_dp\Debug" -L"C:\Users\Bitse\Documents\LPCXpresso_8.1.4_606\workspace\lib_chip_nss\Debug" -Xlinker -Map="app_demo_dp_blinky.map" -Xlinker --gc-sections -mcpu=cortex-m0plus -mthumb -T "app_demo_dp_blinky_Debug.ld" -o "app_demo_dp_blinky.axf"  ./src/crp.o ./src/mainblinky.o   -llib_board_dp -llib_chip_nss
c:/nxp/lpcxpresso_8.1.4_606/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(fpprintf.o): In function `printf':
fpprintf.c:(.text.printf+0x38): undefined reference to `__sys_write'
c:/nxp/lpcxpresso_8.1.4_606/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(_deferredlazyseek.o): In function `__flsbuf':
_deferredlazyseek.c:(.text.__flsbuf+0x88): undefined reference to `__sys_istty'
c:/nxp/lpcxpresso_8.1.4_606/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(_writebuf.o): In function `_Cwritebuf':
_writebuf.c:(.text._Cwritebuf+0x16): undefined reference to `__sys_flen'
_writebuf.c:(.text._Cwritebuf+0x26): undefined reference to `__sys_seek'
_writebuf.c:(.text._Cwritebuf+0x3c): undefined reference to `__sys_write'
c:/nxp/lpcxpresso_8.1.4_606/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(alloc.o): In function `_Csys_alloc':
alloc.c:(.text._Csys_alloc+0xe): undefined reference to `__sys_write'
alloc.c:(.text._Csys_alloc+0x12): undefined reference to `__sys_appexit'
c:/nxp/lpcxpresso_8.1.4_606/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv6-m\libcr_c.a(fseek.o): In function `fseek':
fseek.c:(.text.fseek+0x18): undefined reference to `__sys_istty'
fseek.c:(.text.fseek+0x3c): undefined reference to `__sys_flen'
collect2.exe: error: ld returned 1 exit status
make: *** [app_demo_dp_blinky.axf] Error 1
12:43:24 Build Finished (took 856ms)
***************
Sorry I am a new comer for NXP NHS3100 and LPCXpresso development.
Look forward to your guide.
Many thanks,
Arna
タグ(2)
1 解決策
1,527件の閲覧回数
driesmoors
NXP Employee
NXP Employee

Hi,

It looks like you forgot to change the library setting. Under the LPCXpresso IDE, check:

Project > Properties > C/C++ Build > Settings > Tool Settings > MCU Linker > Managed Linker script > Library

That should be set to Redlib (semihost). Take care to change it for the correct (and all) build configurations (listed on top). 

Also take into account that using semihost carries some disadvantages:

  • Firmware image size increases by ~10K
  • Using a printf statement is very slow: the ARM will halt, waiting for the PC to read out the string output by printf. Only after that execution continues.
  • This also means that you must at all times have a physical connection. Without the SWD cable, the IC will halt and stay there perpetually
  • Plus, you can't use it in combination with the low power mode "Deep Power down", or go to Power-off.

We recommend using the uarttx module to insert traces in a more unobtrusive way. That said, using semihosting still remains an easy way to try out the different functionalities the chip can offer.

Kind regards,
Dries.

元の投稿で解決策を見る

3 返答(返信)
1,528件の閲覧回数
driesmoors
NXP Employee
NXP Employee

Hi,

It looks like you forgot to change the library setting. Under the LPCXpresso IDE, check:

Project > Properties > C/C++ Build > Settings > Tool Settings > MCU Linker > Managed Linker script > Library

That should be set to Redlib (semihost). Take care to change it for the correct (and all) build configurations (listed on top). 

Also take into account that using semihost carries some disadvantages:

  • Firmware image size increases by ~10K
  • Using a printf statement is very slow: the ARM will halt, waiting for the PC to read out the string output by printf. Only after that execution continues.
  • This also means that you must at all times have a physical connection. Without the SWD cable, the IC will halt and stay there perpetually
  • Plus, you can't use it in combination with the low power mode "Deep Power down", or go to Power-off.

We recommend using the uarttx module to insert traces in a more unobtrusive way. That said, using semihosting still remains an easy way to try out the different functionalities the chip can offer.

Kind regards,
Dries.

1,527件の閲覧回数
aresmarser
Contributor III

Hi Dries,

Thank you so much for the answer.

I can now use printf.

BTW, as you suggestion, "We recommend using the uarttx module to insert traces in a more unobtrusive way".

Could you advice some document or guide to how to add trace log in my project?

Thanks a lot,

Arna

0 件の賞賛
返信
1,527件の閲覧回数
driesmoors
NXP Employee
NXP Employee

Hi,

Have a look at the doxygen generated documentation about this: docs/FirmwareDevelopmentDocumentation/index.html, then from the left pane Modules > Modules (weird, I know) > uarttx: Uart Tx-only module.

Best,
Dries.

0 件の賞賛
返信