This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

cannot retarget getchar/read/getch

I'm using SDK 15.0 on an nRF52840 dongle. I've been able to retarget the output functions (outputting through the CDC UART) but so far I can't seem to use getchar() in my higher level code and have it correctly hook into the received data stream from the PC.

I've tried retargeting fgetc, _read and __getchar() -- my code builds and there are no linker errors, but when my higher level code calls getchar() it looks like it's getting lost in some binary library -- there is no reference to getchar() in the SDK 15 source code, yet the function that is being executed is not my getchar() code.


I understand that I do not need to retarget and can simply call the usb_read() function, but the entire point of retargeting is to avoid having to change the higher level code. I have successfully retargeted for output to UART, USB and even CAN on other architectures, but it seems there is a specific bug in the Nordic SDK when it comes to being able to retarget the input functions.

Is there a working example of getch/getchar/fgetc/read retargeting with SDK15?

Parents
  • Hi Andrew

    Which IDE/compiler are you using?

    getchar() should be implemented in the retarget file, but I don't think any of our examples use it. 

    Best regards
    Torbjørn

  • No IDE, just gcc and a Makefile.

    im not sure I made the issue clear. getchar() is present in the binary. Something has implemented it, and it’s not calling any of the normal retargeted functions (__getchar, _read, _fgetc, etc.). The getchar implementation appears to be in one of the binary-only libraries in SDK15.0, as grepping the entire source tree reveals nothing useful. 

    Because of this, I can’t call getchar() I my high level code and have it actually pull data from my data source. stdio works (fgetc, etc) but I’m trying to understand the getchar issue. 

  • Hi Andrew

    Is your project based on one of the existing SDK examples?

    If yes, which one?

    The map file should show which module implements the getchar() function, even if the source code does not. Could you have a look there, or share it with me?

    Best regards
    Torbjørn

  • (man this "new" devzone is a terrible, terrible website. It's sacrificing actual usability for glitz and flashy UI!)

    My code is not based off of anything, I just copied the retarget.c from an old project long, long ago and have been modifying and using it on several ARM systems, not just Nordic.

    The .map file shows that getchar() is implemneted in libc.a (arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a) -- perhaps this has nothing to do with Nordic's SDK at all and everything to do with a bad implementation in libc which ships with gcc-arm-none-eabi-7-2018-q2-update.

Reply
  • (man this "new" devzone is a terrible, terrible website. It's sacrificing actual usability for glitz and flashy UI!)

    My code is not based off of anything, I just copied the retarget.c from an old project long, long ago and have been modifying and using it on several ARM systems, not just Nordic.

    The .map file shows that getchar() is implemneted in libc.a (arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a) -- perhaps this has nothing to do with Nordic's SDK at all and everything to do with a bad implementation in libc which ships with gcc-arm-none-eabi-7-2018-q2-update.

Children
Related