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

Trying to run on Arduino Giga R1 #41

Open
startOfStars opened this issue Aug 7, 2023 · 21 comments
Open

Trying to run on Arduino Giga R1 #41

startOfStars opened this issue Aug 7, 2023 · 21 comments

Comments

@startOfStars
Copy link

Hi everybody,

I'm trying to run "LoopBackDemoArduinoUnoNoInt" example on Arduino Giga R1 (I was able to run the ACAN2517FD library on Rapsberry Pico).

Each time I open the Serial Monitor the sketch freezes just after "MCP2517FD RAM Usage: 2016 bytes" (Arduino Giga R1 red led lights up).

It seems that sketch freezes on line : "const uint32_t errorCode = can.begin (settings, NULL)"

Is there a chance that ACAN2517FD works on Arduino Giga R1 or shall I stop my tests ?

Thanks !
(and thanks again to Pierre for this library !)

@pierremolinaro
Copy link
Owner

pierremolinaro commented Aug 7, 2023 via email

@startOfStars
Copy link
Author

startOfStars commented Aug 8, 2023

Hi Pierre

Thank you for your quick answer.

I took care about what you said, no problem on that.

"The library should run on any microcontroller that has a SPI" => that's what I was thinking about, so I don't understand why I do not find the way to run on Giga...

I use your library since severall months that's why I'm aware about what I have to be carrefull about (int / on int / Hz quartz frequency and so one).

Since yesterday I made severall tests.

I don't understand, I double checked my connections, also tried with Mikroe Click : ok on Uno and Raspberry Pico but fail with Giga... Also tried others examples with INTERRUPT, same issue.

The programm always crashes at const uint32_t errorCode = can.begin (settings, NULL)

I'm pretty sure there is a problem with SPI connection but I don't understand why. I'm running Ethernet Shield on Giga with SPI connection on others projects with success.

Shall I tried adjustements on mSPISettings = SPISettings (800UL * 1000, MSBFIRST, SPI_MODE0) ; ?

Best regards and thanks !

@startOfStars
Copy link
Author

After more investigations, I found that calls of noInterrupts () and interrupts () in ACAN2517FD.cpp causes Arduino Giga R1 crashs.
When commenting these parts of sketch, the sketch runs well.

Arduino Giga R1 is supposed to be compatible with these inetrrupt functions.

I don't find what I'm missing.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Aug 10, 2023 via email

@startOfStars
Copy link
Author

In file ACAN2517FD.cpp, all parts as :
#ifdef ARDUINO_ARCH_ESP32 taskDISABLE_INTERRUPTS () ; #else noInterrupts () ; #endif
and
#ifdef ARDUINO_ARCH_ESP32 taskENABLE_INTERRUPTS () ; #else interrupts () ; #endif
Thanks!

@startOfStars
Copy link
Author

startOfStars commented Aug 12, 2023

To be more precised I made search/replace in ACAN2517FD.cpp:
noInterrupts () ; = > delay(0); // noInterrupts () ;

and then :

interrupts () ; => delay(0); // interrupts () ;

Just retried:

  • if not modified => OS crash
  • if modified as above => success (CAN messages well sent)

@pierremolinaro
Copy link
Owner

pierremolinaro commented Aug 14, 2023 via email

@startOfStars
Copy link
Author

startOfStars commented Aug 16, 2023

Hi

I'm motivated to make this amazing library to work on Arduino Giga R1 🙂

So to resume :

After more investigations I found that this is noInterrupts () function only that causes crash. When I comment only this one (leaving interrupts () ; ) it works. So this is noInterrupts () that causes crash.

How shall I continue my investigations ? How noInterrupts () could make mbed crashes in this library ?

Thanks !

@pierremolinaro
Copy link
Owner

pierremolinaro commented Aug 18, 2023 via email

@startOfStars
Copy link
Author

startOfStars commented Aug 28, 2023

Hi Pierre

Unfortunatly, new try of the library with attach interrupt order updated does not solve the issue...

I made an other test :

  1. First I replaced all noInterrupts() by delay(0) in ACAN2517FD.cpp filte => success
  2. I added two Serial.print like this in begin method :

` //----------------------------------- Reset MCP2517FD (always use a 800 kHz clock)

Serial.println("before reset");

reset2517FD () ;

Serial.println("after reset");`

I checked, "before reset" and "after reset" are well printed.

  1. I put back noInterrupts() in reset2517FD :
    `void ACAN2517FD::reset2517FD (void) {

mSPI.beginTransaction (mSPISettings) ; // Check RESET is performed with 800 kHz clock

#ifdef ARDUINO_ARCH_ESP32

  taskDISABLE_INTERRUPTS () ;
  
#else

  noInterrupts () ; // <=======================
  
#endif

  assertCS () ;
  
    mSPI.transfer16 (0x00) ; // Reset instruction: 0x0000
    
  deassertCS () ;
  
#ifdef ARDUINO_ARCH_ESP32

  taskENABLE_INTERRUPTS () ;
  
#else

  interrupts () ;
  
#endif

mSPI.endTransaction () ;

}`

=> Crash

So it's sure the issue is due to noInterrupts()

  1. I ran a very simple sketch on Giga :
    `void setup() {}

void loop() {
noInterrupts();
// critical, time-sensitive code here
interrupts();
// other code here
}`

=> no problem

I don't understand.

Thanks!

@emagnetto
Copy link

Hi! TEsting also on Giga R1. Same issue as mentioned here. Under analysis now.
@startOfStars what CAN controller are you using? MCP2518FD ? Purchased MCP251863 so as to start my tests.

Are you also trying work on FDCAN Giga native ports?

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 17, 2024 via email

@emagnetto
Copy link

Pierre, thank's for your response.
The Giga is an interesting board, specially whenever you want to be close to a Mega layout.
I received it a couple of weeks ago. I agree, a little bit expensive ...
I think the issue has to do with the mbed layer, but had no time to work on the issue yet.

About MCP251863 and MCP2518FD. I know both. I studied a them before purchasing. In fact, I bought the former (a nice CLICK board from MIKRO, easy to connect to any Arduino), as costs almost half than the latter (with same transiever). Still waiting for them ... will arrive in a couple of days.

I'm designing a custom system for flight simulators instruments and commands, based on a "powerfull" master node (by now, a GIGA, but may be other STM32, depending on my future complete requirements), and several satellite, slave nodes (RP2040, and perhaps others), with FDCAN for connectivity.

I started analyzing acanfd_stm32 last week. Although MCU is similar on Giga, lib is not compatible, as you said.
On the other hand, I was not able to find any FDCAN library for Giga nor Portenta ...
Hence, I'm still on moving sands ... trying to fix hw or sw decisions and start from there.
That's why I reached your libraries! They will give me a common ground to start from.

In fact, I also need a higher level protocol (like CANOpen), although it will be an overkill for my needs.
Thinking on implementing just a simplified subset.

@pierremolinaro
Copy link
Owner

pierremolinaro commented Feb 24, 2024 via email

@emagnetto
Copy link

Wow! I'll wait for your outcome. Not sure how complex it can be. Although it has an STM32 mcu, whole "arduino" and mbed stuff may impose some difficulties.
Today I received some CAN controllers, so can start playing with it. Will also analyze the crash.

I've been studying CANOpen for a couple of weeks on my spare time, trying to get a higher level layer.
Many web sources and doc. But hard to turn to real working code.
https://github.com/CANopenNode/CANopenNode has a nice starting point, although not FD compatible.
My goal: a (sort of) CANOpen FD implementation on top of ACAN2517FD and ACANFD_STM32

@emagnetto
Copy link

emagnetto commented Mar 1, 2024

Just an insight on the nointerrupt() issue.

Made additional tests, like @startOfStars on Aug, 28th , on reset2517FD().
The issue seems to be on SPI transfers (mSPI.transfer16 (0x00) ; ) whenever noInterrupts() has been called.
Hence, tested code below.
It crashes with red blinking led. (mbed crash)
Simple test to reproduce ...

`

#include <SPI.h>
const int CS_1 = 7;
void setup() {
pinMode(CS_1, OUTPUT);
Serial.println(" START");

SPI.begin();
digitalWrite(CS_1, LOW);
noInterrupts();
SPI.transfer(0x00);
interrupts();
digitalWrite(CS_1, HIGH);

Serial.println(" END");

}

`

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 2, 2024 via email

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 2, 2024 via email

@emagnetto
Copy link

Hi! I did same analysis about GIGA and MBED.
In fact, already made some changes to support GIGA, in line with what you proposed, as an initial testbed.

Anyway, the second approach is smarter. In fact yesterday I downloaded the STM32H747 Ref Manual (more than 3000 pages!) and looked at FDCAN specs and analyzed a little bit ACANFD_STM32 code.
Now that I know where to look, it´s not so scary as initially thought ... Your code is modular and very neat. And as you mentioned before, Portenta and Giga shares a very similar MCU as one of the NUCLEO (H743ZI2) you developed for ... In fact, checking both Ref Manuals, FDCAN implementation seems to be the same.
It´s great you have already running on loop!

By the way, I was studing a little bit Saleae products (I want to purchase a Logoc Analyzer), and found you developed an FDCAN plugin for it!

@pierremolinaro
Copy link
Owner

pierremolinaro commented Mar 3, 2024 via email

@emagnetto
Copy link

emagnetto commented Mar 3, 2024

Pierre, thanks for this great package! I´ll test it tomorrow.
I´m ending my vacations (I took time from it to start studying CAN ... My wife was not happy), and had not enough time yet to go deeper on coding and testing.
What I will also test tomorrow is this code (acan2517FD) and my new hardware with Pi Pico (RP2040).
Also analyzed two CANOpen codes (Easy-CANOpen and CANOpenNode), so as to build this protocol (or part of it) on top of your CAN libs. Easy-CANOpen seems to be easier to adapt. I´m not sure how much time I will have now that I´m back to work ... But will let you know the results, and of course, if I have any issue or suggestions, will open an issue!

Eduardo

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

No branches or pull requests

3 participants