{"action":"opened","issue":{"url":"https://api.github.com/repos/espruino/Espruino/issues/776","labels_url":"https://api.github.com/repos/espruino/Espruino/issues/776/labels{/name}","comments_url":"https://api.github.com/repos/espruino/Espruino/issues/776/comments","events_url":"https://api.github.com/repos/espruino/Espruino/issues/776/events","html_url":"https://github.com/espruino/Espruino/issues/776","id":124861929,"number":776,"title":"RTCPrescaler for LSI should be 30000 for 30kHz LSI on Pico micro controller (STM32F401CD)","user":{"login":"dmcnaugh","id":3985508,"avatar_url":"https://avatars.githubusercontent.com/u/3985508?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcnaugh","html_url":"https://github.com/dmcnaugh","followers_url":"https://api.github.com/users/dmcnaugh/followers","following_url":"https://api.github.com/users/dmcnaugh/following{/other_user}","gists_url":"https://api.github.com/users/dmcnaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcnaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcnaugh/subscriptions","organizations_url":"https://api.github.com/users/dmcnaugh/orgs","repos_url":"https://api.github.com/users/dmcnaugh/repos","events_url":"https://api.github.com/users/dmcnaugh/events{/privacy}","received_events_url":"https://api.github.com/users/dmcnaugh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-04T23:23:07Z","updated_at":"2016-01-04T23:23:07Z","closed_at":null,"body":"In Espruino/targets/stm32/jshardware.c\r\nhttps://github.com/espruino/Espruino/blob/master/targets/stm32/jshardware.c\r\nin the following code (lines: 667-680) the RTCPrescaler is set to 32768 assuming 32kHz for LSI on the Pico micro controller (STM32F401CD)\r\n\r\n```C++\r\n#ifdef USE_RTC\r\nvoid jshSetupRTCPrescaler(bool isUsingLSI) {\r\n  if (isUsingLSI) {\r\n#ifdef STM32F1\r\n    jshRTCPrescaler = 40000; // 40kHz for LSI on F1 parts\r\n#else\r\n    jshRTCPrescaler = 32768; // 32kHz for LSI\r\n#endif\r\n  } else {\r\n    jshRTCPrescaler = 32768; // 32kHz for LSE\r\n  }\r\n  jshRTCPrescalerReciprocal = (unsigned short)((((unsigned int)JSSYSTIME_SECOND) << RTC_PRESCALER_RECIPROCAL_SHIFT) /  jshRTCPrescaler);\r\n}\r\n#endif\r\n```\r\n\r\nOn the 7th line \r\n\r\n```C++\r\n    jshRTCPrescaler = 32768; // 32kHz for LSI\r\n```\r\n\r\nAccording to the reference manual for the STM32F401 http://www.st.com/web/en/catalog/mmc/SC1169/SS1577/LN1810\r\nthe LSI frequency is 30kHz, requiring the RTCPrescaler to be set to 30000 as follows:\r\n\r\n```C++\r\n    jshRTCPrescaler = 30000; // 30kHz for LSI\r\n```\r\n\r\nWhat led me to look into this is noticing that the time on my Pico looses approximately 1 second every minute (without an external 32.768 kHz crystal attached). If you do the maths, this slip corresponds approximately to the delta in the prescaler.\r\n\r\nAny chance this change can be made in the next release of the firmware, assuming it doesn't cause any other negative side effects?"}}