STM32F429 Why I can't read RTC? - stm32

I have a question about the RTC on STM43F429. I have a board that manages the RTC date and Time with a battery backup.
After some test I have this problem: after a reset , when I try to read the RTC time for the first time, the RTC seems stopped (I see hh:mm:ss stipped) but if I look at the internal RTC register (with debugger) all is OK... so I cant read the current time.
To solve this I have to read the date before and then I can read the time and the RTC is running correctly.. I don't understand why I have to read the date before to read the time. Can someone explay this? Thanks

You need wait when data from RTC will be synchronised with their shadow registers, it is every two RTC clocks, and can be checked with RTC_ISR.RSF (Registers Synchronisation Flag).
More info is in Reference manual section 26.3.2 Real-time clock and calendar.

Related

STM32L151c8t6 PCB design problems (nrst)

hi we haveseveral boards in need of the stm32L151C8t6 and we have some stock of the mcu in question the problem is that all the pcbs 'from JLCPCB' have this weird issue were the mcu is stuck and i have to manually poke thenrst pin multiple time for it to run normally "poke as in pull it to gnd for it to reset " please i need help with this i'll share some the the designs
example 1:
PCB design
example 2:
PCB design
made a dac output from 0 to max
start the program nothing happens
try to jump the nrst multiple times until it starts
using stm studio and changing a value i in the program so i can see where it stopped
video explaining
Video

Restrict user to use only network provided time

I made an attendance app in Flutter in which I want to restrict employees to use only network provided time so that employees won't be able to temper the date and time.
Is there any option or solution to implement this in android and iOS as well?
Using this package datetime_settings we will get the settings of Automatic date & time of mobile so when automatic date & time is on mobile will give us an accurate network time otherwise we will show an error to turn on the automatic date & time in settings. That's how I used to restrict users to use only network-provided time.
I'll tell you what worked for me. Hope this can help you. I don't know if it's the most optimized way to do it, but it worked very well for me:
You need to create an internal clock for your app, and from this, use it instead of the DateTime.now() function. For this, you must take the server time when opening the app, and keep it updated with a timer that runs every 1 second.
Please note that the app goes to sleep (or closes) when the device is locked or the app is minimized for a certain amount of time (this depends on the operating system and battery saver settings), thereby stopping the internal clock, and consequently, it is delayed when the app is activated again. In my case, I got around this problem by using a foreground service that I designated to perform this task (I used flutter_foreground_task). Another advantage of using a foreground service, is that the user can close the app and the clock keeps running (and in my case, I also perform other simple tasks periodically).
If the user does not manipulate the system time, the difference should never reach 1 second.
Optionally, you could check when retrieving the server time, the difference with the device time, and if it is greater than a certain gap that you determine, warn the user, so that he can correct it if he prefers, so that he does not see a discrepancy with the time recorded and displayed by the application.
Regards.

Get current MIDI timecode from stopped device

Is there a way to ask a MIDI device for its current timecode value while it is stopped? Specifically, I want to poll Pro Tools for its current MTC value (via the macOS Audio MIDI Setup Utility, IAC bus). The only way I've been able to come up with is to send a play command, immediately followed by a stop command. But I'd like to find a way to do it without moving the bus. I've tried sending "pause", "reset", "shuttle", and "chase" commands, but nothing will get Pro Tools to send the current MTC time value besides "play." Hoping to not have to use the old HUI protocol (if it even works with PT anymore). Thanks
The MTC specification says that Full Time Code messages are sent "when equipment needs to be fast-forwarded or rewound, located or cued to a specific time". This implies that no messages are sent if the time has not changed.
So there is no standard way.

STM32L4 - HAL_I2C_STATE_BUSY_RX issue

I'm having trouble with i2c communication. In my i2c bus, i have 4 boards (STM32L4 Sensortiles) and sometimes one of them blocks the bus and the others stop communicating consequently. When I reset that one that blocks the bus, all boards starting working again.
In my debugs, this bug happened when HAL_I2C_GetState(&hi2c3) returns HAL_I2C_STATE_BUSY_RX, even my others i2c functions HAL_I2C_Slave_Receive_IT and HAL_I2C_Slave_Transmit_IT returns HAL_OK:
Any ideas what Im doing wrong? Thanks.
Using libraries like HAL leads to problems like this one. Why?
HAL users feel free from knowing your hardware as magic library will do everything for you.
HAL users usually do not know how the peripheral works and how to debug it.
HAL users do not bother to go through the magic HAL function to see what the problem is.
Posting some images form debugger will not help.
What you need to do:
Get even the cheapest logic analyzer (there are $10 on ebay) and record the communication. See if the slave keeps the clock or data line low. If yes toggle the clock pin 9 times to unblock the line
If nothing helps reset the I2C peripheral using RCC register (it has to be implemented on all connected boards).

Detect device time change ONLY WHEN it is changed manually

Problem: I know about the method applicationSignificantTimeChange to detect manual time change. But the method documentation says:
Examples of significant time changes include the arrival of midnight, an update of the time by a carrier, and the change to daylight savings time. The delegate can implement this method to adjust any object of the application that displays time or is sensitive to time changes.
So it detects not only a manual time change, but arrival of midnight as well. In my application, that will create a problem as the user will see an alertbox:
You have change the time. Please revert back to actual time.
even when he resumes the app after midnight (or may be he minimized the app and went to sleep. Next day he wakes up, resumes the app and surprisingly gets the time change notification).
Question:
How to show the alert only on manual time change and not on arrival of midnight ?
Just use NSSystemClockDidChangeNotification
Apple doc link
I have used a variant of the remote server time check for one or a few years now. It works pretty well, on iOS.
Fetch remote time.
In your time checking class, store the offset between remote time and device time, store that in a simple NSTimeInterval variable.
Now you can get "real time" at any time from your time checking class, because it can take the current device time and just add the stored offset and you will have the real time, all the time.
Whenever the app backgrounds, you will need to delete the stored offset, because the user can be fiddling with the time settings.
For every app foreground event, you will have to perform 3. again. Go get remote time again. Deny any calls to get real time until you have that offset again. Any calls depending on the real time existing will have to fail gracefully in those events where real time has not yet been fetched.
Now the offset you get should/can be compared with the offset you got last time. Decide a threshold, like 15 seconds. If the offset change from last time exceeds that threshold, the user likely changed time manually. This is a useful event for me. Of course even though the user can change the device time I will always have real time handy (most of the time).
Afaik, I always work with UTC time stamps to avoid any locale troubles.
Always its better to check such things with server time.
Follow below steps.
Fetch the server time and convert to current locale.
Check mobile time using current locale.
If they are not same, that means user has changed the time.
Let me know if this is clear or not.