diff --git a/car_fmw/Makefile b/car_fmw/Makefile index 916839c80ea..224ffaaf10b 100644 --- a/car_fmw/Makefile +++ b/car_fmw/Makefile @@ -40,22 +40,25 @@ dircs=$(wildcard $(1)/*.c) dircs_to_prefxd_objs=\ $(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 $< $@ $(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 $@ -$(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) +$(BIN_DIR)/$(CAR_OBJ_PREFIX)%.o: $(SRC_DIR)/%.c \ + $(call dirhs,$(SRC_DIR)) + $(CC_ALL_DEPS) + $(BIN_DIR): mkdir -p $(BIN_DIR) -$(BIN_DIR)/%.o: $(SRC_DIR)/%.c - $(CC_ALL_DEPS) - flash: $(CAR_FMW_BIN) $(ST_DIR)/st-flash write $(CAR_FMW_BIN) 0x8000000 diff --git a/car_fmw/src/assert.c b/car_fmw/src/assert.c new file mode 100644 index 00000000000..43decf8acfd --- /dev/null +++ b/car_fmw/src/assert.c @@ -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) + { + } +} diff --git a/car_fmw/src/car_leds.h b/car_fmw/src/car_leds.h new file mode 100644 index 00000000000..1d0992d6709 --- /dev/null +++ b/car_fmw/src/car_leds.h @@ -0,0 +1,58 @@ +#pragma once + +#include + +#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); +} + diff --git a/car_fmw/src/delay.h b/car_fmw/src/delay.h new file mode 100644 index 00000000000..492981a32aa --- /dev/null +++ b/car_fmw/src/delay.h @@ -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--) + { + } +} diff --git a/car_fmw/src/lib/stdperiph/Makefile b/car_fmw/src/lib/stdperiph/Makefile index dbefcf6426a..f9452148b9c 100644 --- a/car_fmw/src/lib/stdperiph/Makefile +++ b/car_fmw/src/lib/stdperiph/Makefile @@ -5,5 +5,5 @@ $(LIB_STDPERIPH_OBJ): \ $(LD_ALL_DEPS) $(BIN_DIR)/$(LIB_STDPRPH_OBJ_PREFIX)%.o: $(LIB_STDPERIPH_DIR)/%.c \ - $(call dirhs, $(LIB_STDPERIPH_DIR)) + $(call dirhs,$(LIB_STDPERIPH_DIR)) $(CC_ALL_DEPS) diff --git a/car_fmw/src/main.c b/car_fmw/src/main.c index 5da875ffb82..6e0b1a3f6dc 100644 --- a/car_fmw/src/main.c +++ b/car_fmw/src/main.c @@ -1,143 +1,31 @@ -/** - ****************************************************************************** - * @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. - * - *

© COPYRIGHT 2011 STMicroelectronics

- ****************************************************************************** - */ +#include "car_leds.h" +#include "delay.h" -/* 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) { - /*!< 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 file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to - system_stm32f4xx.c file + system_stm32f4xx.c file */ - /* GPIOD Periph clock enable */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); + leds_init(); - /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */ - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - while (1) - { - /* PD12 to be toggled */ - GPIO_SetBits(GPIOD, GPIO_Pin_12); - - /* Insert delay */ - Delay(0x3FFFFF); - - /* 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); - } + while (1) + { + led_set(LED_GREEN, true); + Delay(0x3FFFFF); + led_set(LED_ORANGE, true); + Delay(0x3FFFFF); + led_set(LED_RED, true); + Delay(0x3FFFFF); + led_set(LED_BLUE, true); + Delay(0x7FFFFF); + led_set(LED_GREEN, false); + led_set(LED_ORANGE, false); + led_set(LED_RED, false); + led_set(LED_BLUE, false); + 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****/