Changeset - df3cd2f9bf90
[Not reviewed]
sgp30
0 3 0
matthewreed - 7 years ago 2018-08-25 12:38:32

Started to add support for sgp30
3 files changed with 49 insertions and 3 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
##########################################################################################################################
 
# File automatically-generated by tool: [projectgenerator] version: [2.25.0] date: [Thu Sep 28 21:25:25 EDT 2017]
 
##########################################################################################################################
 
 
# ------------------------------------------------
 
# Generic Makefile (based on gcc)
 
#
 
# ChangeLog :
 
#	2017-02-10 - Several enhancements + project update mode
 
#   2015-07-22 - first version
 
# ------------------------------------------------
 
 
######################################
 
# target
 
######################################
 
TARGET = protomodule-software
 
 
 
######################################
 
# building variables
 
######################################
 
# debug build?
 
DEBUG = 1
 
# optimization
 
OPT = -Og
 
 
 
#######################################
 
# paths
 
#######################################
 
# source path
 
SOURCES_DIR =  \
 
Drivers/CMSIS \
 
Drivers/STM32F0xx_HAL_Driver \
 
Application/MAKEFILE \
 
Application \
 
Application/User \
 
Drivers
 
 
# firmware library path
 
PERIFLIB_PATH = 
 
 
# Build path
 
BUILD_DIR = build
 
 
######################################
 
# source
 
######################################
 
# C sources
 
C_SOURCES =  \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_can.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c \
 
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c \
 
Src/gpio.c \
 
Src/main.c \
 
Src/stm32f0xx_hal_msp.c \
 
Src/stm32f0xx_it.c \
 
Src/system_stm32f0xx.c \
 
Src/system.c \
 
Src/i2c.c \
 
Src/sgp30.c \
 
hydrobot-sharedlibs/src/can_buffer.c \
 
hydrobot-sharedlibs/src/can.c \
 
hydrobot-sharedlibs/src/flash.c \
 
hydrobot-sharedlibs/src/led.c \
 
hydrobot-sharedlibs/src/protocol.c
 
 
# ASM sources
 
ASM_SOURCES =  \
 
startup_stm32f042x6.s
 
 
 
######################################
 
# firmware library
 
######################################
 
PERIFLIB_SOURCES = 
 
 
 
#######################################
 
# binaries
 
#######################################
 
BINPATH = 
 
PREFIX = arm-none-eabi-
 
CC = $(PREFIX)gcc
 
AS = $(PREFIX)gcc -x assembler-with-cpp
 
CP = $(PREFIX)objcopy
 
AR = $(PREFIX)ar
 
SZ = $(PREFIX)size
 
HEX = $(CP) -O ihex
 
BIN = $(CP) -O binary -S
 
 
 
#######################################
 
# CFLAGS
 
#######################################
 
# cpu
 
CPU = -mcpu=cortex-m0
 
 
# fpu
 
# NONE for Cortex-M0/M0+/M3
 
 
# float-abi
 
 
 
# mcu
 
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
 
 
# macros for gcc
 
# AS defines
 
AS_DEFS = 
 
 
# C defines
 
C_DEFS =  \
 
-DUSE_HAL_DRIVER \
 
-DSTM32F042x6
 
 
 
# AS includes
 
AS_INCLUDES = 
 
 
# C includes
 
C_INCLUDES =  \
 
-IInc \
 
-IDrivers/STM32F0xx_HAL_Driver/Inc \
 
-IDrivers/STM32F0xx_HAL_Driver/Inc/Legacy \
 
-IDrivers/CMSIS/Device/ST/STM32F0xx/Include \
 
-IDrivers/CMSIS/Include \
 
-Ihydrobot-sharedlibs/inc
 
 
# compile gcc flags
 
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
 
 
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
 
 
ifeq ($(DEBUG), 1)
 
CFLAGS += -g -gdwarf-2
 
endif
 
 
 
# Generate dependency information
 
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)"
 
 
 
#######################################
 
# LDFLAGS
 
#######################################
 
# link script
 
LDSCRIPT = STM32F042K6Tx_FLASH.ld
 
 
# libraries
 
LIBS = -lc -lm -lnosys
 
LIBDIR =
 
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
 
 
# default action: build all
 
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
 
 
# flash via serial wire debug 
 
flash: all
 
	st-flash --reset write $(BUILD_DIR)/$(TARGET).bin 0x8000000
 
 
#######################################
 
# build the application
 
#######################################
 
# list of objects
 
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
 
vpath %.c $(sort $(dir $(C_SOURCES)))
 
# list of ASM program objects
 
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
 
vpath %.s $(sort $(dir $(ASM_SOURCES)))
 
 
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 
 
	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
 
 
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
 
	$(AS) -c $(CFLAGS) $< -o $@
 
 
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
 
	$(CC) $(OBJECTS) $(LDFLAGS) -o $@
 
	$(SZ) $@
 
 
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
 
	$(HEX) $< $@
 
	
 
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
 
	$(BIN) $< $@	
 
	
 
$(BUILD_DIR):
 
	mkdir $@		
 
 
#######################################
 
# clean up
 
#######################################
 
clean:
 
	-rm -fR .dep $(BUILD_DIR)
 
  
 
#######################################
 
# dependencies
 
#######################################
 
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
 
 
# *** EOF ***
 
\ No newline at end of file
Src/main.c
Show inline comments
 
#include "stm32f0xx_hal.h"
 
#include "can.h"
 
#include "gpio.h"
 
#include "system.h"
 
#include "led.h"
 
#include "protocol.h"
 
 
#include "i2c.h"
 
#include "sgp30.h"
 
 
int main(void)
 
{
 
 
    HAL_Init();
 
    system_init();
 
    gpio_init();
 
    //sgp30_init();
 
    //sgp30_IAQinit();
 
 
    protocol_init(PROTOMODULE);
 
 
    led_init();
 
    led_blink(LED_STATUS, 2000);
 
    led_blink_once(LED_CAN, 2000);
 
    led_set(LED_ERROR, 0);
 
 
    uint32_t loop_timer_1ms = 0;
 
    uint32_t loop_timer_10ms = 0;
 
    uint32_t loop_timer_200ms = 0;
 
    uint32_t loop_timer_1s = 0;
 
    uint32_t loop_timer_2s = 0;
 
    uint32_t loop_timer_data = 0;
 
 
    while (1)
 
    {
 
        can_receive();
 
 
        if (HAL_GetTick() - loop_timer_1ms >= 1)
 
        {
 
            can_process_receive_buffer();
 
            led_update_all();
 
 
            loop_timer_1ms = HAL_GetTick();
 
        }
 
 
        if (HAL_GetTick() - loop_timer_10ms >= 10)
 
        {
 
 
            loop_timer_10ms = HAL_GetTick();
 
        }
 
 
        if (HAL_GetTick() - loop_timer_200ms >= 200)
 
        {
 
 
            loop_timer_200ms = HAL_GetTick();
 
        }
 
 
        if (HAL_GetTick() - loop_timer_1s >= 1000)
 
        {
 
 
            //sgp30_IAQmeasure();
 
            //protocol_send_data(NONE, 0, sgp30_get_tvoc());
 
            loop_timer_1s = HAL_GetTick();
 
        }
 
        if (HAL_GetTick() - loop_timer_2s >= 2000)
 
        {
 
 
            loop_timer_2s = HAL_GetTick();
 
        }
 
        if (HAL_GetTick() - loop_timer_data >= (protocol_get_settings()->val.data_rate))
 
        {
 
 
            loop_timer_data = HAL_GetTick();
 
        }
 
    }
 
 
}
 
 
bool protocol_set_output(protocol_message_t* message)
 
{
 
    bool result = false;
 
 
    return result;
 
}
 
 
bool protocol_get_data(protocol_message_t* message)
 
{
 
    bool result = false;
 
 
    return result;
 
}
 
 
bool protocol_config(protocol_message_t* message)
 
{
 
    bool result = false;
 
    protocol_data_key_t data = (protocol_data_key_t)(uint16_t)message->data.float_data;
 
 
    return result;
 
}
 
 
bool protocol_calibrate(protocol_message_t* message)
 
{
 
    bool result = false;
 
 
    return result;
 
}
Src/stm32f0xx_hal_msp.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * File Name          : stm32f0xx_hal_msp.c
 
  * Description        : This file provides code for the MSP Initialization 
 
  *                      and de-Initialization codes.
 
  ******************************************************************************
 
  ** This notice applies to any and all portions of this file
 
  * that are not between comment pairs USER CODE BEGIN and
 
  * USER CODE END. Other portions of this file, whether 
 
  * inserted by the user or by software development tools
 
  * are owned by their respective copyright owners.
 
  *
 
  * COPYRIGHT(c) 2017 STMicroelectronics
 
  *
 
  * Redistribution and use in source and binary forms, with or without modification,
 
  * are permitted provided that the following conditions are met:
 
  *   1. Redistributions of source code must retain the above copyright notice,
 
  *      this list of conditions and the following disclaimer.
 
  *   2. Redistributions in binary form must reproduce the above copyright notice,
 
  *      this list of conditions and the following disclaimer in the documentation
 
  *      and/or other materials provided with the distribution.
 
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
 
  *      may be used to endorse or promote products derived from this software
 
  *      without specific prior written permission.
 
  *
 
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
  *
 
  ******************************************************************************
 
  */
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32f0xx_hal.h"
 
 
extern void _Error_Handler(char *, int);
 
/* USER CODE BEGIN 0 */
 
 
/* USER CODE END 0 */
 
/**
 
  * Initializes the Global MSP.
 
  */
 
void HAL_MspInit(void)
 
{
 
  /* USER CODE BEGIN MspInit 0 */
 
 
  /* USER CODE END MspInit 0 */
 
 
  __HAL_RCC_SYSCFG_CLK_ENABLE();
 
 
  /* System interrupt init*/
 
  /* SVC_IRQn interrupt configuration */
 
  HAL_NVIC_SetPriority(SVC_IRQn, 0, 0);
 
  /* PendSV_IRQn interrupt configuration */
 
  HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0);
 
  /* SysTick_IRQn interrupt configuration */
 
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
 
 
  /* USER CODE BEGIN MspInit 1 */
 
 
  /* USER CODE END MspInit 1 */
 
}
 
 
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
 
{
 
 
  GPIO_InitTypeDef GPIO_InitStruct;
 
  if(hcan->Instance==CAN)
 
  {
 
  /* USER CODE BEGIN CAN_MspInit 0 */
 
 
  /* USER CODE END CAN_MspInit 0 */
 
    /* Peripheral clock enable */
 
    __HAL_RCC_CAN1_CLK_ENABLE();
 
  
 
    /**CAN GPIO Configuration    
 
    PA11     ------> CAN_RX
 
    PA12     ------> CAN_TX 
 
    */
 
    GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 
    GPIO_InitStruct.Alternate = GPIO_AF4_CAN;
 
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
  /* USER CODE BEGIN CAN_MspInit 1 */
 
 
  /* USER CODE END CAN_MspInit 1 */
 
  }
 
 
}
 
 
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
 
{
 
 
  if(hcan->Instance==CAN)
 
  {
 
  /* USER CODE BEGIN CAN_MspDeInit 0 */
 
 
  /* USER CODE END CAN_MspDeInit 0 */
 
    /* Peripheral clock disable */
 
    __HAL_RCC_CAN1_CLK_DISABLE();
 
  
 
    /**CAN GPIO Configuration    
 
    PA11     ------> CAN_RX
 
    PA12     ------> CAN_TX 
 
    */
 
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
 
 
  /* USER CODE BEGIN CAN_MspDeInit 1 */
 
 
  /* USER CODE END CAN_MspDeInit 1 */
 
  }
 
 
}
 
 
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
 
{
 
 
    GPIO_InitTypeDef GPIO_InitStruct;
 
    if(hi2c->Instance==I2C1)
 
    {
 
        /* USER CODE BEGIN I2C1_MspInit 0 */
 
 
          RCC_PeriphCLKInitTypeDef  RCC_PeriphCLKInitStruct;
 
 
          /*##-1- Configure the I2C clock source. The clock is derived from the SYSCLK #*/
 
          RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
 
          RCC_PeriphCLKInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
 
          HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
 
 
        /* USER CODE END I2C1_MspInit 0 */
 
 
        /**I2C1 GPIO Configuration
 
        PB6     ------> I2C1_SCL
 
        PB7     ------> I2C1_SDA
 
        */
 
 
        GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
 
        GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
 
        GPIO_InitStruct.Pull = GPIO_PULLUP;
 
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 
        GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
 
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
        /* Peripheral clock enable */
 
        __HAL_RCC_I2C1_CLK_ENABLE();
 
        /* USER CODE BEGIN I2C1_MspInit 1 */
 
 
      /* USER CODE END I2C1_MspInit 1 */
 
    }
 
 
}
 
 
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
 
{
 
 
  if(htim_pwm->Instance==TIM1)
 
  {
 
  /* USER CODE BEGIN TIM1_MspInit 0 */
 
 
  /* USER CODE END TIM1_MspInit 0 */
 
    /* Peripheral clock enable */
 
    __HAL_RCC_TIM1_CLK_ENABLE();
 
  /* USER CODE BEGIN TIM1_MspInit 1 */
 
 
  /* USER CODE END TIM1_MspInit 1 */
 
  }
 
 
}
 
 
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
 
{
 
 
  GPIO_InitTypeDef GPIO_InitStruct;
 
  if(htim->Instance==TIM1)
 
  {
 
  /* USER CODE BEGIN TIM1_MspPostInit 0 */
 
 
  /* USER CODE END TIM1_MspPostInit 0 */
 
  
 
    /**TIM1 GPIO Configuration    
 
    PA8     ------> TIM1_CH1
 
    PA9     ------> TIM1_CH2
 
    PA10     ------> TIM1_CH3 
 
    */
 
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 
    GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
 
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
  /* USER CODE BEGIN TIM1_MspPostInit 1 */
 
 
  /* USER CODE END TIM1_MspPostInit 1 */
 
  }
 
 
}
 
 
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
 
{
 
 
  if(htim_pwm->Instance==TIM1)
 
  {
 
  /* USER CODE BEGIN TIM1_MspDeInit 0 */
 
 
  /* USER CODE END TIM1_MspDeInit 0 */
 
    /* Peripheral clock disable */
 
    __HAL_RCC_TIM1_CLK_DISABLE();
 
  /* USER CODE BEGIN TIM1_MspDeInit 1 */
 
 
  /* USER CODE END TIM1_MspDeInit 1 */
 
  }
 
 
}
 
 
/* USER CODE BEGIN 1 */
 
 
/* USER CODE END 1 */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
0 comments (0 inline, 0 general)