HelTecAutomation / ESP32_LoRaWAN

Transplanted from Semtech LoRaWAN(https://github.com/Lora-net/LoRaMac-node) protocol to "ESP32 + Arduino" platform. Use RTC, support deep sleep, only working with ESP32 + LoRa boards made by HelTec Automation(TM). Need a unique license to use it.
344 stars 109 forks source link

Problem with read/write license #90

Closed rodrigolange closed 2 years ago

rodrigolange commented 2 years ago

Hello,

I'm having some troubles running the OTAA examples for HelTec Wifi LoRa 32(V2).

I followed the installation tutorial in https://github.com/HelTecAutomation/ESP32_LoRaWAN, installed the boards from github and got the license code using the chipId in http://www.heltec.cn/search/.

But when after I compile and write the code, the ESP stuck in a reboot loop:

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0030,len:1344 load:0x40078000,len:13864 load:0x40080400,len:3608 entry 0x400805f0 ESP32 MCU init...

abort() was called at PC 0x40082596 on core 1

Backtrace:0x40083cb1:0x3ffb26500x40089311:0x3ffb2670 0x4008e0fd:0x3ffb2690 0x40082596:0x3ffb2710 0x40082b6c:0x3ffb2760 0x400d1a04:0x3ffb2780 0x400d2195:0x3ffb27a0 0x400d1898:0x3ffb27e0 0x400d751e:0x3ffb2820

Using Esp Exception Decoder, I get the following information:

Decoding stack results 0x40083cb1: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c line 402 0x40089311: esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c line 128 0x4008e0fd: abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/abort.c line 46 0x40082596: esp_flash_erase_region at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/esp_flash_api.c line 541 0x40082b6c: spi_flash_erase_range at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/spi_flash/esp_flash_api.c line 1173 0x400d1a04: writelicense() at Mcu.cpp line 33 0x400d2195: McuClass::init(int, int, int, int, unsigned int*) at Mcu.cpp line 229 0x400d1898: setup() at C:\Users\lange\AppData\Local\Temp\arduino_modified_sketch_13536/pingpong.ino line 95 0x400d751e: loopTask(void*) at C:\Users\lange\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\cores\esp32\main.cpp line 42

It seems to me that the problem is related to the writting of the license in ESP32 flash, but the source code only has a Mcu.S file containing assembly (and therefore I cannot make some tests.

I run an example code that writes to the ESP flash and it worked without any problem.

Does anyone have the same problem/can help me?

Thanks!

PS: I'm trying to use the following code (pingpong.ino):

`

include

include "Arduino.h"

define RF_FREQUENCY 868000000 // Hz

define TX_OUTPUT_POWER 15 // dBm

define LORA_BANDWIDTH 0 // [0: 125 kHz,

                                                          //  1: 250 kHz,
                                                          //  2: 500 kHz,
                                                          //  3: Reserved]

define LORA_SPREADING_FACTOR 7 // [SF7..SF12]

define LORA_CODINGRATE 1 // [1: 4/5,

                                                          //  2: 4/6,
                                                          //  3: 4/7,
                                                          //  4: 4/8]

define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx

define LORA_SYMBOL_TIMEOUT 0 // Symbols

define LORA_FIX_LENGTH_PAYLOAD_ON false

define LORA_IQ_INVERSION_ON false

define RX_TIMEOUT_VALUE 1000

define BUFFER_SIZE 30 // Define the payload size here

char txpacket[BUFFER_SIZE]; char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents; void OnTxDone( void ); void OnTxTimeout( void ); void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );

typedef enum { STATUS_LOWPOWER, STATUS_RX, STATUS_TX }States_t;

int16_t txNumber; States_t state; bool sleepMode = false; int16_t Rssi,rxSize;

uint32_t license[4] = {0x15F25A2E,0x82CE5A13,0xF387854B,0x5C69085B};

define FORMAT_SPIFFS_IF_FAILED true

// Add your initialization code here void setup() { Serial.begin(115200); while (!Serial);

SPI.begin(SCK,MISO,MOSI,SS); Mcu.init(SS,RST_LoRa,DIO0,DIO1,license);

txNumber=0;
Rssi=0;

RadioEvents.TxDone = OnTxDone;
RadioEvents.TxTimeout = OnTxTimeout;
RadioEvents.RxDone = OnRxDone;

Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                               LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                               LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                               true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );

Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                               LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                               LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                               0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
state=STATUS_TX;

}

void loop() { switch(state) { case STATUS_TX: delay(1000); txNumber++; sprintf(txpacket,"%s","hello"); sprintf(txpacket+strlen(txpacket),"%d",txNumber); sprintf(txpacket+strlen(txpacket),"%s"," Rssi : "); sprintf(txpacket+strlen(txpacket),"%d",Rssi);

    Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));

    Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );
    state=STATUS_LOWPOWER;
    break;
case STATUS_RX:
  Serial.println("into RX mode");
    Radio.Rx( 0 );
    state=STATUS_LOWPOWER;
    break;
case STATUS_LOWPOWER:
    LoRaWAN.sleep(CLASS_C,0);
    break;
    default:
        break;

} }

void OnTxDone( void ) { Serial.print("TX done......"); state=STATUS_RX; }

void OnTxTimeout( void ) { Radio.Sleep( ); Serial.print("TX Timeout......"); state=STATUS_TX; } void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { Rssi=rssi; rxSize=size; memcpy(rxpacket, payload, size ); rxpacket[size]='\0'; Radio.Sleep( );

Serial.printf("\r\nreceived packet \"%s\" with Rssi %d , length %d\r\n",rxpacket,Rssi,rxSize);
Serial.println("wait to send next packet");

state=STATUS_TX;

}`

rodrigolange commented 2 years ago

updating:

i totally removed the Arduino IDE and reinstalled the boards using the IDE itself, now it seems to be working.

Thanks in advance!