-
Notifications
You must be signed in to change notification settings - Fork 3k
STM32WL I2C_1 and I2C_2: Unable to deep sleep #15191
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
Comments
@IoTopenTech thank you for raising this issue.Please take a look at the following comments: Could you add some more detail to the description? A good description should be at least 25 words. NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'. This indicates to us that at least all the fields have been considered. |
Yes, deepsleep is currently disabled during I2C init, and re-enabled in deinit... In the current implementation, I suppose that sensor should be "init" before each transmission.. |
Or deepsleep procedure could be re-implemented to save I2C registers before going in STOP mode, https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/sleep.c#L166 |
Thanks @jeromecoutant The problem is that there is no way to deinit I2C in the I2C API (https://os.mbed.com/docs/mbed-os/v6.15/apis/i2c.html) |
Oh! I didn't know that! You can have a look on |
Sorry @jeromecoutant I'm not experienced enough with mbed as to know what to look on there (i2c_free of mbed_hal_fpga_ci_test_shield/i2c/main.cpp). I think that there should be a free method in I2C.cpp; something like this As there is already a i2c_free function in https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/i2c_api.c That unlocks deep sleep in I2C_1 and I2C_2 Kind regards |
Related issue : #3106 |
Thanks @LMESTM, I've made that local change and it seems to work properly (now the uC is deepsleeping). |
closing , being tracked in 3106. Thanks for the confirmation the local change fixed it. |
Hi, got into the same situation. I did add: Behaviour I get is unreliable. After some time (sometime after a single uplink, sometime after 20mins) MCU doesn't enter sleep mode and with MBED_SLEEP_TRACING_ENABLED is see that at some point deepsleep locked by: [i2c_api.c x 1] pops up and after even more time x1 changed to x188 and increasing. |
Hi @JenertsA As indicated in #15191 (comment) When MCU doesn't enter into deepsleep any more, maybe a I2C "reset" is misisng ? |
hmm, could you tell me more about where reset should be placed? |
Hi, did you find any solution to the problem? I'm having the same problem and I can't find a solution. |
Hi @saffetblt Yes I found a workaround. |
Hi! take a look here: https://www.thethingsnetwork.org/forum/t/rak3172-mbedos-help-randomly-not-going-to-deep-sleep/55979/11 |
Hi @JenertsA @IoTopenTech |
Thanks for the tips, I was able to solve my issues with the tips, but unfortunately as I'm using a secure element with mbed-cryptoauth this one prevented any deepsleep.
But still no success, then I enabled Then following your recommandation I digged into mbed I2C stack and found 2 interesting stuff and explanation on why deep sleep is prevented on I2C1 and I2C2 on i2c_api.c #if defined(TARGET_STM32WL)
/* In Stop2 mode, I2C1 and I2C2 instances are powered down (only I2C3 register content is kept) */
sleep_manager_lock_deep_sleep();
#endif That means that by design, default I2C to use should be I2C3 to avoid all these issues (good to know for new design), but needs re routing our board that is not an option on the one we have. So I decided to fix that other way, assuming I know what I'm doing so let me do what I need. I commented out these 2 instance of #if defined(TARGET_STM32WL)
/* In Stop2 mode, I2C1 and I2C2 instances are powered down (only I2C3 register content is kept) */
//sleep_manager_lock_deep_sleep();
#endif So this mean any sleep between I2C transfer will break everything because I2C register will be lost, but in majority of case I wake up, do I2C stuff then going to sleep, so It's my charge to prevent deep sleep when I'm working on. and tada on each wake when I need to read sensors I call a function like that void read_sensor(void)
{
// Init back I2C since was lost during deep sleep
I2C i2c(I2C_SDA,I2C_SCL);
// Prevent deep sleep when using I2C
sleep_manager_lock_deep_sleep();
// Sensor stuff
Init_my_sensor(&i2c);
// Do all your sensor stuff
// bla bla bla you can use sleep it will not go to deep sleep to prevent I2C lost
// We done unlock deep sleep
sleep_manager_unlock_deep_sleep();
} quite easy, works with mbed-cryptoauth or any other. Just need 2 comments on mbed-os i2c_api.c, no need to call free or whatever, and you can have your I2C instance declared globally, you may just need to call back I2C init such as frequency each time you need to use I2C stuff of course. Any hints are welcome |
The previous library didn't work well when trying to deepsleep. Upon sleeping, the state of I2C_1 and I2C_2 of the STM32WLExx is cleared. This means that we can't sleep while they are in use. We will create a new I2C class whenever we want to communicate with the bmp280 and free it when we are done. This means we can sleep in between. NOTE: Some changes have been made to mbed os itself as well. See hallard/mbed-os@fabbed3 See ARMmbed/mbed-os#15191
The previous library didn't work well when trying to deepsleep. Upon sleeping, the state of I2C_1 and I2C_2 of the STM32WLExx is cleared. This means that we can't sleep while they are in use. We will create a new I2C class whenever we want to communicate with the bmp280 and free it when we are done. This means we can sleep in between. NOTE: Some changes have been made to mbed os itself as well. See hallard/mbed-os@fabbed3 See ARMmbed/mbed-os#15191
I'm currently doing
And use it locally |
Description of defect
Using STM32WLE5C, I2C_3 is able to enter deep sleep, but I2C_1 and I2C_2 no.
Target(s) affected by this defect ?
STM32WL
Toolchain(s) (name and version) displaying this defect ?
ARM GCC
What version of Mbed-os are you using (tag or sha) ?
mbed-os-6.15.0
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
Mbed Studio: 1.4.3
How is this defect reproduced ?
The following code in https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/i2c_api.c for I2C_1 and I2C_2 seems to lock deepsleep
But there is no way to re-enable deepsleep (for example in a low power device that only needs to read a sensor once per hour).
This increases the power consumption in 3mA.
It would be useful to have a free or deinit method.
The text was updated successfully, but these errors were encountered: