Hello there,
I used to work with the RAK3172-T and I recently tried the -F version.
It seems that there is a critical firmware crash happening when waking up from api.system.sleep.all() under specific compilation conditions on the RAK3172-F target (rak_rui 4.2.4).
The crash occurs only when both SPI.begin() and sqrt() (from standard <math.h>) are present in the project. Removing either Serial.begin() OR sqrt() makes the system stable. Other <math.h> functions (such as atan()) do not trigger the bug.
Furthermore, compiling the exact same code with the RAK3172-T target variant running on the RAK3172-F seems to work as expected.
here is the OTAA exemple with a minimal use of SPI and sqrt(). You will notice that after the first received callback, the code doesn’t come back in the loop.
#define OTAA_PERIOD (5000)
#define OTAA_BAND (RAK_REGION_EU868)
uint8_t collected_data[64] = {0};
void recvCallback(SERVICE_LORA_RECEIVE_T* data) {
Serial.println(“received callback”);
if (data->BufferSize > 0) {
Serial.println(“Something received!”);
for (int i = 0; i < data->BufferSize; i++)
Serial.printf(“%x”, data->Buffer[i]);
Serial.print(“\r\n”);
}
}
void joinCallback(int32_t status) {
Serial.printf(“Join status: %d\r\n”, status);
}
void sendCallback(int32_t status) {
if (status == RAK_LORAMAC_STATUS_OK)
Serial.println(“Successfully sent”);
else
Serial.println(“Sending failed”);
}
void setup() {
SPI.begin();
delay(1000);
Serial.begin(115200, RAK_AT_MODE);
delay(2000);
if (api.lorawan.nwm.get() != 1) {
Serial.printf(“Set Node device work mode %s\r\n”, api.lorawan.nwm.set() ? “Success” : “Fail”);
api.system.reboot();
}
if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) {
Serial.printf(“LoRaWan OTAA - set device class is incorrect! \r\n”);
return;
}
if (!api.lorawan.njm.set(RAK_LORA_OTAA)) // Set the network join mode to OTAA
{
Serial.printf(“LoRaWan OTAA - set network join mode is incorrect! \r\n”);
return;
}
if (!api.lorawan.join()) // Join to Gateway
{
Serial.printf(“LoRaWan OTAA - join fail! \r\n”);
return;
}
while (api.lorawan.njs.get() == 0) {
Serial.print(“Wait for LoRaWAN join…”);
api.lorawan.join();
delay(5000);
}
if (!api.lorawan.adr.set(true)) {
Serial.printf(“LoRaWan OTAA - set adaptive data rate is incorrect! \r\n”);
return;
}
if (!api.lorawan.rety.set(1)) {
Serial.printf(“LoRaWan OTAA - set retry times is incorrect! \r\n”);
return;
}
if (!api.lorawan.cfm.set(1)) {
Serial.printf(“LoRaWan OTAA - set confirm mode is incorrect! \r\n”);
return;
}
api.lorawan.registerRecvCallback(recvCallback);
api.lorawan.registerJoinCallback(joinCallback);
api.lorawan.registerSendCallback(sendCallback);
}
void uplink_routine() {
uint8_t data_len = 0;
collected_data[data_len++] = (uint8_t)‘t’;
collected_data[data_len++] = (uint8_t)‘e’;
collected_data[data_len++] = (uint8_t)‘s’;
collected_data[data_len++] = (uint8_t)‘t’;
if (api.lorawan.send(data_len, (uint8_t*)&collected_data, 2, true, 1))
Serial.println(“Sending is requested”);
else
Serial.println(“Sending failed”);
}
void loop() {
Serial.println(“loop”);
double varX = sqrt(millis());
static uint64_t last = 0;
static uint64_t elapsed;
if ((elapsed = millis() - last) > OTAA_PERIOD) {
uplink_routine();
last = millis();
}
Serial.printf(“Try sleep %ums…”, OTAA_PERIOD);
api.system.sleep.all(OTAA_PERIOD);
Serial.println(“Wakeup…”);
}
Could you please confirm if you are able to reproduce this behavior ? Any insights on the root cause or suggestions for a workaround would be greatly appreciated.
Thanks in advance for your help !