Changeset - 4202475a7575
[Not reviewed]
default
3 8 2
Ethan Zonca - 10 years ago 2016-03-25 22:55:08
ez@ethanzonca.com
Refactor and remove garbage
11 files changed with 25 insertions and 491 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
# STM32F0xx Makefile
 
# #####################################
 
#
 
# Part of the uCtools project
 
# uctools.github.com
 
#
 
#######################################
 
# user configuration:
 
#######################################
 

	
 
BUILD_NUMBER ?= 0
 

	
 
# SOURCES: list of sources in the user application
 
SOURCES = main.c system_stm32f0xx.c adc.c dma.c gpio.c i2c.c stm32f0xx_hal_msp.c stm32f0xx_it.c usart.c  gps.c
 
SOURCES = main.c system_stm32f0xx.c adc.c dma.c gpio.c i2c.c interrupts.c usart.c  gps.c
 

	
 
# TARGET: name of the user application
 
TARGET = wsprhab-b$(BUILD_NUMBER)
 

	
 
# BUILD_DIR: directory to place output files in
 
BUILD_DIR = build
 

	
 
# LD_SCRIPT: location of the linker script
 
LD_SCRIPT = STM32F031G6_FLASH.ld
 

	
 
# USER_DEFS user defined macros
 
USER_DEFS = -D HSE_VALUE=16000000
 
USER_DEFS += -D WSPRHAB_BUILD_NUMBER=$(BUILD_NUMBER)
 

	
 
# USER_INCLUDES: user defined includes
 
USER_INCLUDES =
 

	
 
# USB_INCLUDES: includes for the usb library
 
# USB_INCLUDES = -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc
 
#USB_INCLUDES += -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
 

	
 
SI5351_INCLUDES = -Ilib/si5351
 

	
 
JTENCODE_INCLUDES = -Ilib/jtencode
 

	
 
# USER_CFLAGS: user C flags (enable warnings, enable debug info)
 
USER_CFLAGS = -Wall -g -ffunction-sections -fdata-sections -Os -fno-common --function-sections -fdata-sections -flto
 
# USER_LDFLAGS:  user LD flags
 
USER_LDFLAGS = -flto -fno-exceptions -ffunction-sections -fdata-sections -Wl,--gc-sections 
 
USER_LDFLAGS += --static
 
#USER_LDFLAGS += -nostartfiles 
 

	
 
# TARGET_DEVICE: device to compile for
 
TARGET_DEVICE = STM32F031x6
 

	
 
#######################################
 
# end of user configuration
 
#######################################
 
#
 
#######################################
 
# binaries
 
#######################################
 
CC = arm-none-eabi-gcc
 
AR = arm-none-eabi-ar
 
RANLIB = arm-none-eabi-ranlib
 
SIZE = arm-none-eabi-size
 
OBJCOPY = arm-none-eabi-objcopy
 
MKDIR = mkdir -p
 
#######################################
 

	
 
# core and CPU type for Cortex M0
 
# ARM core type (CORE_M0, CORE_M3)
 
CORE = CORE_M0
 
# ARM CPU type (cortex-m0, cortex-m3)
 
CPU = cortex-m0
 

	
 
# where to build STM32Cube
 
CUBELIB_BUILD_DIR = $(BUILD_DIR)/STM32Cube
 

	
 
# various paths within the STmicro library
 
CMSIS_PATH = drivers/CMSIS
 
CMSIS_DEVICE_PATH = $(CMSIS_PATH)/Device/ST/STM32F0xx
 
DRIVER_PATH = drivers/STM32F0xx_HAL_Driver
 

	
 

	
 
# includes for gcc
 
INCLUDES = -I$(CMSIS_PATH)/Include
 
INCLUDES += -I$(CMSIS_DEVICE_PATH)/Include
 
INCLUDES += -I$(DRIVER_PATH)/Inc
 
INCLUDES += -Iinc
 
#INCLUDES += $(USB_INCLUDES)
 
INCLUDES += $(USER_INCLUDES)
 
INCLUDES += $(SI5351_INCLUDES)
 
INCLUDES += $(JTENCODE_INCLUDES)
 

	
 

	
 
# macros for gcc
 
DEFS = -D$(CORE) $(USER_DEFS) -D$(TARGET_DEVICE)
 

	
 
# compile gcc flags
 
CFLAGS = $(DEFS) $(INCLUDES)
 
# EMZ: Maybe remove -msoft-float
 
CFLAGS += -mcpu=$(CPU) -mthumb -msoft-float
 
CFLAGS += $(USER_CFLAGS)
 

	
 
# default action: build the user application
 
all: $(BUILD_DIR)/$(TARGET).bin $(BUILD_DIR)/$(TARGET).hex
 

	
 
flash: all
 
	st-flash write $(BUILD_DIR)/$(TARGET).bin 0x8000000
 

	
 

	
 
#######################################
 
# build the st micro peripherial library
 
# (drivers and CMSIS)
 
#######################################
 

	
 
CUBELIB = $(CUBELIB_BUILD_DIR)/libstm32cube.a
 

	
 
# List of stm32 driver objects
 
CUBELIB_DRIVER_OBJS = $(addprefix $(CUBELIB_BUILD_DIR)/, $(patsubst %.c, %.o, $(notdir $(wildcard $(DRIVER_PATH)/Src/*.c))))
 

	
 
# shortcut for building core library (make cubelib)
 
cubelib: $(CUBELIB)
 

	
 
$(CUBELIB): $(CUBELIB_DRIVER_OBJS)
 
	$(AR) rv $@ $(CUBELIB_DRIVER_OBJS)
 
	$(RANLIB) $@
 

	
 
$(CUBELIB_BUILD_DIR)/%.o: $(DRIVER_PATH)/Src/%.c | $(CUBELIB_BUILD_DIR)
 
	$(CC) -c $(CFLAGS) -o $@ $^
 

	
 
$(CUBELIB_BUILD_DIR):
 
	$(MKDIR) $@
 

	
 
#######################################
 
# build the USB library
 
#######################################
 
#USB_MIDDLEWARE_PATH = ./Middlewares/ST/STM32_USB_Device_Library/
 
#USB_BUILD_DIR = $(BUILD_DIR)/usb
 
#USB_SOURCES += usbd_ctlreq.c usbd_ioreq.c usbd_core.c usbd_cdc.c
 
# list of usb library objects
 
#USB_OBJECTS += $(addprefix $(USB_BUILD_DIR)/,$(notdir $(USB_SOURCES:.c=.o)))
 

	
 
#usb: $(USB_OBJECTS)
 

	
 
#$(USB_BUILD_DIR)/%.o: $(USB_MIDDLEWARE_PATH)/Core/Src/%.c | $(USB_BUILD_DIR)
 
#	$(CC) -Os $(CFLAGS) -c -o $@ $^
 
#
 
#$(USB_BUILD_DIR)/%.o: $(USB_MIDDLEWARE_PATH)/Class/CDC/Src/%.c | $(USB_BUILD_DIR)
 
#	$(CC) -Os $(CFLAGS) -c -o $@ $^
 

	
 
#$(USB_BUILD_DIR):
 
#	@echo $(USB_BUILD_DIR)
 
#	$(MKDIR) $@
 

	
 

	
 
#######################################
 
# build the user libraries
 
#######################################
 

	
 
# si5351
 
SI5351_PATH = ./lib/si5351/
 
SI5351_BUILD_DIR = $(BUILD_DIR)/si5351
 
SI5351_SOURCES += si5351.c
 

	
 
SI5351_OBJECTS += $(addprefix $(SI5351_BUILD_DIR)/,$(notdir $(SI5351_SOURCES:.c=.o)))
 

	
 
si5351: $(SI5351_OBJECTS)
 

	
 
$(SI5351_BUILD_DIR)/%.o: $(SI5351_PATH)/%.c | $(SI5351_BUILD_DIR)
 
	$(CC) -Os $(CFLAGS) -c -o $@ $^
 

	
 
$(SI5351_BUILD_DIR):
 
	@echo $(SI5351_BUILD_DIR)
 
	$(MKDIR) $@
 

	
 
# jtencode
 
JTENCODE_PATH = ./lib/jtencode/
 
JTENCODE_BUILD_DIR = $(BUILD_DIR)/jtencode
 
JTENCODE_SOURCES += jtencode.c init_rs_int.c encode_rs_int.c
 

	
 
JTENCODE_OBJECTS += $(addprefix $(JTENCODE_BUILD_DIR)/,$(notdir $(JTENCODE_SOURCES:.c=.o)))
 

	
 
jtencode: $(JTENCODE_OBJECTS)
 

	
 
$(JTENCODE_BUILD_DIR)/%.o: $(JTENCODE_PATH)/%.c | $(JTENCODE_BUILD_DIR)
 
	$(CC) -Os $(CFLAGS) -c -o $@ $^
 

	
 
$(JTENCODE_BUILD_DIR):
 
	@echo $(JTENCODE_BUILD_DIR)
 
	$(MKDIR) $@
 

	
 

	
 

	
 
#######################################
 
# build the user application
 
#######################################
 

	
 
# list of user program objects
 
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(SOURCES:.c=.o)))
 
# add an object for the startup code
 
OBJECTS += $(BUILD_DIR)/startup_stm32f031x6.o
 

	
 
# use the periphlib core library, plus generic ones (libc, libm, libnosys)
 
LIBS = -lstm32cube -lc -lm -lnosys
 
LDFLAGS = -T $(LD_SCRIPT) -L $(CUBELIB_BUILD_DIR) -static $(LIBS) $(USER_LDFLAGS)
 

	
 
$(BUILD_DIR)/$(TARGET).hex: $(BUILD_DIR)/$(TARGET).elf
 
	$(OBJCOPY) -O ihex $(BUILD_DIR)/$(TARGET).elf $@
 

	
 
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
inc/adc.h
Show inline comments
 
/**
 
  ******************************************************************************
 
  * File Name          : ADC.h
 
  * Description        : This file provides code for the configuration
 
  *                      of the ADC instances.
 
  ******************************************************************************
 
  *
 
  * COPYRIGHT(c) 2016 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.
 
  *
 
  ******************************************************************************
 
  */
 
/* Define to prevent recursive inclusion -------------------------------------*/
 
#ifndef __adc_H
 
#define __adc_H
 
#ifdef __cplusplus
 
 extern "C" {
 
#endif
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32f0xx_hal.h"
 
 
/* USER CODE BEGIN Includes */
 
 
/* USER CODE END Includes */
 
 
extern ADC_HandleTypeDef hadc;
 
 
/* USER CODE BEGIN Private defines */
 
 
/* USER CODE END Private defines */
 
 
void MX_ADC_Init(void);
 
 
/* USER CODE BEGIN Prototypes */
 
 
/* USER CODE END Prototypes */
 
void adc_init(void); 
 
 
#ifdef __cplusplus
 
}
 
#endif
 
#endif /*__ adc_H */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
inc/dma.h
Show inline comments
 
/**
 
  ******************************************************************************
 
  * File Name          : dma.h
 
  * Description        : This file contains all the function prototypes for
 
  *                      the dma.c file
 
  ******************************************************************************
 
  *
 
  * COPYRIGHT(c) 2016 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.
 
  *
 
  ******************************************************************************
 
  */
 
/* Define to prevent recursive inclusion -------------------------------------*/
 
#ifndef __dma_H
 
#define __dma_H
 
 
#ifdef __cplusplus
 
 extern "C" {
 
#endif
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32f0xx_hal.h"
 
 
/* DMA memory to memory transfer handles -------------------------------------*/
 
 
/* USER CODE BEGIN Includes */
 
 
/* USER CODE END Includes */
 
 
/* USER CODE BEGIN Private defines */
 
 
/* USER CODE END Private defines */
 
 
void MX_DMA_Init(void);
 
 
/* USER CODE BEGIN Prototypes */
 
void dma_init(void);
 
 
/* USER CODE END Prototypes */
 
 
#ifdef __cplusplus
 
}
 
#endif
 
 
#endif /* __dma_H */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
inc/i2c.h
Show inline comments
 
#ifndef __i2c_H
 
#define __i2c_H
 
 
#include "stm32f0xx_hal.h"
 
 
void i2c_init(void);
 
I2C_HandleTypeDef* i2c_get(void);
 
 
#endif /*__ i2c_H */
 
#endif 
 
inc/interrupts.h
Show inline comments
 
file renamed from inc/stm32f0xx_it.h to inc/interrupts.h
 
/**
 
  ******************************************************************************
 
  * @file    stm32f0xx_it.h
 
  * @brief   This file contains the headers of the interrupt handlers.
 
  ******************************************************************************
 
  *
 
  * COPYRIGHT(c) 2016 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.
 
  *
 
  ******************************************************************************
 
  */
 
 
/* Define to prevent recursive inclusion -------------------------------------*/
 
#ifndef __STM32F0xx_IT_H
 
#define __STM32F0xx_IT_H
 
 
#ifdef __cplusplus
 
 extern "C" {
 
#endif 
 
 
/* Includes ------------------------------------------------------------------*/
 
/* Exported types ------------------------------------------------------------*/
 
/* Exported constants --------------------------------------------------------*/
 
/* Exported macro ------------------------------------------------------------*/
 
/* Exported functions ------------------------------------------------------- */
 
 
void SysTick_Handler(void);
 
void DMA1_Channel2_3_IRQHandler(void);
 
void USART1_IRQHandler(void);
 
 
#ifdef __cplusplus
 
}
 
#endif
 
 
#endif /* __STM32F0xx_IT_H */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
inc/usart.h
Show inline comments
 
/**
 
  ******************************************************************************
 
  * File Name          : USART.h
 
  * Description        : This file provides code for the configuration
 
  *                      of the USART instances.
 
  ******************************************************************************
 
  *
 
  * COPYRIGHT(c) 2016 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.
 
  *
 
  ******************************************************************************
 
  */
 
/* Define to prevent recursive inclusion -------------------------------------*/
 
#ifndef __usart_H
 
#define __usart_H
 
#ifdef __cplusplus
 
 extern "C" {
 
#endif
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32f0xx_hal.h"
 
 
/* USER CODE BEGIN Includes */
 
 
/* USER CODE END Includes */
 
 
extern UART_HandleTypeDef huart1;
 
 
/* USER CODE BEGIN Private defines */
 
 
/* USER CODE END Private defines */
 
 
void MX_USART1_UART_Init(void);
 
 
/* USER CODE BEGIN Prototypes */
 
 
/* USER CODE END Prototypes */
 
 
#ifdef __cplusplus
 
}
 
#endif
 
#endif /*__ usart_H */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
src/adc.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * File Name          : ADC.c
 
  * Description        : This file provides code for the configuration
 
  *                      of the ADC instances.
 
  ******************************************************************************
 
  *
 
  * COPYRIGHT(c) 2016 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"
 
#include "adc.h"
 
 
#include "gpio.h"
 
 
/* USER CODE BEGIN 0 */
 
 
/* USER CODE END 0 */
 
 
ADC_HandleTypeDef hadc;
 
 
/* ADC init function */
 
void MX_ADC_Init(void)
 
// Initialize ADC
 
void adc_init(void)
 
{
 
    __ADC1_CLK_ENABLE();
 
 
    GPIO_InitTypeDef GPIO_InitStruct;
 
    GPIO_InitStruct.Pin = VBATT_SENSE_Pin;
 
    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
 
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 
    HAL_GPIO_Init(VBATT_SENSE_GPIO_Port, &GPIO_InitStruct);
 
 
  ADC_ChannelConfTypeDef sConfig;
 
 
    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
 
    */
 
  hadc.Instance = ADC1;
 
  hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC;
 
  hadc.Init.Resolution = ADC_RESOLUTION12b;
 
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
 
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
 
  hadc.Init.EOCSelection = EOC_SINGLE_CONV;
 
  hadc.Init.LowPowerAutoWait = DISABLE;
 
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
 
  hadc.Init.ContinuousConvMode = DISABLE;
 
  hadc.Init.DiscontinuousConvMode = DISABLE;
 
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 
  hadc.Init.DMAContinuousRequests = DISABLE;
 
  hadc.Init.Overrun = OVR_DATA_PRESERVED;
 
  HAL_ADC_Init(&hadc);
 
 
    /**Configure for the selected ADC regular channel to be converted. 
 
    */
 
  sConfig.Channel = ADC_CHANNEL_6;
 
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
 
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
 
  HAL_ADC_ConfigChannel(&hadc, &sConfig);
 
 
}
 
 
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
 
{
 
 
  GPIO_InitTypeDef GPIO_InitStruct;
 
  if(hadc->Instance==ADC1)
 
  {
 
  /* USER CODE BEGIN ADC1_MspInit 0 */
 
 
  /* USER CODE END ADC1_MspInit 0 */
 
    /* Peripheral clock enable */
 
    __ADC1_CLK_ENABLE();
 
  
 
    /**ADC GPIO Configuration    
 
    PA6     ------> ADC_IN6 
 
    */
 
    GPIO_InitStruct.Pin = VBATT_SENSE_Pin;
 
    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
 
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 
    HAL_GPIO_Init(VBATT_SENSE_GPIO_Port, &GPIO_InitStruct);
 
 
  /* USER CODE BEGIN ADC1_MspInit 1 */
 
 
  /* USER CODE END ADC1_MspInit 1 */
 
  }
 
}
 
 
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
 
{
 
 
  if(hadc->Instance==ADC1)
 
  {
 
  /* USER CODE BEGIN ADC1_MspDeInit 0 */
 
 
  /* USER CODE END ADC1_MspDeInit 0 */
 
    /* Peripheral clock disable */
 
    __ADC1_CLK_DISABLE();
 
  
 
    /**ADC GPIO Configuration    
 
    PA6     ------> ADC_IN6 
 
    */
 
    HAL_GPIO_DeInit(VBATT_SENSE_GPIO_Port, VBATT_SENSE_Pin);
 
 
  }
 
  /* USER CODE BEGIN ADC1_MspDeInit 1 */
 
 
  /* USER CODE END ADC1_MspDeInit 1 */
 
} 
 
 
/* USER CODE BEGIN 1 */
 
 
/* USER CODE END 1 */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
src/dma.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * File Name          : dma.c
 
  * Description        : This file provides code for the configuration
 
  *                      of all the requested memory to memory DMA transfers.
 
  ******************************************************************************
 
  *
 
  * COPYRIGHT(c) 2016 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 "dma.h"
 
 
/* USER CODE BEGIN 0 */
 
 
/* USER CODE END 0 */
 
 
/*----------------------------------------------------------------------------*/
 
/* Configure DMA                                                              */
 
/*----------------------------------------------------------------------------*/
 
 
/* USER CODE BEGIN 1 */
 
 
/* USER CODE END 1 */
 
 
/** 
 
  * Enable DMA controller clock
 
  */
 
void MX_DMA_Init(void) 
 
void dma_init(void) 
 
{
 
  /* DMA controller clock enable */
 
  __DMA1_CLK_ENABLE();
 
 
  /* DMA interrupt init */
 
  HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
 
  HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
 
 
}
 
 
/* USER CODE BEGIN 2 */
 
 
/* USER CODE END 2 */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
src/interrupts.c
Show inline comments
 
file renamed from src/stm32f0xx_it.c to src/interrupts.c
 
//
 
// Interrupts: all global ISRs
 
//
 
 
#include "stm32f0xx_hal.h"
 
#include "stm32f0xx.h"
 
#include "stm32f0xx_it.h"
 
#include "interrupts.h"
 
#include "gpio.h"
 
 
extern DMA_HandleTypeDef hdma_usart1_rx;
 
extern DMA_HandleTypeDef hdma_usart1_tx;
 
extern UART_HandleTypeDef huart1;
 
extern TIM_HandleTypeDef htim1;
 
extern volatile uint8_t proceed;
 
 
void SysTick_Handler(void)
 
{
 
    HAL_IncTick();
 
    HAL_SYSTICK_IRQHandler();
 
}
 
 
void DMA1_Channel2_3_IRQHandler(void)
 
{
 
    HAL_DMA_IRQHandler(&hdma_usart1_tx);
 
    HAL_DMA_IRQHandler(&hdma_usart1_rx);
 
}
 
 
void USART1_IRQHandler(void)
 
{
 
    HAL_UART_IRQHandler(&huart1);
 
}
 
 
void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
 
{
 
    proceed = 1;
 
    HAL_TIM_IRQHandler(&htim1);
 
}
src/main.c
Show inline comments
 
//
 
// WSPRHAB: Minimal high-altitude balloon tracker with WSPR telemetry
 
//
 
 
#include "stm32f0xx_hal.h"
 
#include "si5351.h"
 
#include "jtencode.h"
 
#include "adc.h"
 
#include "dma.h"
 
#include "i2c.h"
 
#include "usart.h"
 
#include "gpio.h"
 
#include "gps.h"
 
 
 
void sysclk_init(void);
 
 
//#define WSPR_DEFAULT_FREQ 14097100UL
 
#define WSPR_DEFAULT_FREQ 10140100UL
 
#define WSPR_TONE_SPACING 146 // ~1.46 Hz
 
#define WSPR_CTC 10672 // CTC value for WSPR
 
 
char call[7] = "KD8TDF";
 
char loc[5] = "EN72";
 
uint8_t dbm = 10;
 
uint8_t tx_buffer[255];
 
 
 
uint32_t freq = WSPR_DEFAULT_FREQ;
 
uint8_t symbol_count = WSPR_SYMBOL_COUNT;
 
uint16_t ctc = WSPR_CTC;
 
uint16_t tone_spacing = WSPR_TONE_SPACING;
 
volatile uint8_t proceed = 0;
 
 
void encode_wspr(void)
 
{
 
    uint8_t i;
 
    //for(i=0; i<255; i++)
 
    //    tx_buffer[i] = 0;
 
 
    wspr_encode(call, loc, dbm, tx_buffer);
 
 
 
    //si5351_output_enable(SI5351_CLK0, 1);
 
 
    for(i=0; i<symbol_count; i++)
 
    {
 
 
        uint32_t freq2 = (freq * 100) + (tx_buffer[i] * tone_spacing);
 
        si5351_set_freq(freq2, 0, SI5351_CLK0);
 
        HAL_GPIO_TogglePin(LED_BLUE);
 
 
          //si5351_set_freq((freq * 100) + (tx_buffer[i] * tone_spacing), 0, SI5351_CLK0);
 
          //HAL_Delay(300);
 
          proceed = 0;
 
          while(!proceed);
 
    }
 
        si5351_output_enable(SI5351_CLK0, 0);
 
}
 
 
    TIM_HandleTypeDef htim1;
 
 
int main(void)
 
{
 
    HAL_Init();
 
 
    sysclk_init();
 
    gpio_init();
 
    MX_DMA_Init();
 
    MX_ADC_Init();
 
    dma_init();
 
    adc_init();
 
    i2c_init();
 
 
    HAL_GPIO_WritePin(OSC_NOTEN, 0);
 
    HAL_GPIO_WritePin(TCXO_EN, 1);
 
 
 
    // Start timer for WSPR
 
    __TIM1_CLK_ENABLE();
 
    TIM_MasterConfigTypeDef sMasterConfig;
 
    TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
 
    TIM_OC_InitTypeDef sConfigOC;
 
 
    htim1.Instance = TIM1;
 
    htim1.Init.Prescaler = 512; // gives 64uS ticks from 8MHz ahbclk
 
    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 
    htim1.Init.Period = ctc; // Count up to this value (how many 64uS ticks per symbol)
 
    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 
    htim1.Init.RepetitionCounter = 0;
 
    HAL_TIM_Base_Init(&htim1);
 
 
    HAL_TIM_Base_Start_IT(&htim1);
 
/*
 
    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
 
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
 
    HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig);
 
 
    sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
 
    sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
 
    sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
 
    sBreakDeadTimeConfig.DeadTime = 0;
 
    sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
 
    sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
 
    sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
 
    HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig);
 
 
    sConfigOC.OCMode = TIM_OCMODE_TIMING;
 
    sConfigOC.Pulse = 0;
 
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
 
    sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
 
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
 
    sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
 
    sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
 
    HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);
 
*/
 
 
 
    HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, 0, 0);
 
    HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 
 
    HAL_Delay(100);
 
 
 
 
 
 
 
//    MX_USART1_UART_Init();
 
 
    jtencode_init();
 
    //gps_init();
 
    si5351_init(i2c_get(), SI5351_CRYSTAL_LOAD_8PF, 0);
 
    si5351_set_correction(0);
 
    //si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
    //si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA);
 
    si5351_set_freq(WSPR_DEFAULT_FREQ * 100, 0, SI5351_CLK0);
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_2MA); // Set for max power if desired (8ma max)
 
    si5351_output_enable(SI5351_CLK0, 1);
 
    //si5351_pll_reset(SI5351_PLLA);
 
 
    //wspr_encode(call, loc, dbm, tx_buffer);
 
 
    encode_wspr();
 
 
    HAL_Delay(1000);
 
 
    uint32_t led_timer = HAL_GetTick();
 
    uint32_t last_gps  = HAL_GetTick();
 
    uint32_t last_wspr  = HAL_GetTick();
 
 
    while (1)
 
    {
 
        if(HAL_GetTick() - last_wspr > 6000)
 
        {
 
            last_wspr = HAL_GetTick();
 
        }
 
        
 
        if(HAL_GetTick() - led_timer > 100)
 
        {
 
            HAL_GPIO_TogglePin(LED_BLUE);
 
            led_timer = HAL_GetTick();
 
        }
 
        if(HAL_GetTick() - last_gps > 100)
 
        {
 
//            gps_process();
 
            last_gps = HAL_GetTick();
 
        }
 
    }
 
}
 
 
 
// Initialize system clocks
 
void sysclk_init(void)
 
{
 
    RCC_OscInitTypeDef RCC_OscInitStruct;
 
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
 
    RCC_PeriphCLKInitTypeDef PeriphClkInit;
 
 
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
 
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 
    RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
 
    RCC_OscInitStruct.HSICalibrationValue = 16;
 
    RCC_OscInitStruct.HSI14CalibrationValue = 16;
 
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 
    HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
 
    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
 
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
 
 
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_I2C1;
 
    PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
 
    PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
 
    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
 
 
    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 
 
    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
 
    __SYSCFG_CLK_ENABLE();
 
    // SysTick_IRQn interrupt configuration 
 
    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
 
}
 
src/stm32f0xx_hal_msp.c
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)