khoih-prog / Ethernet_Generic

Simple Ethernet library for AVR, AVR Dx, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, W5100S, W6100. With this library you can use the Arduino Ethernet (shield or board) to connect to Internet to provides both Client and server functionalities.
43 stars 22 forks source link

Using SPI1 for LoRaWAN WISOL LOM204 Module #4

Closed tcpipchip closed 2 years ago

tcpipchip commented 2 years ago

Dear Khoih

I am using the STM32L0 + SX1276 (LoRaWAN WISOL LOM204 MODULE).

I ported the STM32 ARDUINO to it and working nice!

image

The module uses the SPI, not the SPI1 or SPI2

Now i want to add the WIZNET W500 to SPI1 , did you port the defines to use the SPI1 to WIZNET ?

I spent some hours without success!

My idea is to use the SPI (SX1276) and SPI1 (WIZNET) togetther, btw, add ETHERNET to LOM204

khoih-prog commented 2 years ago

Hi @tcpipchip

I'm sorry I don't have that kind of hardware to help you, but these are steps you can try, test and adapt

  1. Define the new and extra SPI, such as SPI3 as you did in variant_generic.h
#ifndef PIN_SPI3_MOSI
  //LOM204
  #define PIN_SPI3_MOSI PB15
#endif

#ifndef PIN_SPI3_MISO
  //LOM204
  #define PIN_SPI3_MISO PB14
#endif

#ifndef PIN_SPI3_SCK
  //LOM204
  #define PIN_SPI3_SCK PB13
#endif

#ifndef PIN_SPI_SS3
  //LOM204
  #define PIN_SPI_SS3 PB16 // Or another good pin
#endif
  1. Modify STM32 SPI library, or add somewhere in your code, to create an instance of SPI3 for STM32L072
// SPIClass(uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel = PNUM_NOT_DEFINED);
SPIClass SPI3(PIN_SPI3_MOSI, PIN_SPI3_MISO, PIN_SPI3_SCK, PIN_SPI_SS3);
  1. Modify the file w5100_Impl.h to add STM32L072-related code

https://github.com/khoih-prog/Ethernet_Generic/blob/bab28a9fd77e9a141fc4d051a77c972ae0a01578/src/utility/w5100_Impl.h#L197-L223

such as

#elif (ETHERNET_USE_RPIPICO && !defined(ARDUINO_ARCH_MBED))
    // For arduino-pico core
    // SPIClassRP2040(spi_inst_t *spi, pin_size_t rx, pin_size_t cs, pin_size_t sck, pin_size_t tx);
    SPIClass* pCUR_SPI = (SPIClass*) &SPI1;

    #define CUR_PIN_MISO      PIN_SPI1_MISO
    #define CUR_PIN_MOSI      PIN_SPI1_MOSI
    #define CUR_PIN_SCK       PIN_SPI1_SCK
    #define CUR_PIN_SS        PIN_SPI1_SS
#elif defined(STM32L0)
    // For STM32L072 of LOM204
    // SPIClass SPI3(PIN_SPI3_MOSI, PIN_SPI3_MISO, PIN_SPI3_SCK, PIN_SPI_SS3);
    SPIClass* pCUR_SPI = (SPIClass*) &SPI3;  
#endif  
  1. In you code, select
#define USING_SPI2       true

before

#include "Ethernet_Generic.h"

These steps are just drafted and not tested, you have to test and adapt according to your hardware and condition.

Good Luck

PS:

Why don't share the same SPI bus for both Ethernet and SX1276 LoRaWAN? Possibly some mods in the code and/or hardware to select the CS/SS pin to avoid SPI-bus monopolization

tcpipchip commented 2 years ago

Thank you so much KHOIH I will make the changes tomorrow

I can not share the sx1276 and Ethernet with the same bus because I don’t have the physical access to the spi gpios connected to sx1276, only access to a second spi bus

Lom204 is a module

tcpipchip commented 2 years ago

define USING_SPI2 true OR the correct is

define USING_SPI3 true

?

because in main() I see

if (USING_SPI2)

if defined(CUR_PIN_MISO)

ETG_LOGWARN(F("Default SPI pinout:"));
ETG_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ETG_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ETG_LOGWARN1(F("SCK:"),  CUR_PIN_SCK);
ETG_LOGWARN1(F("SS:"),   CUR_PIN_SS);
khoih-prog commented 2 years ago

It's not important as each board is using the different notation.

So I just name

#define USING_SPI2   true

for any SPI besides SPI0/SPI1


I've modified the libraries and tested OK on Nucleo144 F767ZI and L552ZE-Q using SPI2. I'll publish new releases of this Ethernet_Generic and EthernetWebServer_STM32 to support SPI2, or any custom hardware SPI

I'm sure you can adapt the code and be OK.


WebClientRepeating on NUCLEO_F767ZI, using W5x00 using Ethernet_Generic Library on SPI2

Start WebClientRepeating on NUCLEO_F767ZI, using W5x00 using Ethernet_Generic Library on SPI2
EthernetWebServer_STM32 v1.4.2
[EWS] Default SPI pinout:
[EWS] MOSI: 22
[EWS] MISO: 25
[EWS] SCK: 23
[EWS] SS: 24
[EWS] =========================
Connected! IP address: 192.168.2.123
Connecting...
HTTP/1.1 200 OK
Date: Tue, 03 May 2022 02:21:30 GMT
Content-Type: text/plain
Content-Length: 2263
Connection: close
x-amz-id-2: 3UTJOk8AtRD5jCq+6bBOdAUucpho+KMM4ra+5/evX48oAT9NyZiaJbPNw5DOAr+amoxXbxbowX0=
x-amz-request-id: RB5W2BTZZ19E49PA
Last-Modified: Wed, 23 Feb 2022 14:56:42 GMT
ETag: "667cf48afcc12c38c8c1637947a04224"
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=GhwgztuLVJJhJBZt6cqr%2BYWDLWUzEcRPjVVpSU3Sz9KSRzj4q4DK9bvi1B2BSl7uxytKSSxOFBnKeekqPJw9LvpyYpYvHuOVcxatw924HWhtyK1OCApzLxZRLmobotQ%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 705586061d4354d9-YYZ
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

           `:;;;,`                      .:;;:.           
        .;;;;;;;;;;;`                :;;;;;;;;;;:     TM 
      `;;;;;;;;;;;;;;;`            :;;;;;;;;;;;;;;;      
     :;;;;;;;;;;;;;;;;;;         `;;;;;;;;;;;;;;;;;;     
    ;;;;;;;;;;;;;;;;;;;;;       .;;;;;;;;;;;;;;;;;;;;    
   ;;;;;;;;:`   `;;;;;;;;;     ,;;;;;;;;.`   .;;;;;;;;   
  .;;;;;;,         :;;;;;;;   .;;;;;;;          ;;;;;;;  
  ;;;;;;             ;;;;;;;  ;;;;;;,            ;;;;;;. 
 ,;;;;;               ;;;;;;.;;;;;;`              ;;;;;; 
 ;;;;;.                ;;;;;;;;;;;`      ```       ;;;;;`
 ;;;;;                  ;;;;;;;;;,       ;;;       .;;;;;
`;;;;:                  `;;;;;;;;        ;;;        ;;;;;
,;;;;`    `,,,,,,,,      ;;;;;;;      .,,;;;,,,     ;;;;;
:;;;;`    .;;;;;;;;       ;;;;;,      :;;;;;;;;     ;;;;;
:;;;;`    .;;;;;;;;      `;;;;;;      :;;;;;;;;     ;;;;;
.;;;;.                   ;;;;;;;.        ;;;        ;;;;;
 ;;;;;                  ;;;;;;;;;        ;;;        ;;;;;
 ;;;;;                 .;;;;;;;;;;       ;;;       ;;;;;,
 ;;;;;;               `;;;;;;;;;;;;                ;;;;; 
 `;;;;;,             .;;;;;; ;;;;;;;              ;;;;;; 
  ;;;;;;:           :;;;;;;.  ;;;;;;;            ;;;;;;  
   ;;;;;;;`       .;;;;;;;,    ;;;;;;;;        ;;;;;;;:  
    ;;;;;;;;;:,:;;;;;;;;;:      ;;;;;;;;;;:,;;;;;;;;;;   
    `;;;;;;;;;;;;;;;;;;;.        ;;;;;;;;;;;;;;;;;;;;    
      ;;;;;;;;;;;;;;;;;           :;;;;;;;;;;;;;;;;:     
       ,;;;;;;;;;;;;;,              ;;;;;;;;;;;;;;       
         .;;;;;;;;;`                  ,;;;;;;;;:         

    ;;;   ;;;;;`  ;;;;:  .;;  ;; ,;;;;;, ;;. `;,  ;;;;   
    ;;;   ;;:;;;  ;;;;;; .;;  ;; ,;;;;;: ;;; `;, ;;;:;;  
   ,;:;   ;;  ;;  ;;  ;; .;;  ;;   ,;,   ;;;,`;, ;;  ;;  
   ;; ;:  ;;  ;;  ;;  ;; .;;  ;;   ,;,   ;;;;`;, ;;  ;;. 
   ;: ;;  ;;;;;:  ;;  ;; .;;  ;;   ,;,   ;;`;;;, ;;  ;;` 
  ,;;;;;  ;;`;;   ;;  ;; .;;  ;;   ,;,   ;; ;;;, ;;  ;;  
  ;;  ,;, ;; .;;  ;;;;;:  ;;;;;: ,;;;;;: ;;  ;;, ;;;;;;  
  ;;   ;; ;;  ;;` ;;;;.   `;;;:  ,;;;;;, ;;  ;;,  ;;;;   

WebClientRepeating on NUCLEO_L552ZE_Q, using W5x00 using Ethernet_Generic Library on SPI2

Start WebClientRepeating on NUCLEO_L552ZE_Q, using W5x00 using Ethernet_Generic Library on SPI2
EthernetWebServer_STM32 v1.4.2
[EWS] Default SPI pinout:
[EWS] MOSI: 22
[EWS] MISO: 25
[EWS] SCK: 23
[EWS] SS: 24
[EWS] =========================
Connected! IP address: 192.168.2.123

Connecting...
HTTP/1.1 200 OK
Date: Tue, 03 May 2022 02:40:24 GMT
Content-Type: text/plain
Content-Length: 2263
Connection: close
x-amz-id-2: 46EhWX58C9hyDf7ag/cTxLHtNc/l+uC2facDUqKXDnm4pAdM3721pkdwUwjVF0O7mr1MGAcjQiY=
x-amz-request-id: 04CEE3RJB7W2M05T
Last-Modified: Wed, 23 Feb 2022 14:56:42 GMT
ETag: "667cf48afcc12c38c8c1637947a04224"
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=TYzyXPfNW7yd579FqPTzYEXQnSRcAFeyj74iulNNRmVZEUk6Qz%2F2dgIwFVJxacbwtzdVR9Q2FK2cgryr0GC9k3NfyFAgZpLZIjEwfEhycKWnNE9KxX%2F%2B6dRwTLcV9hY%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 7055a1b9cda84009-YYZ
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

           `:;;;,`                      .:;;:.           
        .;;;;;;;;;;;`                :;;;;;;;;;;:     TM 
      `;;;;;;;;;;;;;;;`            :;;;;;;;;;;;;;;;      
     :;;;;;;;;;;;;;;;;;;         `;;;;;;;;;;;;;;;;;;     
    ;;;;;;;;;;;;;;;;;;;;;       .;;;;;;;;;;;;;;;;;;;;    
   ;;;;;;;;:`   `;;;;;;;;;     ,;;;;;;;;.`   .;;;;;;;;   
  .;;;;;;,         :;;;;;;;   .;;;;;;;          ;;;;;;;  
  ;;;;;;             ;;;;;;;  ;;;;;;,            ;;;;;;. 
 ,;;;;;               ;;;;;;.;;;;;;`              ;;;;;; 
 ;;;;;.                ;;;;;;;;;;;`      ```       ;;;;;`
 ;;;;;                  ;;;;;;;;;,       ;;;       .;;;;;
`;;;;:                  `;;;;;;;;        ;;;        ;;;;;
,;;;;`    `,,,,,,,,      ;;;;;;;      .,,;;;,,,     ;;;;;
:;;;;`    .;;;;;;;;       ;;;;;,      :;;;;;;;;     ;;;;;
:;;;;`    .;;;;;;;;      `;;;;;;      :;;;;;;;;     ;;;;;
.;;;;.                   ;;;;;;;.        ;;;        ;;;;;
 ;;;;;                  ;;;;;;;;;        ;;;        ;;;;;
 ;;;;;                 .;;;;;;;;;;       ;;;       ;;;;;,
 ;;;;;;               `;;;;;;;;;;;;                ;;;;; 
 `;;;;;,             .;;;;;; ;;;;;;;              ;;;;;; 
  ;;;;;;:           :;;;;;;.  ;;;;;;;            ;;;;;;  
   ;;;;;;;`       .;;;;;;;,    ;;;;;;;;        ;;;;;;;:  
    ;;;;;;;;;:,:;;;;;;;;;:      ;;;;;;;;;;:,;;;;;;;;;;   
    `;;;;;;;;;;;;;;;;;;;.        ;;;;;;;;;;;;;;;;;;;;    
      ;;;;;;;;;;;;;;;;;           :;;;;;;;;;;;;;;;;:     
       ,;;;;;;;;;;;;;,              ;;;;;;;;;;;;;;       
         .;;;;;;;;;`                  ,;;;;;;;;:         

    ;;;   ;;;;;`  ;;;;:  .;;  ;; ,;;;;;, ;;. `;,  ;;;;   
    ;;;   ;;:;;;  ;;;;;; .;;  ;; ,;;;;;: ;;; `;, ;;;:;;  
   ,;:;   ;;  ;;  ;;  ;; .;;  ;;   ,;,   ;;;,`;, ;;  ;;  
   ;; ;:  ;;  ;;  ;;  ;; .;;  ;;   ,;,   ;;;;`;, ;;  ;;. 
   ;: ;;  ;;;;;:  ;;  ;; .;;  ;;   ,;,   ;;`;;;, ;;  ;;` 
  ,;;;;;  ;;`;;   ;;  ;; .;;  ;;   ,;,   ;; ;;;, ;;  ;;  
  ;;  ,;, ;; .;;  ;;;;;:  ;;;;;: ,;;;;;: ;;  ;;, ;;;;;;  
  ;;   ;; ;;  ;;` ;;;;.   `;;;:  ,;;;;;, ;;  ;;,  ;;;;   
khoih-prog commented 2 years ago

The Ethernet_Generic releases v2.2.0 has just been published

You now can use any SPI with STM32, or any future boards.

To adapt to any STM32 board, just simply change in defines.h, for examples

https://github.com/khoih-prog/Ethernet_Generic/blob/8b5eada9557c534a921c5caf742325a5316618d7/examples/WebClientRepeating/defines.h#L313-L352


Releases v2.2.0

  1. Add support to STM32 boards using Arduino_Core_STM32
  2. Add support to any board with core supporting custom hardware / software SPI, for example STM32.
khoih-prog commented 2 years ago

The EthernetWebServer_STM32 releases v1.5.0 has just been published

You now can use any SPI with STM32

To adapt to any STM32 board, just simply change in defines.h, for examples

https://github.com/khoih-prog/EthernetWebServer_STM32/blob/0f96707eff5d79ff252a97026b28a927d511cef9/examples/AdvancedWebServer/defines.h#L87-L135

#if USE_ETHERNET_GENERIC

  #include <SPI.h>

  // Be sure to use true only if necessary for your board, or compile error
  #define USING_CUSTOM_SPI            true

  #if ( USING_CUSTOM_SPI )
    // Currently test OK for F767ZI and L552ZE_Q
    #define USING_SPI2                  true

    #define SHIELD_TYPE           "W5x00 using Ethernet_Generic Library and custom SPI" 

    #if (USING_SPI2)
      // For L552ZE-Q, F767ZI, but you can change the pins for any other boards
      // SCK: 23,  MOSI: 22, MISO: 25, SS/CS: 24 for SPI1
      #define CUR_PIN_MISO              25
      #define CUR_PIN_MOSI              22
      #define CUR_PIN_SCK               23
      #define CUR_PIN_SS                24

      #define SPI_NEW_INITIALIZED       true

      // Don't create the instance with CUR_PIN_SS, or Ethernet not working
      // To change for other boards' SPI libraries
      SPIClass SPI_New(CUR_PIN_MOSI, CUR_PIN_MISO, CUR_PIN_SCK);

      //#warning Using USE_THIS_SS_PIN = CUR_PIN_SS = 24

      #if defined(USE_THIS_SS_PIN)
        #undef USE_THIS_SS_PIN
      #endif   
      #define USE_THIS_SS_PIN       CUR_PIN_SS    //24

    #endif

  #else

    #define SHIELD_TYPE           "W5x00 using Ethernet_Generic Library"  

  #endif

  #include "Ethernet_Generic.h"

  #define ETHERNET_LARGE_BUFFERS

  #define _ETG_LOGLEVEL_                      1

#endif

Releases v1.5.0

  1. Add support to any custom hardware / software SPI for W5x00 using Ethernet_Generic Library
  2. Add support to STM32L5 boards, such as Nucleo-L552ZE-Q
tcpipchip commented 2 years ago

Nice! I will test it this afternoon :) LoRaWAN and Ethernet together 😀

tcpipchip commented 2 years ago

Good morning

image

WISOL LOM204 LoRaWAN + W5500 working together :)

image

tcpipchip commented 2 years ago

i will test more then we update the Github :)

tcpipchip commented 2 years ago

Tests ok

Wich software terminal do you use to show aligment arduino text (splash)?

image

khoih-prog commented 2 years ago

Just using Arduino IDE Terminal.

IMO, good and reliable terminal must be dumb and just printing out whatever the output is.

You have to format the output as you'd like before sending any text to the terminal.

tcpipchip commented 2 years ago

thank you! https://lom204-cli-wisol.blogspot.com/2022/05/importante-opcao-nao-oficial-da-wisol.html