me-no-dev / RasPiArduino

Arduino Framework for RaspberryPI
333 stars 75 forks source link

Not compatible with CM4 / Ubuntu 20.04 #119

Open muawijhe opened 3 years ago

muawijhe commented 3 years ago

Hi!

First of all, very good job! I was looking into the web to find a compatibility layer to use arduino-libraries (far more popular than pi) on the CM4 module.

Let me explain the underlying idea I tried to setup based on your repo:

a) I mostly work with ROS2 in advanced robotics applications, where processes are normally multi-thread and heavily network based; b) the arduino libraries are very popular, and it will be time-efficient to import some of them into raspberry pi C++ code;

now, you enter into the point (b - hopefully), but in order to use the basic arduino functionality (that is heavily used by sensor libraries, for example SPI, I2C etc...), I need to separate the library part from the runnable part, which is the main function using setup/loop classical arduino scheme.

This is what I did:

SOURCES  += $$files(../dep/RasPiArduino/cores/piduino/wiring*.c, true)

# Utility functions
SOURCES  += ../dep/RasPiArduino/cores/piduino/raspberry_pi_revision.c
SOURCES  += ../dep/RasPiArduino/cores/piduino/stdlib_noniso.cpp
SOURCES  += ../dep/RasPiArduino/cores/piduino/idemonitor.c
SOURCES  += ../dep/RasPiArduino/cores/piduino/piconsole.c
SOURCES  += ../dep/RasPiArduino/cores/piduino/cbuf.cpp

# Strings and basic hardware serial support
SOURCES  += ../dep/RasPiArduino/cores/piduino/WString.cpp
SOURCES  += ../dep/RasPiArduino/cores/piduino/HardwareSerial.cpp
SOURCES  += ../dep/RasPiArduino/cores/piduino/Print.cpp

# Header files
HEADERS  += $$files(../dep/RasPiArduino/cores/piduino/Arduino.h, true)

# Libraries
SOURCES  += $$files(../dep/RasPiArduino/libraries/SPI/*.cpp, true)
SOURCES  += $$files(../dep/RasPiArduino/libraries/Wire/*.cpp, true)
SOURCES  += $$files(../dep/RasPiArduino/libraries/TTY/*.cpp, true)

Then I also built a secondary library to handle Arduino-like Runner (main function) in order to use the existing libraries (such as SPI, Wire etc.. also without the regular setup/loop scheme)

Then I got the standard blink file and i modified it, replacing the definition for the standard led with:

#include <Arduino.h>

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(PWM00, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PWM00, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(PWM00, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

I linked the blink file with the two libraries.

Everything compiles fines (although there are a large number of warning - i am allergic to warnings), but unfortunately, this is what I got after run:

UNKNOWN_REVISION: 0x00D03140, MODEL: 0xFFFFFFFF

Are you planning to support CM4, and if so when? Do you need help for testing on such a platform?