Browse Source

LED四个灯初始化并点亮

樊春春 2 years ago
parent
commit
c490bc803a
6 changed files with 177 additions and 94 deletions
  1. 0 0
      Project/GCC/scripts.py
  2. 27 0
      User/Bsp/LED/led.c
  3. 8 0
      User/Bsp/LED/led.h
  4. 53 4
      User/main.c
  5. 88 90
      User/stm32f4xx_it.c
  6. 1 0
      platformio.ini

+ 0 - 0
Project/GCC/sctipts.py → Project/GCC/scripts.py


+ 27 - 0
User/Bsp/LED/led.c

@@ -0,0 +1,27 @@
+#include "led.h"
+
+void LED_Init(void)
+{
+    /* 1、打开外设时钟 */
+    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOC, ENABLE);
+
+    /* 2、定义GPIO外设初始化结构体 */
+    GPIO_InitTypeDef GPIO_StructInit;
+    /* 3、配置GPIO初始化结构成员*/
+    GPIO_StructInit.GPIO_Mode = GPIO_Mode_OUT;
+    GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
+    GPIO_StructInit.GPIO_Speed = GPIO_Low_Speed;
+    GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
+    GPIO_StructInit.GPIO_Pin = GPIO_Pin_10;
+    /* 4、调用GPIO初始化函数 */
+    GPIO_Init(GPIOI, &GPIO_StructInit);
+
+    GPIO_StructInit.GPIO_Pin = GPIO_Pin_7;
+    GPIO_Init(GPIOF, &GPIO_StructInit);
+
+    GPIO_StructInit.GPIO_Pin = GPIO_Pin_8;
+    GPIO_Init(GPIOF, &GPIO_StructInit);
+
+    GPIO_StructInit.GPIO_Pin = GPIO_Pin_2;
+    GPIO_Init(GPIOC, &GPIO_StructInit);
+}

+ 8 - 0
User/Bsp/LED/led.h

@@ -0,0 +1,8 @@
+#ifndef _LED_H
+#define _LED_H
+
+#include "stm32f4xx.h"
+
+void LED_Init(void);
+
+#endif

+ 53 - 4
User/main.c

@@ -7,7 +7,56 @@
 *********************************************************************************************************
 */
 
-int main(void) {
-    while (1) {
-    }
-}
+#include "stm32f4xx.h"
+
+#include "led.h"
+
+void Delay(uint32_t count)
+{
+    for (; count != 0; count--)
+        ;
+}
+int main(void)
+{
+#if 0
+    /* 打开GOIOI 端口时钟 */
+    *(unsigned int *)(0x40023800 + 0x30) |= (1 << 8);
+
+    /* PI10 为输出 */
+    *(unsigned int *)(0x40022000 + 0x00) &= ~((0x03) << (2 * 10));
+    *(unsigned int *)(0x40022000 + 0x00) |= (1 << (2 * 10));
+
+    /* PI10 输出高电平 */
+    *(unsigned int *)(0x40022000 + 0x14) |= (1 << 10);
+    /* PI10 输出低电平 */
+    *(unsigned int *)(0x40022000 + 0x14) &= ~(1 << 10);
+#elif 1
+    LED_Init();
+    while (1)
+    {
+        GPIO_ResetBits(GPIOI, GPIO_Pin_10);
+        Delay(0xFFFFFFFF);
+        // GPIO_SetBits(GPIOI, GPIO_Pin_10);
+        // Delay(0xFFFFFFFF);
+
+        GPIO_ResetBits(GPIOF, GPIO_Pin_7);
+        Delay(0xFFFFFF);
+        // GPIO_SetBits(GPIOF, GPIO_Pin_7);
+        // Delay(0xFFFFFF);
+
+        GPIO_ResetBits(GPIOF, GPIO_Pin_8);
+        Delay(0xFFFFFF);
+        // GPIO_SetBits(GPIOF, GPIO_Pin_8);
+        // Delay(0xFFFFFF);
+
+        GPIO_ResetBits(GPIOC, GPIO_Pin_2);
+        Delay(0xFFFFFF);
+        // GPIO_SetBits(GPIOC, GPIO_Pin_2);
+        // Delay(0xFFFFFF);
+    };
+#endif
+}
+
+// void SystemInit(void)
+// {
+// }

+ 88 - 90
User/stm32f4xx_it.c

@@ -1,39 +1,38 @@
 /**
-  ******************************************************************************
-  * @file    Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.c 
-  * @author  MCD Application Team
-  * @version V1.5.0
-  * @date    06-March-2015
-  * @brief   Main Interrupt Service Routines.
-  *          This file provides template for all exceptions handler and 
-  *          peripherals interrupt service routine.
-  ******************************************************************************
-  * @attention
-  *
-  * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
-  *
-  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
-  * You may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at:
-  *
-  *        http://www.st.com/software_license_agreement_liberty_v2
-  *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  *
-  ******************************************************************************
-  */
+ ******************************************************************************
+ * @file    Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.c
+ * @author  MCD Application Team
+ * @version V1.5.0
+ * @date    06-March-2015
+ * @brief   Main Interrupt Service Routines.
+ *          This file provides template for all exceptions handler and
+ *          peripherals interrupt service routine.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
+ *
+ * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *        http://www.st.com/software_license_agreement_liberty_v2
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************
+ */
 
 /* Includes ------------------------------------------------------------------*/
 #include "stm32f4xx_it.h"
-#include "main.h"
 
 /** @addtogroup Template_Project
-  * @{
-  */
+ * @{
+ */
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
@@ -47,101 +46,101 @@
 /******************************************************************************/
 
 /**
-  * @brief  This function handles NMI exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles NMI exception.
+ * @param  None
+ * @retval None
+ */
 void NMI_Handler(void)
 {
 }
 
 /**
-  * @brief  This function handles Hard Fault exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles Hard Fault exception.
+ * @param  None
+ * @retval None
+ */
 void HardFault_Handler(void)
 {
-  /* Go to infinite loop when Hard Fault exception occurs */
-  while (1)
-  {
-  }
+    /* Go to infinite loop when Hard Fault exception occurs */
+    while (1)
+    {
+    }
 }
 
 /**
-  * @brief  This function handles Memory Manage exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles Memory Manage exception.
+ * @param  None
+ * @retval None
+ */
 void MemManage_Handler(void)
 {
-  /* Go to infinite loop when Memory Manage exception occurs */
-  while (1)
-  {
-  }
+    /* Go to infinite loop when Memory Manage exception occurs */
+    while (1)
+    {
+    }
 }
 
 /**
-  * @brief  This function handles Bus Fault exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles Bus Fault exception.
+ * @param  None
+ * @retval None
+ */
 void BusFault_Handler(void)
 {
-  /* Go to infinite loop when Bus Fault exception occurs */
-  while (1)
-  {
-  }
+    /* Go to infinite loop when Bus Fault exception occurs */
+    while (1)
+    {
+    }
 }
 
 /**
-  * @brief  This function handles Usage Fault exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles Usage Fault exception.
+ * @param  None
+ * @retval None
+ */
 void UsageFault_Handler(void)
 {
-  /* Go to infinite loop when Usage Fault exception occurs */
-  while (1)
-  {
-  }
+    /* Go to infinite loop when Usage Fault exception occurs */
+    while (1)
+    {
+    }
 }
 
 /**
-  * @brief  This function handles SVCall exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles SVCall exception.
+ * @param  None
+ * @retval None
+ */
 void SVC_Handler(void)
 {
 }
 
 /**
-  * @brief  This function handles Debug Monitor exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles Debug Monitor exception.
+ * @param  None
+ * @retval None
+ */
 void DebugMon_Handler(void)
 {
 }
 
 /**
-  * @brief  This function handles PendSVC exception.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles PendSVC exception.
+ * @param  None
+ * @retval None
+ */
 void PendSV_Handler(void)
 {
 }
 
 /**
-  * @brief  This function handles SysTick Handler.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles SysTick Handler.
+ * @param  None
+ * @retval None
+ */
 void SysTick_Handler(void)
 {
-  TimingDelay_Decrement();
+    // TimingDelay_Decrement();
 }
 
 /******************************************************************************/
@@ -152,17 +151,16 @@ void SysTick_Handler(void)
 /******************************************************************************/
 
 /**
-  * @brief  This function handles PPP interrupt request.
-  * @param  None
-  * @retval None
-  */
+ * @brief  This function handles PPP interrupt request.
+ * @param  None
+ * @retval None
+ */
 /*void PPP_IRQHandler(void)
 {
 }*/
 
 /**
-  * @}
-  */ 
-
+ * @}
+ */
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 1 - 0
platformio.ini

@@ -14,6 +14,7 @@ monitor_speed = 115200
 
 build_flags = 
   -IUser
+  -IUser/BSP/LED
   -ILibraries/CMSIS/Include
   -ILibraries/CMSIS/Device/ST/STM32F4xx/Include
   -ILibraries/STM32F4xx_StdPeriph_Driver/inc