nigelb / platform-apollo3blue

AmbiqMicro Apollo 3 Blue: development platform for PlatformIO
Apache License 2.0
30 stars 13 forks source link

undefined reference to `_kill' & `_getpid' #25

Closed sentientthings closed 2 years ago

sentientthings commented 3 years ago

When I compile SPI example: https://github.com/sparkfun/Arduino_Apollo3/blob/main/libraries/Apollo3/examples/Example6_SPI/Example6_SPI.ino

#include <Arduino.h>
#include "SPI.h"

// define SPI settings at which to test
#define SPI_FREQ 10000000
#define SPI_MODE SPI_MODE3
#define SPI_ORDER MSBFIRST
#define CS_PIN 0

#define SERIAL_PORT Serial

// define pins to create a custom SPI port
// using mbed PinNames or Arduino pin numbers
// (must be all pins from one IOM module)
//#define mySDI D25
//#define mySDO D28
//#define myCLK D27
#if (defined mySDI) && (defined mySDO) && (defined myCLK)
MbedSPI mySPI(mySDI, mySDO, myCLK); // declare the custom MbedSPI object mySPI
extern "C" SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk); // this mbed internal function determines the IOM module number for a set of pins
#endif

// define a macro to aid testing
#define TEST_SPI_PORT(P)  SERIAL_PORT.printf("testing %s\n\ttime (ms): %d\n\tbyte transer: %s\n\tbuffer transfer: %s\n\n", #P, millis(), ((test_byte_transfer(P) == 0) ? "pass" : "fail"), ((test_buffer_transfer(P) == 0) ? "pass" : "fail"))

int test_byte_transfer( SPIClass &spi  ){
  uint8_t tx = random(1, 256);
  uint8_t rx = 0x00;
  spi.beginTransaction(SPISettings(SPI_FREQ, SPI_ORDER, SPI_MODE));
  rx = spi.transfer(tx);
  spi.endTransaction();
  if(rx != tx){
    return -1;
  }
  return 0;
}

int test_buffer_transfer( SPIClass &spi ){
  const size_t len = 10;
  uint8_t tx_buff[len];
  uint8_t mirror[len];
  for(size_t idx = 0; idx < len; idx++){
    tx_buff[idx] = random(1, 256);
    mirror[idx] = tx_buff[idx];
  }
  spi.beginTransaction(SPISettings(SPI_FREQ, SPI_ORDER, SPI_MODE));
  spi.transfer(tx_buff, len);
  spi.endTransaction();
  bool mismatched = false;
  for(size_t idx = 0; idx < len; idx++){
    if(tx_buff[idx] != mirror[idx]){
      mismatched = true;
    }
  }
  if(mismatched){
    return -1;
  }
  return 0;
}

void setup() {
  SERIAL_PORT.begin(115200);
  SERIAL_PORT.println("Apollo3 - Simple SPI");

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH);

  SPI.begin();

#if (defined mySDI) && (defined mySDO) && (defined myCLK)
  SERIAL_PORT.printf("starting mySPI on IOM %d\n", spi_get_peripheral_name(mySDO, mySDI, myCLK));
  mySPI.begin();
#endif
}

void loop() {
  Serial.println("test");
  TEST_SPI_PORT(SPI);

#if (defined mySDI) && (defined mySDO) && (defined myCLK)
  TEST_SPI_PORT(mySPI);
#endif

  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

I get the following error:

PS C:\Users\rober\Documents\PlatformIO\Projects\ArtemisSPITest> C:\Users\rober\.platformio\penv\Scripts\platformio.exe run --environment SparkFun_Thing_Plus -v
Processing SparkFun_Thing_Plus (platform: apollo3blue; board: SparkFun_Thing_Plus; framework: arduino; platform_packages: C:/Users/rober/.platformio/packages/framework-arduinoapollo3@2.1.0; monitor_speed: 115200; lib_extra_dirs: C:/Users/rober/.platformio/packages/framework-arduinoapollo3@2.1.0/libraries, lib)
-----------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/apollo3blue/SparkFun_Thing_Plus.html
PLATFORM: Apollo 3 Blue (0.0.2) > SparkFun Artemis Thing Plus
HARDWARE: AMA3B1KK 48MHz, 384KB RAM, 960KB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoapollo3 2.1.0
 - toolchain-gccarmnoneeabi 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 11 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPI> 2.0.0 (C:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\libraries\SPI)
Building in release mode
arm-none-eabi-g++ -o .pio\build\SparkFun_Thing_Plus\program.exe -TC:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\tools\uploaders\svl\0x10000.ld @C:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\variants\SFE_ARTEMIS_THING_PLUS\mbed\.ld-flags @C:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\variants\SFE_ARTEMIS_THING_PLUS\mbed\.ld-symbols -Wl,--whole-archive C:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\variants\SFE_ARTEMIS_THING_PLUS\mbed\libmbed-os.a -Wl,--no-whole-archive -Wl,-Map=C:\Users\rober\Documents\PlatformIO\Projects\ArtemisSPITest\.pio\build\SparkFun_Thing_Plus\program.map --specs=nano.specs .pio\build\SparkFun_Thing_Plus\src\main.cpp.o -L.pio\build\SparkFun_Thing_Plus -LC:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\variants\SFE_ARTEMIS_THING_PLUS\mbed -LC:\Users\rober\.platformio\packages\framework-arduinoapollo3@2.1.0\cores\mbed-os\targets\TARGET_Ambiq_Micro\TARGET_Apollo3\sdk\CMSIS\ARM\Lib\ARM -Wl,--start-group .pio\build\SparkFun_Thing_Plus\libb82\libSPI.a .pio\build\SparkFun_Thing_Plus\libvariant.a .pio\build\SparkFun_Thing_Plus\libmbed_bridge.a .pio\build\SparkFun_Thing_Plus\libcore-implement.a .pio\build\SparkFun_Thing_Plus\libEEPROM.a .pio\build\SparkFun_Thing_Plus\libPDM.a .pio\build\SparkFun_Thing_Plus\libRTC.a .pio\build\SparkFun_Thing_Plus\libServo.a .pio\build\SparkFun_Thing_Plus\libSoftwareSerial.a .pio\build\SparkFun_Thing_Plus\libSPI.a .pio\build\SparkFun_Thing_Plus\libWire.a .pio\build\SparkFun_Thing_Plus\libWDT.a .pio\build\SparkFun_Thing_Plus\libBurstMode.a -lstdc++ -lsupc++ -lmbed-os -larm_cortexM4lf_math -lm -Wl,--end-group
c:/users/rober/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/users/rober/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-signalr.o): in function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
c:/users/rober/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/users/rober/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-signalr.o): in function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\SparkFun_Thing_Plus\program.exe] Error 1
============================================================ [FAILED] Took 2.10 seconds ============================================================

It appears that functions _getpid and _kill are missing.

Adding the following into the code sample:

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

Fixes the issue.

I believe I followed the Readme correctly but it looks like my installation is missing something. I did have to add a lib_extra_dir path in my platformio.ini to enable some of the libs to be found:

;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:SparkFun_Thing_Plus]
platform = apollo3blue
board = SparkFun_Thing_Plus
framework = arduino
;platform_packages = framework-arduinoapollo3@2.1.0
platform_packages = C:/Users/rober/.platformio/packages/framework-arduinoapollo3@2.1.0
monitor_speed = 115200
lib_extra_dirs = 
    C:/Users/rober/.platformio/packages/framework-arduinoapollo3@2.1.0/libraries
    lib

Is this my particular installation that has an issue? Any ideas how to fix it?

nigelb commented 3 years ago

Hi @sentientthings, sorry for the delay in getting back to you.

I have the same issue when compiling the example code. Which is odd because one of my projects heavily uses SPI and has not run afoul of this bug.

Another workaround is to uncomment line 148 and to comment out line 149 of builder/frameworks/arduino/core_v2.py https://github.com/nigelb/platform-apollo3blue/blob/b936fa3f4d426236b4452aabc2ceb2909f14631f/builder/frameworks/arduino/core_v2.py#L148-L149

Like this older version :

https://github.com/nigelb/platform-apollo3blue/blob/9c00b14b474566e7f2679401042e3adbaefdfffd/builder/frameworks/arduino/core_v2.py#L149-L150

I will look into this and see if I can locate the source of this issue.

sentientthings commented 3 years ago

Hi @sentientthings, sorry for the delay in getting back to you.

I have the same issue when compiling the example code. Which is odd because one of my projects heavily uses SPI and has not run afoul of this bug.

Another workaround is to uncomment line 148 and to comment out line 149 of builder/frameworks/arduino/core_v2.py

https://github.com/nigelb/platform-apollo3blue/blob/b936fa3f4d426236b4452aabc2ceb2909f14631f/builder/frameworks/arduino/core_v2.py#L148-L149

Like this older version :

https://github.com/nigelb/platform-apollo3blue/blob/9c00b14b474566e7f2679401042e3adbaefdfffd/builder/frameworks/arduino/core_v2.py#L149-L150

I will look into this and see if I can locate the source of this issue.

Thank you

nigelb commented 3 years ago

Hi @sentientthings, I believe I have located the issue. It seems to be that this behavior exists in some versions of the compiler toolchain and not in others. I have modified the platform.json to select a version of the compiler that works on both Windows and Linux, though I don't have a way to test it on OSX.

Please update platform-apollo3blue and let me know how you go.

nigelb commented 3 years ago

Weirdly there is at least one (that I ran across) c++ standard library (it was either queue or map) that was causing this to happen to me even with the update compiler version. It also seems that other people have been having problems as well as SparkFun changed from --specs=nano.specs to --specs=nosys.specs here: https://github.com/sparkfun/Arduino_Apollo3/commit/8f1280a3f3c3e32ec50b285de2c8edcf26f66900. I updated this project to use --specs=nosys.specs by default and allowed it to be changed in one's platformio.ini file.