{"id":12111,"date":"2021-05-04T16:15:21","date_gmt":"2021-05-04T16:15:21","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=12111"},"modified":"2021-10-21T09:29:00","modified_gmt":"2021-10-21T09:29:00","slug":"stm32duino-systick","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=12111","title":{"rendered":"STM32duino SysTick"},"content":{"rendered":"<h1>STM32G474RE<\/h1>\n<hr\/>\n<p><!-- -------------------------------------------------------------------------------------- --><\/p>\n<h2>SysTick_Config<\/h2>\n<div><a href=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config-1024x282.png\" alt=\"\" width=\"625\" height=\"172\" class=\"alignleft size-large wp-image-12687\" srcset=\"https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config-1024x282.png 1024w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config-300x83.png 300w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config-768x212.png 768w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config-624x172.png 624w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_Config.png 1205w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/div>\n<h1>STM32G071RB<\/h1>\n<hr\/>\n<p><!-- -------------------------------------------------------------------------------------- --><\/p>\n<h2>Twice initialization<\/h2>\n<div>\n<a href=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init-1024x341.png\" alt=\"\" width=\"625\" height=\"208\" class=\"alignleft size-large wp-image-12112\" srcset=\"https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init-1024x341.png 1024w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init-300x100.png 300w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init-768x256.png 768w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init-1536x511.png 1536w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init-624x208.png 624w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init.png 1823w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a>\n<\/div>\n<div>\n<a href=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2-1024x356.png\" alt=\"\" width=\"625\" height=\"217\" class=\"alignleft size-large wp-image-12121\" srcset=\"https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2-1024x356.png 1024w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2-300x104.png 300w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2-768x267.png 768w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2-1536x535.png 1536w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2-624x217.png 624w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2021\/05\/SysTick_init2.png 1842w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a>\n<\/div>\n<hr\/>\n<p><!-- -------------------------------------------------------------------------------------- --><\/p>\n<h2>Code<\/h2>\n<ul>\n<li><code>HAL_Init()<\/code>:<br \/><code>SystemCoreClock = 16'000'000 Hz = 16 MHz<\/code><\/li>\n<li><code>SystemClock_Config()<\/code>:<br \/><code>SystemCoreClock = 64'000'000 Hz = 64 MHz<\/code><\/li>\n<\/ul>\n<pre class=\"brush: cpp; title: cores\/arduino\/stm32\/stm32_def.h; notranslate\" title=\"cores\/arduino\/stm32\/stm32_def.h\">\r\n#ifndef F_CPU\r\n  #define F_CPU SystemCoreClock\r\n#endif\r\n<\/pre>\n<pre class=\"brush: cpp; title: libraries\/SrcWrapper\/src\/stm32\/hw_config.c; notranslate\" title=\"libraries\/SrcWrapper\/src\/stm32\/hw_config.c\">\r\nvoid hw_config_init(void)\r\n{\r\n  \/* Initialize the HAL *\/\r\n  HAL_Init();\r\n\r\n  \/* Configure the system clock *\/\r\n  SystemClock_Config();\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: system\/STM32G0xx\/system_stm32g0xx.c; notranslate\" title=\"system\/STM32G0xx\/system_stm32g0xx.c\">\r\n\/* The SystemCoreClock variable is updated in three ways:\r\n    1) by calling CMSIS function SystemCoreClockUpdate()\r\n    2) by calling HAL API function HAL_RCC_GetHCLKFreq()\r\n    3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency\r\n       Note: If you use this function to configure the system clock; then there\r\n             is no need to call the 2 first functions listed above, since SystemCoreClock\r\n             variable is updated automatically.\r\n*\/\r\nuint32_t SystemCoreClock = 16000000UL;\r\n<\/pre>\n<pre class=\"brush: cpp; title: system\/Drivers\/STM32G0xx_HAL_Driver\/Src\/stm32g0xx_hal_rcc.c; notranslate\" title=\"system\/Drivers\/STM32G0xx_HAL_Driver\/Src\/stm32g0xx_hal_rcc.c\">\r\nHAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)\r\n{\r\n  &#x5B;...]\r\n\r\n  \/* Update the SystemCoreClock global variable *\/\r\n  SystemCoreClock = (HAL_RCC_GetSysClockFreq() &gt;&gt; ((AHBPrescTable&#x5B;(RCC-&gt;CFGR &amp; RCC_CFGR_HPRE) &gt;&gt; RCC_CFGR_HPRE_Pos]) &amp; 0x1FU));\r\n\r\n  \/* Configure the source of time base considering new system clocks settings*\/\r\n  return HAL_InitTick(uwTickPrio);\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: libraries\/SrcWrapper\/src\/stm32\/clock.c; notranslate\" title=\"libraries\/SrcWrapper\/src\/stm32\/clock.c\">\r\nvoid noOsSystickHandler() { } \/\/ empty\r\n\r\nvoid osSystickHandler() __attribute__((weak, alias(&quot;noOsSystickHandler&quot;)));\r\nvoid SysTick_Handler(void)\r\n{\r\n  HAL_IncTick();\r\n  HAL_SYSTICK_IRQHandler();\r\n  osSystickHandler();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>STM32G474RE SysTick_Config STM32G071RB Twice initialization Code HAL_Init():SystemCoreClock = 16&#8217;000&#8217;000 Hz = 16 MHz SystemClock_Config():SystemCoreClock = 64&#8217;000&#8217;000 Hz = 64 MHz #ifndef F_CPU #define F_CPU SystemCoreClock #endif void hw_config_init(void) { \/* Initialize the HAL *\/ HAL_Init(); \/* Configure the system clock *\/ SystemClock_Config(); } \/* The SystemCoreClock variable is updated in three ways: 1) by calling [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12111","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/12111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12111"}],"version-history":[{"count":12,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/12111\/revisions"}],"predecessor-version":[{"id":12689,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/12111\/revisions\/12689"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}