mbed-ce / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
37 stars 12 forks source link

Reset LSCOEN after test with 32KHz output #245

Closed lefebvresam closed 4 months ago

lefebvresam commented 4 months ago

In system_clock.c (TARGET_STM32U575xG) I made a test option to output the 32kHz signal to PA_2 pin:

#if DEBUG_LSCO == 1
    HAL_RCCEx_EnableLSCO(RCC_LSCOSOURCE_LSE); // 32 kHz
#endif

But if you disable that option after using it, the register config survives a reboot and the 32KHz clock is still at the output pin. It makes it impossible to use that pin for digital I/O, Interrupt or Pwmout. I don't know why those register settings are permanent. I should expect to redo register settings after every reset.

My suggestion is to disable the LSCO before this call to ensure that the output is released when the debug option is put off:

// Output clock on LSCO pin(PA2) for debugging purpose
// LSE is set with the low power ticker
HAL_RCCEx_DisableLSCO();
#if DEBUG_LSCO == 1
    HAL_RCCEx_EnableLSCO(RCC_LSCOSOURCE_LSE); // 32 kHz
#endif

I tested this and it works as expected. The strange thing is that HAL_RCCEx_DisableLSCO is never used for other CPU's. When OK I can make a PR for that.

multiplemonomials commented 4 months ago

Hmm, how about making it a target option instead? e.g. here: https://github.com/mbed-ce/mbed-os/blob/master/targets/targets.json5#L4834

That would allow people to decide if they want LSCO via a mbed_app.json setting!

JohnK1987 commented 4 months ago

It is not related to your application with the battery? The LSCO is related to LSE and can be used for external devices. So its settings/register could have same behavior like LSE when Vbat is powered, mean it can be stored in backup domain.

lefebvresam commented 4 months ago

I think you are right. I have a backup battery which is permanently connected. I agree to make it open for everyone and put it in an option, but I was wondering if there is a 'standardized' method for this. With other words, are other devices also exposing it as an option?

JohnK1987 commented 4 months ago

The strange thing is that HAL_RCCEx_DisableLSCO is never used for other CPU's.

Nothing strange, you do not need call disable when you never call enable. That seems be state of all clock settings of STM32 in Mbed.

So i see this like a project specific option. But i believe it could be handy to make a note about this in https://github.com/mbed-ce/mbed-os/tree/master/targets/TARGET_STM#low-power-clock

multiplemonomials commented 4 months ago

I'm going to close this since it seems like it's more of a prototyping level thing. But please do create a wiki page if you'd like to make sure other people can find this information!