]> Zhao Yanbai Git Server - acecode.git/commitdiff
SysTick Delay
authorAceVest <zhaoyanbai@126.com>
Mon, 27 May 2019 08:32:16 +0000 (16:32 +0800)
committerAceVest <zhaoyanbai@126.com>
Mon, 27 May 2019 08:32:16 +0000 (16:32 +0800)
learn/stm32/F103/.settings/language.settings.xml
learn/stm32/F103/F103 Run.cfg
learn/stm32/F103/src/main.c
learn/stm32/F103/src/systick.c
learn/stm32/F103/src/systick.h

index f90e2ce695085a5ce049ad58f9b9249ef19d590d..5ccf38dffbced7ffc1c614f37f44640209d212a6 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-                       <provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1540645472206959902" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1481427363850259294" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
@@ -16,7 +16,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-                       <provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1540645472206959902" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-1481427363850259294" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 0102e6a2a2ee7aa4c352e0ad603c9de206eaf6fd..023afefd6c6dd3178d632afef9258f91115627cb 100644 (file)
@@ -3,7 +3,7 @@
 # Generated by System Workbench for STM32\r
 # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)\r
 \r
-source [find interface/stlink-tcp.cfg]\r
+source [find interface/stlink.cfg]\r
 \r
 set WORKAREASIZE 0x5000\r
 \r
index e87669de4979e956846623acaad161eb23490272..20439a69372d1b12564e4259faadbf64be57c25d 100644 (file)
@@ -19,6 +19,8 @@ unsigned int pin = 9;
 void SystemInit() {
        InitSystemClock();
 
+       InitSysTick();
+
        // 使能时钟
        RCCEnableGPIOBClock();
 
@@ -26,10 +28,7 @@ void SystemInit() {
 }
 
 void delay() {
-       Delay();
-       return;
-       int i=965536;
-       while(i--);
+       Delay(200);
 }
 
 int main() {
index 646efc645df7aa65585f5ff1d0d23ef48eaaf017..6fd6a4f840a3106a704454464cc623b557ec24d3 100644 (file)
 #define SYSTICK_CTRL_ENABLE_MASK       (1 << SYSTICK_CTRL_ENABLE_POS)
 #define SYSTICK_CTRL_ENABLE            (1 << SYSTICK_CTRL_ENABLE_POS)
 
-void Delay() {
+uint32_t gSysTickCnt = 0;
+void SysTick_Handler() {
+       gSysTickCnt++;
+}
+
+// 每1ms触发一次SysTick中断
+void InitSysTick() {
+       SysTick->CTRL &= ~SYSTICK_CTRL_ENABLE_MASK;
+       SysTick->CTRL &= ~SYSTICK_CTRL_TICKINT_MASK;
+       SysTick->CTRL &= ~SYSTICK_CTRL_CLKSOURCE_MASK;
+
+
+       SysTick->LOAD = 9000;
+       SysTick->VAL  = 0;
+
+
+       SysTick->CTRL |= SYSTICK_CTRL_ENABLE | SYSTICK_CTRL_TICKINT_ENABLE;
+}
+
+void Delay(uint32_t ms) {
+       gSysTickCnt = 0;
+       while(gSysTickCnt < ms) {
+
+       }
+}
+
+// 非中断版本的Delay
+// ms 最大值为1864
+void NoneIntDelay(uint32_t ms) {
        SysTick->CTRL &= ~SYSTICK_CTRL_ENABLE_MASK;
        SysTick->CTRL &= ~SYSTICK_CTRL_TICKINT_MASK;
        SysTick->CTRL &= ~SYSTICK_CTRL_CLKSOURCE_MASK;
 
 
-       SysTick->LOAD = 9000*1000; // 1000ms
+       SysTick->LOAD = 9000*ms;
        SysTick->VAL  = 0;
 
 
index ac32069875681212a565a9bb1d8436034258d0e8..51821b34773006f0ae472ee48df848ef15bb4e78 100644 (file)
@@ -20,6 +20,7 @@ typedef struct {
 
 #define SysTick ((SysTick_t*) 0xE000E010)
 
-
-void Delay();
+void InitSysTick();
+void Delay(uint32_t ms);
+void NoneIntDelay(uint32_t ms);
 #endif /* SYSTICK_H_ */