car_fmw: straightforward refactoring of MCU GPIO example code
- Extract code to dedicated files, create more abstract interfaces - Remove meaningless comments
This commit is contained in:
+9
-6
@@ -40,22 +40,25 @@ dircs=$(wildcard $(1)/*.c)
|
|||||||
dircs_to_prefxd_objs=\
|
dircs_to_prefxd_objs=\
|
||||||
$(patsubst $(1)/%.c,$(BIN_DIR)/$(2)%.o,$(call dircs,$1))
|
$(patsubst $(1)/%.c,$(BIN_DIR)/$(2)%.o,$(call dircs,$1))
|
||||||
|
|
||||||
$(CAR_FMW_BIN): $(CAR_FMW_ELF)
|
$(CAR_FMW_BIN): $(CAR_FMW_ELF) $(BIN_DIR)
|
||||||
$(OBJ_COPY) -O binary $< $@
|
$(OBJ_COPY) -O binary $< $@
|
||||||
|
|
||||||
$(CAR_FMW_ELF): $(CAR_FMW_OBJ) $(LIB_STM32F4D_OBJ) \
|
$(CAR_FMW_ELF): $(CAR_FMW_OBJ) $(LIB_STM32F4D_OBJ) \
|
||||||
$(LIB_CMSIS_OBJ) $(LIB_STDPERIPH_OBJ)
|
$(LIB_CMSIS_OBJ) $(LIB_STDPERIPH_OBJ)
|
||||||
$(CC) $(CFLAGS) $^ -T $(SRC_DIR)/stm32_flash.ld -o $@
|
$(CC) $(CFLAGS) $^ -T $(SRC_DIR)/stm32_flash.ld -o $@
|
||||||
|
|
||||||
$(CAR_FMW_OBJ): $(BIN_DIR) $(call dircs_to_prefxd_objs,$(SRC_DIR))
|
CAR_OBJ_PREFIX=car_
|
||||||
|
$(CAR_FMW_OBJ): \
|
||||||
|
$(call dircs_to_prefxd_objs,$(SRC_DIR),$(CAR_OBJ_PREFIX))
|
||||||
$(LD_ALL_DEPS)
|
$(LD_ALL_DEPS)
|
||||||
|
|
||||||
|
$(BIN_DIR)/$(CAR_OBJ_PREFIX)%.o: $(SRC_DIR)/%.c \
|
||||||
|
$(call dirhs,$(SRC_DIR))
|
||||||
|
$(CC_ALL_DEPS)
|
||||||
|
|
||||||
$(BIN_DIR):
|
$(BIN_DIR):
|
||||||
mkdir -p $(BIN_DIR)
|
mkdir -p $(BIN_DIR)
|
||||||
|
|
||||||
$(BIN_DIR)/%.o: $(SRC_DIR)/%.c
|
|
||||||
$(CC_ALL_DEPS)
|
|
||||||
|
|
||||||
flash: $(CAR_FMW_BIN)
|
flash: $(CAR_FMW_BIN)
|
||||||
$(ST_DIR)/st-flash write $(CAR_FMW_BIN) 0x8000000
|
$(ST_DIR)/st-flash write $(CAR_FMW_BIN) 0x8000000
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include "stm32f4_discovery.h"
|
||||||
|
#include "stm32f4xx_conf.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void assert_failed(uint8_t* file, uint32_t line)
|
||||||
|
{
|
||||||
|
/* User can add his own implementation to report the file name and line number,
|
||||||
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
|
|
||||||
|
/* Infinite loop */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "stm32f4_discovery.h"
|
||||||
|
#include "stm32f4xx_conf.h"
|
||||||
|
|
||||||
|
#define CAR_LED_GPIO_PORT_CLOCK RCC_AHB1Periph_GPIOD
|
||||||
|
#define CAR_LED_GPIO_PORT GPIOD
|
||||||
|
#define CAR_LED_PIN_GREEN GPIO_Pin_12
|
||||||
|
#define CAR_LED_PIN_ORANGE GPIO_Pin_13
|
||||||
|
#define CAR_LED_PIN_RED GPIO_Pin_14
|
||||||
|
#define CAR_LED_PIN_BLUE GPIO_Pin_15
|
||||||
|
|
||||||
|
inline void leds_init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
RCC_AHB1PeriphClockCmd(CAR_LED_GPIO_PORT_CLOCK, ENABLE);
|
||||||
|
GPIO_InitStructure.GPIO_Pin = CAR_LED_PIN_GREEN
|
||||||
|
| CAR_LED_PIN_ORANGE
|
||||||
|
| CAR_LED_PIN_RED
|
||||||
|
| CAR_LED_PIN_BLUE;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_Init(CAR_LED_GPIO_PORT, &GPIO_InitStructure);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LED_GREEN,
|
||||||
|
LED_ORANGE,
|
||||||
|
LED_RED,
|
||||||
|
LED_BLUE
|
||||||
|
} led_t;
|
||||||
|
|
||||||
|
inline void led_set(led_t led, bool on)
|
||||||
|
{
|
||||||
|
int led_pin = CAR_LED_PIN_GREEN;
|
||||||
|
switch(led) {
|
||||||
|
case LED_ORANGE:
|
||||||
|
led_pin = CAR_LED_PIN_ORANGE;
|
||||||
|
break;
|
||||||
|
case LED_RED:
|
||||||
|
led_pin = CAR_LED_PIN_RED;
|
||||||
|
break;
|
||||||
|
case LED_BLUE:
|
||||||
|
led_pin = CAR_LED_PIN_BLUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (on)
|
||||||
|
GPIO_SetBits(CAR_LED_GPIO_PORT, led_pin);
|
||||||
|
else
|
||||||
|
GPIO_ResetBits(CAR_LED_GPIO_PORT, led_pin);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stm32f4_discovery.h"
|
||||||
|
#include "stm32f4xx_conf.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Delay Function.
|
||||||
|
* @param nCount:specifies the Delay time length.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
inline void Delay(__IO uint32_t nCount)
|
||||||
|
{
|
||||||
|
while(nCount--)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,5 +5,5 @@ $(LIB_STDPERIPH_OBJ): \
|
|||||||
$(LD_ALL_DEPS)
|
$(LD_ALL_DEPS)
|
||||||
|
|
||||||
$(BIN_DIR)/$(LIB_STDPRPH_OBJ_PREFIX)%.o: $(LIB_STDPERIPH_DIR)/%.c \
|
$(BIN_DIR)/$(LIB_STDPRPH_OBJ_PREFIX)%.o: $(LIB_STDPERIPH_DIR)/%.c \
|
||||||
$(call dirhs, $(LIB_STDPERIPH_DIR))
|
$(call dirhs,$(LIB_STDPERIPH_DIR))
|
||||||
$(CC_ALL_DEPS)
|
$(CC_ALL_DEPS)
|
||||||
|
|||||||
+21
-133
@@ -1,143 +1,31 @@
|
|||||||
/**
|
#include "car_leds.h"
|
||||||
******************************************************************************
|
#include "delay.h"
|
||||||
* @file IO_Toggle/main.c
|
|
||||||
* @author MCD Application Team
|
|
||||||
* @version V1.0.0
|
|
||||||
* @date 19-September-2011
|
|
||||||
* @brief Main program body
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
|
||||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
|
||||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
|
||||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
|
||||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
|
||||||
*
|
|
||||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "stm32f4_discovery.h"
|
|
||||||
#include "stm32f4xx_conf.h"
|
|
||||||
|
|
||||||
/** @addtogroup STM32F4_Discovery_Peripheral_Examples
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup IO_Toggle
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
void Delay(__IO uint32_t nCount);
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Main program
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/*!< At this stage the microcontroller clock setting is already configured,
|
/*!< At this stage the microcontroller clock setting is already configured,
|
||||||
this is done through SystemInit() function which is called from startup
|
this is done through SystemInit() function which is called from startup
|
||||||
file (startup_stm32f4xx.s) before to branch to application main.
|
file (startup_stm32f4xx.s) before to branch to application main.
|
||||||
To reconfigure the default setting of SystemInit() function, refer to
|
To reconfigure the default setting of SystemInit() function, refer to
|
||||||
system_stm32f4xx.c file
|
system_stm32f4xx.c file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* GPIOD Periph clock enable */
|
leds_init();
|
||||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
|
||||||
|
|
||||||
/* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
|
while (1)
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
|
{
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
led_set(LED_GREEN, true);
|
||||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
Delay(0x3FFFFF);
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
led_set(LED_ORANGE, true);
|
||||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
Delay(0x3FFFFF);
|
||||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
led_set(LED_RED, true);
|
||||||
|
Delay(0x3FFFFF);
|
||||||
while (1)
|
led_set(LED_BLUE, true);
|
||||||
{
|
Delay(0x7FFFFF);
|
||||||
/* PD12 to be toggled */
|
led_set(LED_GREEN, false);
|
||||||
GPIO_SetBits(GPIOD, GPIO_Pin_12);
|
led_set(LED_ORANGE, false);
|
||||||
|
led_set(LED_RED, false);
|
||||||
/* Insert delay */
|
led_set(LED_BLUE, false);
|
||||||
Delay(0x3FFFFF);
|
Delay(0xFFFFFF);
|
||||||
|
}
|
||||||
/* PD13 to be toggled */
|
|
||||||
GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
|
||||||
|
|
||||||
/* Insert delay */
|
|
||||||
Delay(0x3FFFFF);
|
|
||||||
|
|
||||||
/* PD14 to be toggled */
|
|
||||||
GPIO_SetBits(GPIOD, GPIO_Pin_14);
|
|
||||||
|
|
||||||
/* Insert delay */
|
|
||||||
Delay(0x3FFFFF);
|
|
||||||
|
|
||||||
/* PD15 to be toggled */
|
|
||||||
GPIO_SetBits(GPIOD, GPIO_Pin_15);
|
|
||||||
|
|
||||||
/* Insert delay */
|
|
||||||
Delay(0x7FFFFF);
|
|
||||||
|
|
||||||
GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
|
|
||||||
|
|
||||||
/* Insert delay */
|
|
||||||
Delay(0xFFFFFF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Delay Function.
|
|
||||||
* @param nCount:specifies the Delay time length.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void Delay(__IO uint32_t nCount)
|
|
||||||
{
|
|
||||||
while(nCount--)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reports the name of the source file and the source line number
|
|
||||||
* where the assert_param error has occurred.
|
|
||||||
* @param file: pointer to the source file name
|
|
||||||
* @param line: assert_param error line source number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void assert_failed(uint8_t* file, uint32_t line)
|
|
||||||
{
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
|
|
||||||
/* Infinite loop */
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user