Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial doesn't work for mbed framework #122

Closed
ivankravets opened this issue Mar 13, 2015 · 5 comments
Closed

Serial doesn't work for mbed framework #122

ivankravets opened this issue Mar 13, 2015 · 5 comments
Labels
Milestone

Comments

@ivankravets
Copy link
Member

Example

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx

int main() {
    pc.printf("Hello World!\n\r");
    while(1) {
        pc.putc(pc.getc() + 1); // echo input back to terminal
    }
}
(develop)➜  mbed-blink git:(develop) ✗ platformio run -e nucleo_f401re -t upload
[Fri Mar 13 23:04:44 2015] Processing nucleo_f401re (platform: ststm32, board: nucleo_f401re, framework: mbed)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
arm-none-eabi-g++ -o .pioenvs/nucleo_f401re/src/main.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthumb -Wno-missing-field-initializers -c -fno-builtin -O2 -mfpu=fpv4-sp-d16 -fomit-frame-pointer -Wall -mfloat-abi=softfp -MMD -mcpu=cortex-m4 -DTARGET_NUCLEO_F401RE -DTARGET_M4 -DTARGET_CORTEX_M -DTARGET_STM -DTARGET_STM32F4 -DTARGET_STM32F401RE -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M4 -DARM_MATH_CM4 -D__FPU_PRESENT=1 -DMBED_BUILD_TIMESTAMP=1426262453.27 -D__MBED__=1 -DTARGET_FF_ARDUINO -DTARGET_FF_MORPHO -DPLATFORMIO=010200 -I.pioenvs/nucleo_f401re/FrameworkMbedInc248832578 -I.pioenvs/nucleo_f401re/FrameworkMbedInc-213564679 -I.pioenvs/nucleo_f401re/FrameworkMbedInc-250686161 -I.pioenvs/nucleo_f401re/FrameworkMbedInc1266984661 -I.pioenvs/nucleo_f401re/FrameworkMbedInc2097404638 -I.pioenvs/nucleo_f401re/FrameworkMbedInc-1116590620 -I.pioenvs/nucleo_f401re/FrameworkMbedInc170856846 -I.pioenvs/nucleo_f401re/FrameworkMbedInc175333816 .pioenvs/nucleo_f401re/src/main.cpp
arm-none-eabi-ar rcs .pioenvs/nucleo_f401re/libFrameworkMbed.a @/var/folders/nj/nt38kxwd2xxfl5l42np_w7qw0000gn/T/pioarargs-f8d149b23e80c5a2dfe687bd465da31f
arm-none-eabi-ranlib .pioenvs/nucleo_f401re/libFrameworkMbed.a
arm-none-eabi-g++ -o .pioenvs/nucleo_f401re/firmware.elf -Wl,--gc-sections -Wl,--wrap,main -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp --specs=nano.specs -T /Users/ikravets/.platformio/packages/framework-mbed/variant/NUCLEO_F401RE/mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM/STM32F401XE.ld .pioenvs/nucleo_f401re/src/main.o -L/Users/ikravets/.platformio/packages/framework-mbed/variant/NUCLEO_F401RE/mbed/TARGET_NUCLEO_F401RE/TOOLCHAIN_GCC_ARM -L.pioenvs/nucleo_f401re -Wl,--start-group -lc -lgcc -lm -lmbed -lstdc++ -lsupc++ -lnosys .pioenvs/nucleo_f401re/libFrameworkMbed.a -Wl,--end-group
.pioenvs/nucleo_f401re/libFrameworkMbed.a(retarget.o): In function `__gnu_cxx::__verbose_terminate_handler()':
retarget.cpp:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x0): multiple definition of `__gnu_cxx::__verbose_terminate_handler()'
/Users/ikravets/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7e-m/softfp/libstdc++_s.a(vterminate.o):vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x0): first defined here
/Users/ikravets/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc_s.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
/Users/ikravets/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/lib/armv7e-m/softfp/libc_s.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
collect2: error: ld returned 1 exit status
scons: *** [.pioenvs/nucleo_f401re/firmware.elf] Error 1
================================================================= [ ERROR ] Took 1.35 seconds =================================================================
@hoosierEE
Copy link

hoosierEE commented May 26, 2016

I should note that I only #include <functional> for its std::function but in my application a function pointer works just as well, so it's not a showstopper for me.

I came here searching for _getpid because I have a similar error, but my code is totally different:

Here's the source code:

// project/src/main.cpp
#include <Arduino.h>
#include <functional>

void method(std::function<int (int)>reader){
    reader(3);// read pin 3
}

void setup(){}
void loop(){
    method(touchRead);
}

Here's the platformio configuration:

# project/project.ini
[env:teensylc]
platform = teensy
framework = arduino
board = teensylc

Here's the error:

$ platformio run
[Thu May 26 13:47:49 2016] Processing teensylc (platform: teensy, board: teensylc, framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------
arm-none-eabi-g++ -o .pioenvs/teensylc/firmware.elf -Os -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m0plus -Wl,--defsym=__rtc_localtime=1
464284869 -fsingle-precision-constant --specs=nano.specs -Wl,-T"mkl26z64.ld" .pioenvs/teensylc/src/main.o -L/Users/lx/.platformio/packages/l
dscripts -L.pioenvs/teensylc -Wl,--start-group -larm_cortexM0l_math .pioenvs/teensylc/libFrameworkArduino.a -lc -lgcc -lm -Wl,--end-group  
/Users/lx/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv6-m/libc_s.a(li
b_a-signalr.o): In function `_kill_r':                                                                                                     
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
/Users/lx/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv6-m/libc_s.a(li
b_a-signalr.o): In function `_getpid_r':                                                                                                   
signalr.c:(.text._getpid_r+0x2): undefined reference to `_getpid'
collect2: error: ld returned 1 exit status
scons: *** [.pioenvs/teensylc/firmware.elf] Error 1
======================================================= [ ERROR ] Took 0.51 seconds =======================================================

@valeros
Copy link
Member

valeros commented May 27, 2016

Hi @hoosierEE !
Does your code compile without error in Teensyduino?

@hoosierEE
Copy link

Hi @valeros no, it complains that it can't find functional, which is expected since it's a C++ standard library and not included in the Arduino toolchain.

@valeros
Copy link
Member

valeros commented May 27, 2016

Hmm, could you please add these stubs to your code? Does it work?

extern "C"{
  int _getpid(){ return -1;}
  int _kill(int pid, int sig){ return -1; }
  int _write(){return -1;}
}

@hoosierEE
Copy link

hoosierEE commented Jun 7, 2016

Hi @valeros it does work when I add those stubs, thanks!

Here is my modified example:

// project/src/main.cpp
#include <Arduino.h>
#include <functional>

extern "C"{
    int _getpid(){ return -1;}
    int _kill(int pid, int sig){ return -1; }
    int _write(){return -1;}
}

void method(std::function<int (int)>reader){
    reader(3);// read pin 3
}

void setup(){}
void loop(){
    method(touchRead);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants