-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RX1 window Timer event never reached #38
Comments
@slavendam I had seen this issue in my mailbox and I was intrigued, but had not found any time to look at it yet. Now you've pointed out that Lora-net/LoRaMac-node#1349 might be relevant, and it might very well be. I have commented at that issue, with some debugging suggestions as well. Maybe best to report the results here, to not pollute that issue to much? |
Thanks for reaching back! I've already printed around line Full code is this:
Left are debug prints when everything WORK, right is when it DOESN'T WORK. I'm also attaching debug log file if you want to take a look (it is big, but you can start/look from end). I didn't find anything obivously wrong in this part, but I suspect that something behind this can be issue. Maybe some RTC value or something inside of IRQ handler where timing values are summed up. Reason why I think this is timing issue is because halt happens every time after 4:40h (no matter if you send with 5min period or 10min period). Like some overflow happens (leaving it for another 4:40h doesn't release it). Do you know if code use some other time source except GetTimerTicks()? |
I don't have "modem.maintain()" call directly in my code, but as I can see it is called from endPacket() function as |
So your prints show I do not have any suggestions right away, but I'm a bit too tired now to really dive in. I'll see if I can find a bit of time to look at your debug log tomorrow (not guarantees, though...). |
Thanks for taking the time to think about the problem. |
I think we have lucky winner :) In this RTC_StartAlarm line alarm is set up based on subSecond (ms) value. STM32LoRaWAN/src/BSP/timer_if.c Line 240 in 192c123
According to this: https://github.com/stm32duino/STM32RTC/blob/90414bcb87c41307b9a93b84a4ae589d6d621325/src/rtc.h#L195 As you can see from my logs, issue happens when processor tries to setup alarm with value of 4 310 527 ticks, and that value is multiplied by 1000. That should give value of 4 310 527 000 which is bigger than max value. That creates overflow in calulation so end result is wrong and alarm is set to some time value which RTC will not reach when it should. This is commit which made this issue: 54882c8 |
UPDATE
Test results:
|
During solving of this problem, I found new one. STM32LoRaWAN/src/BSP/timer_if.c Line 240 in 192c123
Solution for this problem is:
We are using variable with bigger range because during calculations, our values can overflow in uint32_t. Second problem I found is "bomb" which will trigger in ~50 days and will block code execution. Logic of processor is based on number of ticks which value can be between 0 and UINT32_MAX (4294967295). https://github.com/stm32duino/STM32RTC/blob/90414bcb87c41307b9a93b84a4ae589d6d621325/src/rtc.c#L801 That is reason why we are doing calculation number_of_ticks(1000/MS_TO_TICK)* and this second part is equal to ~3.9. Example: In RTC_StartAlarm function ti will send only 32 bits of value, not all 64 bits. In RTC_StartAlarm it is calculating subSeconds back to ticks: https://github.com/stm32duino/STM32RTC/blob/90414bcb87c41307b9a93b84a4ae589d6d621325/src/rtc.c#L906 As it got wrong subSecond value, ticks will be calculated wrong and alarmB will be set wrongly. Solution is to add uint64_t parameter to RTC_StartAlarm function so we can forward correct value of subSeconds (and ticks, because they are connected). I added new line in rtc.h next to this line: as it follows: In rtc.c I changed this line: https://github.com/stm32duino/STM32RTC/blob/90414bcb87c41307b9a93b84a4ae589d6d621325/src/rtc.c#L801 With this:
This logic enables that all library users who implemented this RTC_StartAlarm function don't need to change anything (no need to add new parameters). Maybe it is possible to set "...uint64_t ticksToSubSeconds=NULL)", without declaration of new function, but I didn't test that part. And this line: is changed with this:
It is checking if 64 bits value is sent. If it is, it will use it, and if not, than regular 32 bit subSecond variable will be used. And finally when I changed STM32RTC library, I made change in STM32LoRaWAN. STM32LoRaWAN/src/BSP/timer_if.c Line 240 in 192c123
Is changed with this:
Now we are calling RTC_StartAlarm2 (and not RTC_StartAlarm) because it can receive uint64_t value. subSeconds_start value is not important because it will not be used. I've tested this solution with hardcoded value of 4 290 000 000 ticks.
"tmp" is result of calculating received subseconds (ticksToSubSeconds) back to ticks, and "alarm" is new alarm. EDIT: this difference in result 429... vs 428.. was due to wrong order of calculation (during debuging I changed to first divide by 1000, than multiply by 256). It should first multiply, than divide, as it was earlier. @fpistm probably your assistance will be necessary in solving this here and in STM32RTC library. :) |
Hi @slavendam, |
Hi @slavendam,
The main difference is that a SubSecond parameter is expressed on 64bit, instead of passing the uint32_t subSeconds plus the uint32_t ticksToSubSeconds. Could you please check the conversion and if this fix the issue in the same way as yours
|
@slavendam |
Sorry for delay. I'll give you feedback in day or two |
Thank you for all your work on this issue, I am experiencing the same issue and was relieved to find such a detailed investigation had already been undertaken. ❤ Unfortunately the PRs you mentioned above @FRASTM (#39 and stm32duino/STM32RTC#109) don't appear to resolve this issue for me. After applying these patches locally I continue to find myself stuck in I am a little stuck as to the next steps to try and resolve this, but happy to test other proposed fixes if there are any suggestions. |
I have the same problem as you mentioned: getting stuck at |
I also ran into this problem with my work project where I created a MBus to LoRa WAN Gateway. I have tried to apply multiple patches mentioned here but it seems nothing really works and testing all of this is really hard because I always have to wait almost five hours. I hope there will be some progress on this soon and I am curious if there is a different way to testing solutions than waiting. |
Currently no progress. As we are not able to reproduce with Nucleo WL55. Seems related to other hardware setup. |
Okay thank you for the update. I am using a Seeed Studio LoRa E5 mini Board wit the STM32WLE5JC Module on Board witch seems to be very similar to the STM32WL55JC1 Chip but maybe I am missing something here |
so I ran into this issue too... using a custom board with a Seeed LoRa-E5-LE module. I cannot think of a hardware issue, but I will run my code on a Nucleo WL55. For me this looks like a show stopper as I am running out of time for my project. |
I ran into the 4:40 bug as well, have seen your PRs and that you are still waiting for feedback on that.
I tracked down the issue and found the if-else-branch causing the problem. My PR to resolve it is here: |
Describe the bug
endPacket() is never finished after 4:40h of properly working. I've tested 3 times and it blocked at same time (4:40h).
2 times with 10min sending period between (both times it blocked at counter 29) and once tested with 5min sending period (same time period passed, but now it blocked on counter 57).
I did debugging by adding multiple print logs in header files.
Sending is done successfuly, message arrives on gateway - and than it stops, like it is in infinite loop.
RX1 window should be opened, but it seems that this part is never done.
After LoRaMacProcess() function is done once (for sending), function OnRxWindow1TimerEvent() should be called - but it is never called.
I'm using RAK3172 module, EU868 region.
I'm using STM32 Low Power library to send device in DeepSleep, and I'm using RTC Alarm timed wakeup.
Even if it is stuck between TX and RX windows, this alarms work properly (I can see alarm triggers later).
I tried to disable DeepSleep and alarms, and use delay instead, but result is the same.
Transmitted payload has 6 bytes.
To Reproduce
Set device to send messages every 10min and wait for 29th message. Or set with 5min time period and wait for 57th message.
That last message will be transmitted, endPacket() function will not be finished.
Expected behavior
This is part of logs how it should looks like when it works correctly (note that 2nd section is missing later):
This is log when it stopped:
Has anyone had the same problem, or do you have idea about possible solution?
Thanks!
The text was updated successfully, but these errors were encountered: