ArmDeveloperEcosystem / lorawan-library-for-pico

Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040 based board. 📡
BSD 3-Clause "New" or "Revised" License
139 stars 46 forks source link

Fix EepromMcuReadBuffer: Read back from cache #16

Closed ThomasLeister closed 2 years ago

ThomasLeister commented 2 years ago

Read back information from cache instead of flash. The cache contains the latest context, whereas the flash is only updated periodically.

This could cause issues if the flash is not (yet) updated while the context has been updated in the meantime and values are read by LoRaMAC.

Therefore just read from flash initially after startup (EepromMcuInit()) and rely on write cache later.

This commit effectively makes commit e31d3c133f0effca9d3660e35b383506018eca39 work for me and therefore is a fix. Previous attemps to use commit e31d3c13... without this commit failed. Error message: "Duty cycle restricted".

The error message might not appear at the first startup, but will appear if Raspberry Pi Pico is restarted and values from "EEPROM" / Flash have been read.

Might be related to #14 and also affects #15

ThomasLeister commented 2 years ago

Restoring context after Raspberry restart works fine with this PR:

First start with untouched Flash:

Initilizating LoRaWAN ... success!
Joining LoRaWAN network .......................................................................... joined successfully!
sending internal temperature: 19 °C (0x13)... success!

Second start is much quicker (context is used):

Initilizating LoRaWAN ... success!
Joining LoRaWAN network ............ joined successfully!
sending internal temperature: 19 °C (0x13)... success!
ep1cman commented 2 years ago

Tested using:

Everything seems to work as expected, joins seem to happen quickly.