]> Zhao Yanbai Git Server - acecode.git/commitdiff
F103HAL SysTick
authorAceVest <zhaoyanbai@126.com>
Sat, 1 Jun 2019 10:49:24 +0000 (18:49 +0800)
committerAceVest <zhaoyanbai@126.com>
Sat, 1 Jun 2019 10:49:24 +0000 (18:49 +0800)
learn/stm32/F103HAL/F103HAL.elf.launch
learn/stm32/F103HAL/Src/System.c
learn/stm32/F103HAL/Src/main.c
learn/stm32/F103HAL/Src/stm32f1xx_it.c

index 27e5676eed5fb11862218d5376ee460c6b6dedfd..e5311ff1aaca002d40ad07baf4fd898b7bc20d72 100644 (file)
@@ -42,7 +42,7 @@
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
 <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
 <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
-<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="false"/>
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
@@ -53,7 +53,7 @@
 <stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${TOOLCHAIN_PATH}/arm-none-eabi-gdb"/>
 <booleanAttribute key="org.eclipse.cdt.dsf.gdb.NON_STOP" value="false"/>
 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="remote"/>
-<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="false"/>
 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
 <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/F103HAL.elf"/>
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="F103HAL"/>
index ee1d86b7458e5887d46af918fba08c87ec283ba9..fd0d8f930d177b3512feb746c7a71670ba3e5eef 100644 (file)
@@ -8,9 +8,6 @@
 
 #include "stm32f1xx_hal.h"
 
-void SystemPreInit() {
-
-}
 
 
 #define LED_Pin                GPIO_PIN_6
@@ -42,8 +39,32 @@ void SystemClock_Init() {
        }
 }
 
+void SysTick_Init() {
+       //HAL_SysTick_Init();
+       //HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
+       //HAL_InitTick(0);
+       //HAL_NVIC_EnableIRQ(SysTick_IRQn);
+       //HAL_NVIC_DisableIRQ(SysTick_IRQn);
+       HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
+       HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
+       //HAL_NVIC_ClearPendingIRQ(SysTick_IRQn);
+}
+
+volatile uint32_t SysTicks = 0;
+void SysTick_IRQ_Handler() {
+       SysTicks++;
+       HAL_IncTick();
+}
+
+void Delay(uint32_t n) {
+
+       uint32_t b = SysTicks;
+       while((b+n) > SysTicks);
+}
+
 void GPIO_Init() {
        __HAL_RCC_GPIOB_CLK_ENABLE();
+
        // GPIO 初始化,需要启用相应GPIO Port的时钟
        GPIO_InitTypeDef GPIO_InitStruct;
        GPIO_InitStruct.Mode    = GPIO_MODE_OUTPUT_OD;
@@ -56,16 +77,25 @@ void GPIO_Init() {
 
 void SystemSetup() {
 
+       //__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
        HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2);
 
        SystemClock_Init();
 
+       SysTick_Init();
+
+#if 1
+       __HAL_RCC_AFIO_CLK_ENABLE();
+       //__HAL_RCC_PWR_CLK_ENABLE();
+       __HAL_AFIO_REMAP_SWJ_NOJTAG();
+#endif
+
        GPIO_Init();
 }
 
 void SystemLoop() {
        HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
-       HAL_Delay(1000);
+       Delay(1000);
 }
 
 
index 4a05107ff0a890ff31abcbc4221943fd6762c804..606e216fce02efae9ab92704519b69cd23ef0e08 100644 (file)
@@ -66,8 +66,8 @@ void SystemEntry();
 int main(void)\r
 {\r
   /* USER CODE BEGIN 1 */\r
-       SystemEntry();\r
-       return 0; // never\r
+SystemEntry();\r
+return 0; // never\r
   /* USER CODE END 1 */\r
   \r
 \r
index b770208fb7954c3a6db0c554a8cb8dee439cb542..23e274a0eed54aef168f0bfd56a910804553fb95 100644 (file)
@@ -182,7 +182,8 @@ void PendSV_Handler(void)
 void SysTick_Handler(void)\r
 {\r
   /* USER CODE BEGIN SysTick_IRQn 0 */\r
-\r
+  SysTick_IRQ_Handler();\r
+  return;\r
   /* USER CODE END SysTick_IRQn 0 */\r
   HAL_IncTick();\r
   /* USER CODE BEGIN SysTick_IRQn 1 */\r