groupgets / purethermal1-firmware

Reference firmware for PureThermal 1 FLIR Lepton Dev Kit
MIT License
126 stars 64 forks source link

Possibility to trigger firmware restart from host? #28

Closed ghellwig closed 4 years ago

ghellwig commented 4 years ago

Hi all,

I have a question regarding stability of a long running application. I got the impression that aborted streaming or extension unit requests leave the firmware on the board in some inconsistent state. This leads to a non-responsive camera which does not provide frames anymore. Obviously, one should try to avoid the above-mentioned aborts, but I would like to know if it is possible to send some kind of restart request instead of unplugging the board from the host.

Thank you for your help, Gregor

ghellwig commented 4 years ago

To put this into context: I am using the camera in some continuous streaming mode. When doing so, the camera stops streaming at some point and is irresponsive. This can only be cured unplugging the camera and thereby triggering a firmware restart. Obviously it would be better to fix the cause of the irresponsive state, but I would like to know anyways.

ghellwig commented 4 years ago

@kekiefer @Sheyne I think, you two are most likely the best candidates to answer my question.

I found the command ID LEP_CID_OEM_REBOOT, but issuing this run command leaves the camera in an irresponsive state. In addition it looks like the power_on command is not available via XUs. This might have to do with it to be not fully supported as the documentation states, but I am not sure about this, though.

ghellwig commented 4 years ago

@Sheyne It looks like your PR https://github.com/groupgets/purethermal1-firmware/pull/14 introduced a feature which might be useful for me in order to power_on the camera, right? Can you provide some usage instructions? Thank you, for your help!

ghellwig commented 4 years ago

Happy New Year! As I have seen some activity from you, @kekiefer, I got reminded of this issue here. Could you give me a hint on this one?

kekiefer commented 4 years ago

Sorry @ghellwig I don't know how to do this. For one thing, there is a bit of setup that the firmware does at startup which will have to be repeated (most importantly enable the vsync gpio, also set modes and color palettes), but if the thing is totally unresponsive you won't get this far. There may be some threads about this on the google group that might have more information.

ghellwig commented 4 years ago

Hi @kekiefer, thanks for your feedback. But do you have an idea on how to restart the whole firmware? Btw, which exact Google group are you referring to?

kekiefer commented 4 years ago

I wouldn't restart the whole firmware, since there are other initialization functions that are performed that maybe couldn't be repeated. You can step through and see what it's doing to the Lepton, those would be the things you'd repeat. Here is the google group: https://groups.google.com/forum/#!forum/flir-lepton

ghellwig commented 4 years ago

Ok, thanks for the link. I'll have a look. Regarding the steps to perform: Is it correct that you are referring to these steps: https://github.com/groupgets/purethermal1-firmware/blob/master/Src/lepton_task.c#L122-L169

I am also wondering if it could be that the lepton task died for some reason, e.g. unhandled exceptions, etc. In this, I guess, a camera restart is rather useless, right?

ghellwig commented 4 years ago

Hi @kekiefer, I have a quick question regarding this issue. From a discussion in the Google group I understand that it is sort of normal to obtain a LEP_RESULT of LEP_ERROR_I2C_FAIL when issuing LEP_RunOemReboot().

So, I was wondering if it would make sense to implement a special handling of the command ID LEP_CID_OEM_REBOOT within LEP_I2C_RunCommand_PT(). However, I have no idea how exactly and if one needs to take into account other dependent tasks which become invalid while rebooting the camera.

Any suggestions?

ghellwig commented 4 years ago

Basically, I want to achieve the same thing as the RST button of the PureThermal Mini is doing...

kekiefer commented 4 years ago

You can try calling HAL_NVIC_SystemReset() -- this will generate a system reset, and the code will start over from the reset vector like on POR from the reset button. There could be problems reinitializing clocks and peripherals for a second time if they're not shut down properly first, but it's certainly worth a try.

ghellwig commented 4 years ago

Thank you, I'll give that a try!

ghellwig commented 4 years ago

Just one thing, I noted: There is a special handling of FFC run commands here: https://github.com/groupgets/purethermal1-firmware/blob/master/Src/lepton_i2c_task.c#L675-L676

What's the rationale behind this? Is it required to do this for certain run commands?

ghellwig commented 4 years ago

HAL_NVIC_SystemReset() seems to work as expected, i.e. the board performs a restart.

Although this works, it is of course a dirty hack as you probably agree.

My observations with my previous attempts were the following:

Do you have any idea what I need to do cleanly restart lepton_task?

PS: I was using the LED and some HAL_Delay() calls to get some feedback from the board, but if you have a more sophisticated, but still easy, way for debugging I would be very pleased. :)

Steve7522 commented 3 years ago

@ghellwig Hi ghellwig I have the same problem as you but still do not find any solution so far. Do you solve the question of the non-responsive camera which did not provide frames anymore. Can you teach me to do next steps? I have looked for many ways, but I still can’t find a solution to finish it.

Thx