Victor-Kalenda / LoRa_Library

Library implementation of Semtech's sx126x_driver for Arduino microcontrollers
Other
1 stars 0 forks source link

Compilation possible/recommended for ESP32? #1

Open imfatant opened 1 week ago

imfatant commented 1 week ago

Hi,

Compiled your code just fine using Arduino IDE set for Arduino R4 Wifi board.

However, when I tried setting board to ESP32 Dev Module (or other basic ESP32 boards), compilation failed. Is this worth pursuing, or perhaps I should look elsewhere? I'm getting to know the SX1262 better and I like the way you present the information in an accessible form.

Anyway, here's the output of compilation when attempted for ESP32:

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'void sx126x_hal_init(uint8_t, uint8_t, uint8_t, int8_t)':
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:15:20: error: 'OUTPUT' was not declared in this scope
   15 |   pinMode (cs_pin, OUTPUT);
      |                    ^~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:15:3: error: 'pinMode' was not declared in this scope
   15 |   pinMode (cs_pin, OUTPUT);
      |   ^~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:20:20: error: 'INPUT' was not declared in this scope
   20 |     pinMode (dio1, INPUT);
      |                    ^~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:23:22: error: 'INPUT' was not declared in this scope
   23 |   pinMode (busy_pin, INPUT);
      |                      ^~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:24:3: error: 'digitalWrite' was not declared in this scope
   24 |   digitalWrite(cs_pin,1);
      |   ^~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:27:3: error: 'Serial' was not declared in this scope
   27 |   Serial.println(F("HAL Initialized"));
      |   ^~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:27:18: error: 'F' was not declared in this scope
   27 |   Serial.println(F("HAL Initialized"));
      |                  ^
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_write(const void*, const uint8_t*, uint16_t, const uint8_t*, uint16_t)':
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:41:9: error: 'digitalRead' was not declared in this scope
   41 |   while(digitalRead(busy) == 1);
      |         ^~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:43:3: error: 'digitalWrite' was not declared in this scope
   43 |   digitalWrite(nss,0);
      |   ^~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:44:45: error: 'MSBFIRST' was not declared in this scope; did you mean 'SPI_MSBFIRST'?
   44 |   SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
      |                                             ^~~~~~~~
      |                                             SPI_MSBFIRST
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_read(const void*, const uint8_t*, uint16_t, uint8_t*, uint16_t)':
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:73:9: error: 'digitalRead' was not declared in this scope
   73 |   while(digitalRead(busy) == 1);
      |         ^~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:75:3: error: 'digitalWrite' was not declared in this scope
   75 |   digitalWrite(nss,0);
      |   ^~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:76:45: error: 'MSBFIRST' was not declared in this scope; did you mean 'SPI_MSBFIRST'?
   76 |   SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
      |                                             ^~~~~~~~
      |                                             SPI_MSBFIRST
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_reset(const void*)':
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:97:3: error: 'delayMicroseconds' was not declared in this scope
   97 |   delayMicroseconds( 10000 );
      |   ^~~~~~~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:98:3: error: 'digitalWrite' was not declared in this scope
   98 |   digitalWrite(reset,0);
      |   ^~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_wakeup(const void*)':
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:108:3: error: 'noInterrupts' was not declared in this scope
  108 |   noInterrupts();
      |   ^~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:110:3: error: 'digitalWrite' was not declared in this scope
  110 |   digitalWrite(nss,0);
      |   ^~~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:111:45: error: 'MSBFIRST' was not declared in this scope; did you mean 'SPI_MSBFIRST'?
  111 |   SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
      |                                             ^~~~~~~~
      |                                             SPI_MSBFIRST
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:122:9: error: 'digitalRead' was not declared in this scope
  122 |   while(digitalRead(busy) == 1);
      |         ^~~~~~~~~~~
c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:123:3: error: 'interrupts' was not declared in this scope
  123 |   interrupts();
      |   ^~~~~~~~~~

exit status 1

Compilation error: exit status 1
Victor-Kalenda commented 1 week ago

Hi,

Compiled your code just fine using Arduino IDE set for Arduino R4 Wifi board.

However, when I tried setting board to ESP32 Dev Module (or other basic ESP32 boards), compilation failed. Is this worth pursuing, or perhaps I should look elsewhere? I'm getting to know the SX1262 better and I like the way you present the information in an accessible form.

Anyway, here's the output of compilation when attempted for ESP32:


c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'void sx126x_hal_init(uint8_t, uint8_t, uint8_t, int8_t)':

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:15:20: error: 'OUTPUT' was not declared in this scope

   15 |   pinMode (cs_pin, OUTPUT);

      |                    ^~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:15:3: error: 'pinMode' was not declared in this scope

   15 |   pinMode (cs_pin, OUTPUT);

      |   ^~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:20:20: error: 'INPUT' was not declared in this scope

   20 |     pinMode (dio1, INPUT);

      |                    ^~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:23:22: error: 'INPUT' was not declared in this scope

   23 |   pinMode (busy_pin, INPUT);

      |                      ^~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:24:3: error: 'digitalWrite' was not declared in this scope

   24 |   digitalWrite(cs_pin,1);

      |   ^~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:27:3: error: 'Serial' was not declared in this scope

   27 |   Serial.println(F("HAL Initialized"));

      |   ^~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:27:18: error: 'F' was not declared in this scope

   27 |   Serial.println(F("HAL Initialized"));

      |                  ^

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_write(const void*, const uint8_t*, uint16_t, const uint8_t*, uint16_t)':

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:41:9: error: 'digitalRead' was not declared in this scope

   41 |   while(digitalRead(busy) == 1);

      |         ^~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:43:3: error: 'digitalWrite' was not declared in this scope

   43 |   digitalWrite(nss,0);

      |   ^~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:44:45: error: 'MSBFIRST' was not declared in this scope; did you mean 'SPI_MSBFIRST'?

   44 |   SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

      |                                             ^~~~~~~~

      |                                             SPI_MSBFIRST

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_read(const void*, const uint8_t*, uint16_t, uint8_t*, uint16_t)':

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:73:9: error: 'digitalRead' was not declared in this scope

   73 |   while(digitalRead(busy) == 1);

      |         ^~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:75:3: error: 'digitalWrite' was not declared in this scope

   75 |   digitalWrite(nss,0);

      |   ^~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:76:45: error: 'MSBFIRST' was not declared in this scope; did you mean 'SPI_MSBFIRST'?

   76 |   SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

      |                                             ^~~~~~~~

      |                                             SPI_MSBFIRST

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_reset(const void*)':

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:97:3: error: 'delayMicroseconds' was not declared in this scope

   97 |   delayMicroseconds( 10000 );

      |   ^~~~~~~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:98:3: error: 'digitalWrite' was not declared in this scope

   98 |   digitalWrite(reset,0);

      |   ^~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp: In function 'sx126x_hal_status_t sx126x_hal_wakeup(const void*)':

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:108:3: error: 'noInterrupts' was not declared in this scope

  108 |   noInterrupts();

      |   ^~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:110:3: error: 'digitalWrite' was not declared in this scope

  110 |   digitalWrite(nss,0);

      |   ^~~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:111:45: error: 'MSBFIRST' was not declared in this scope; did you mean 'SPI_MSBFIRST'?

  111 |   SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

      |                                             ^~~~~~~~

      |                                             SPI_MSBFIRST

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:122:9: error: 'digitalRead' was not declared in this scope

  122 |   while(digitalRead(busy) == 1);

      |         ^~~~~~~~~~~

c:\Users\monster\Documents\Arduino\libraries\LoRa_Library\src\sx126x_hal.cpp:123:3: error: 'interrupts' was not declared in this scope

  123 |   interrupts();

      |   ^~~~~~~~~~

exit status 1

Compilation error: exit status 1

Hello,

I'm working on a number of different projects at the moment and will unfortunately not have the time to figure out a way of making the code ESP32 compatible any time soon. Naturally, you are free to edit your own version of the code and figure out a way of getting the SPI pins configured properly.

The layer you would have to change is the sx126x_hal.cpp. You would pretty much have to reimplement the functions for SPI transmit and receive specific for your ESP32. After getting the SPI communication protocol configured, every function should work as intended with your microcontroller, or any microcontroller for that fact. For example, in one of my projects I'm taking this code and reimplementing it for my STM32.

Nevertheless, I really appreciate your interest in the library and hope you find what you are looking for shortly. If you do end up attempting to rework the sx126x_hal.cpp layer for your ESP32. Please let me know how it goes. If it works I would be happy to add you as a contributor to this repository to get the changes onto the Arduino library.

Please let me know if you have any further questions.

Best regards, Victor

imfatant commented 2 days ago

Hi Victor,

I am seriously looking at implementing the SPI code as a programming exercise - which would likely prove very useful to me. Might take a while but I'll stay in touch :)