首先看了官方给的代码,看了好几遍,总结一个字,烂! 再看看驱动RGB灯的代码,发送clk的子函数都是几十毫秒的延时,点亮一个RGB等全过程需要1S以上。从cpu利用率上来讲,这是无法容忍的! 所以必须使用RTOS,否则延时的时候,CPU没法做其他事情了。 1. 由于公司电脑不允许安装MDK,所以用IAR工程,IAR的编译效率高,编译速度也快。 移植步骤就不说了,网上一搜很多,我就直接把移植好的工程传上来,供大家直接使用! 2. 关于底板灯的驱动,原理图的标号与PCB的丝印有些出入,这里必须指出,看了十几遍sch,发现了很多错误不严谨的地方(有一个吐槽贴说的也是这个:这个板绝对是软件工程师画的) 现在修改led驱动如下: pcb上的丝印与原理图的标号不一致:
pb1--led4(sch)--led4(pcb)
pb11--led5(sch)--led3(pcb)
pb14--led6(sch)--led2(pcb)
pb15--led7(sch)--led1(pcb)
为了使用户更直观,统一采用丝印上的led标号为标准。- #ifndef __BSP_GOKIT_LED_H
- #define __BSP_GOKIT_LED_H
- #include "stm32f10x.h"
- typedef enum
- {
- LED1 ,
- LED2 , //
- LED3 , //
- LED4 //
- } Led_TypeDef;
- // 移植的时候只需修改这里,无需修改函数
- /* 移植的时候特别注意:
- 说明:swd调试会占用2个IO口,即:swdio--pa13 swclk--pa14
- 实际连接stlink需要4根线 Target_VCC GND SWDIO SWCLK */
- #define GPIO_LED1_CLK RCC_APB2Periph_GPIOB
- #define GPIO_LED1_PORT GPIOB
- #define GPIO_LED1_PIN GPIO_Pin_15
- #define GPIO_LED2_CLK RCC_APB2Periph_GPIOB
- #define GPIO_LED2_PORT GPIOB
- #define GPIO_LED2_PIN GPIO_Pin_14
- #define GPIO_LED3_CLK RCC_APB2Periph_GPIOB
- #define GPIO_LED3_PORT GPIOB
- #define GPIO_LED3_PIN GPIO_Pin_11
- #define GPIO_LED4_CLK RCC_APB2Periph_GPIOB
- #define GPIO_LED4_PORT GPIOB
- #define GPIO_LED4_PIN GPIO_Pin_1
- #define LED1_ON() GPIO_ResetBits(GPIO_LED1_PORT, GPIO_LED1_PIN)
- #define LED1_OFF() GPIO_SetBits(GPIO_LED1_PORT,GPIO_LED1_PIN)
- #define LED2_OFF() GPIO_ResetBits(GPIO_LED2_PORT, GPIO_LED2_PIN)
- #define LED2_ON() GPIO_SetBits(GPIO_LED2_PORT,GPIO_LED2_PIN)
- #define LED3_OFF() GPIO_ResetBits(GPIO_LED3_PORT, GPIO_LED3_PIN)
- #define LED3_ON() GPIO_SetBits(GPIO_LED3_PORT,GPIO_LED3_PIN)
- #define LED4_ON() GPIO_ResetBits(GPIO_LED4_PORT, GPIO_LED4_PIN)
- #define LED4_OFF() GPIO_SetBits(GPIO_LED4_PORT,GPIO_LED4_PIN)
- void LED_Toggle(Led_TypeDef LEDX);
-
- void BSP_LED_Init(void);//初始化
复制代码
- /**
- ******************************************************************************
- * @file BSP_Led.c
- * @author casy@ganx
- * @version V1.0
- * @Board stm32
- * @date 2014/12/29
- * 说明: 此c文件提供LED显示模块包含的所有函数功能
- pcb上的丝印与原理图的标号不一致:
- pb1--led4(sch)--led4(pcb)
- pb11--led5(sch)--led3(pcb)
- pb14--led6(sch)--led2(pcb)
- pb15--led7(sch)--led1(pcb)
- 为了使用户更直观,统一采用丝印上的led标号为标准。
- ******************************************************************************/
- #include "bsp_gokit_led.h"
- /**
- ********************************************************
- * 函数名:void BSP_LED_Init(void)
- * 说明:LED初始化,LED4,LED5,LED6,LED7 high level Light on
- * 输入参数:void
- * 输出参数:void
- ********************************************************
- */
- void BSP_LED_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(GPIO_LED1_CLK | GPIO_LED2_CLK | GPIO_LED3_CLK | GPIO_LED4_CLK, ENABLE);
-
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- GPIO_InitStructure.GPIO_Pin = GPIO_LED1_PIN;
- GPIO_Init(GPIO_LED1_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_LED2_PIN;
- GPIO_Init(GPIO_LED2_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_LED3_PIN;
- GPIO_Init(GPIO_LED3_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_LED4_PIN;
- GPIO_Init(GPIO_LED4_PORT, &GPIO_InitStructure);
-
- }
- void LED_Toggle(Led_TypeDef LEDX)
- {
-
- switch(LEDX)
- {
- case LED1:
- if((uint8_t)Bit_SET == GPIO_ReadOutputDataBit(GPIO_LED1_PORT, GPIO_LED1_PIN))
- GPIO_ResetBits(GPIO_LED1_PORT,GPIO_LED1_PIN) ;
- else
- GPIO_SetBits(GPIO_LED1_PORT,GPIO_LED1_PIN);
- break;
-
- case LED2:
- if((uint8_t)Bit_SET == GPIO_ReadOutputDataBit(GPIO_LED2_PORT, GPIO_LED2_PIN))
- GPIO_ResetBits(GPIO_LED2_PORT,GPIO_LED2_PIN) ;
- else
- GPIO_SetBits(GPIO_LED2_PORT,GPIO_LED2_PIN);
- break;
-
- case LED3:
- if((uint8_t)Bit_SET == GPIO_ReadOutputDataBit(GPIO_LED3_PORT, GPIO_LED3_PIN))
- GPIO_ResetBits(GPIO_LED3_PORT,GPIO_LED3_PIN) ;
- else
- GPIO_SetBits(GPIO_LED3_PORT,GPIO_LED3_PIN);
- break;
-
- case LED4:
- if((uint8_t)Bit_SET == GPIO_ReadOutputDataBit(GPIO_LED4_PORT, GPIO_LED4_PIN))
- GPIO_ResetBits(GPIO_LED4_PORT,GPIO_LED4_PIN) ;
- else
- GPIO_SetBits(GPIO_LED4_PORT,GPIO_LED4_PIN);
- break;
-
- default:
- break;
- }
- }
复制代码
|