Changeset - 28c7e1414fd9
[Not reviewed]
default
0 3 0
Ethan Zonca - 10 years ago 2016-03-25 23:06:22
ez@ethanzonca.com
Disabled link-time optimization which fixed jump to rst vector on encode, downside is code size grew
3 files changed with 16 insertions and 54 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
@@ -17,51 +17,54 @@ SOURCES = main.c system_stm32f0xx.c adc.
 
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_CFLAGS = -Wall -g -ffunction-sections -fdata-sections -Os -fno-common --function-sections -fdata-sections 
 
#USER_CFLAGS += -flto
 

	
 
# USER_LDFLAGS:  user LD flags
 
USER_LDFLAGS = -flto -fno-exceptions -ffunction-sections -fdata-sections -Wl,--gc-sections 
 
USER_LDFLAGS = -fno-exceptions -ffunction-sections -fdata-sections -Wl,--gc-sections 
 
#USER_LDFLAGS += -flto
 
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
STM32F031G6_FLASH.ld
Show inline comments
 
@@ -14,49 +14,49 @@
 
**  Target      : STMicroelectronics STM32
 
**
 
**  Environment : Atollic TrueSTUDIO(R)
 
**
 
**  Distribution: The file is distributed “as is,” without any warranty
 
**                of any kind.
 
**
 
**  (c)Copyright Atollic AB.
 
**  You may use this file as-is or modify it according to the needs of your
 
**  project. This file may only be built (assembled or compiled and linked)
 
**  using the Atollic TrueSTUDIO(R) product. The use of this file together
 
**  with other tools than Atollic TrueSTUDIO(R) is not permitted.
 
**
 
*****************************************************************************
 
*/
 

	
 
/* Entry Point */
 
ENTRY(Reset_Handler)
 

	
 
/* Highest address of the user mode stack */
 
_estack = 0x20001000;    /* end of RAM */
 

	
 
/* Generate a link error if heap and stack don't fit into RAM */
 
_Min_Heap_Size = 0;      /* required amount of heap  */
 
_Min_Stack_Size = 0x300; /* required amount of stack */
 
_Min_Stack_Size = 0x400; /* required amount of stack */
 

	
 
/* Specify the memory areas */
 
MEMORY
 
{
 
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 32K
 
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 4K
 
}
 

	
 
/* Define output sections */
 
SECTIONS
 
{
 
  /* The startup code goes first into FLASH */
 
  .isr_vector :
 
  {
 
    . = ALIGN(4);
 
    KEEP(*(.isr_vector)) /* Startup code */
 
    . = ALIGN(4);
 
  } >FLASH
 

	
 
  /* The program code and other data goes into FLASH */
 
  .text :
 
  {
 
    . = ALIGN(4);
 
    *(.text)           /* .text sections (code) */
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;
 
 
    // Encode message to transmit
 
    wspr_encode(call, loc, dbm, tx_buffer);
 
 
    // Key transmitter
 
    si5351_output_enable(SI5351_CLK0, 1);
 
 
    //si5351_output_enable(SI5351_CLK0, 1);
 
 
    // Loop through and transmit symbols TODO: Do this from an ISR or ISR-triggered main loop function call (optimal)
 
    uint8_t i;
 
    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);
 
    }
 
 
    // Disable transmitter
 
        si5351_output_enable(SI5351_CLK0, 0);
 
}
 
 
    TIM_HandleTypeDef htim1;
 
 
int main(void)
 
{
 
    HAL_Init();
 
 
    sysclk_init();
 
    gpio_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();
 
    uint32_t last_wspr  = 0xfffff; // start immediately. 
 
 
    while (1)
 
    {
 
        if(HAL_GetTick() - last_wspr > 6000)
 
        if(HAL_GetTick() - last_wspr > 120000)
 
        {
 
            encode_wspr();
 
            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;
 
0 comments (0 inline, 0 general)