Changeset - 30d4d968a3a1
[Not reviewed]
cortex-f0
1 4 0
Ethan Zonca - 9 years ago 2015-09-05 23:20:58
ez@ethanzonca.com
Cleanup: remove CAN and multisetpoint
5 files changed with 18 insertions and 181 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
# STM32F0xx Makefile
 
# #####################################
 
#
 
# Part of the uCtools project
 
# uctools.github.com
 
#
 
#######################################
 
# user configuration:
 
#######################################
 

	
 

	
 
# SOURCES: list of sources in the user application
 
SOURCES = main.c usbd_conf.c usbd_cdc_if.c usb_device.c usbd_desc.c stm32f0xx_hal_msp.c stm32f0xx_it.c system_stm32f0xx.c gpio.c spi.c ssd1306.c stringhelpers.c display.c syslib.c storage.c flash.c max31855.c max31865.c
 
SOURCES = main.c usbd_conf.c usbd_cdc_if.c usb_device.c usbd_desc.c stm32f0xx_it.c system_stm32f0xx.c gpio.c spi.c ssd1306.c stringhelpers.c display.c syslib.c storage.c flash.c max31855.c max31865.c
 

	
 
# TARGET: name of the user application
 
TARGET = main
 

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

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

	
 
# USER_DEFS user defined macros
 
USER_DEFS = -D HSI48_VALUE=48000000 -D HSE_VALUE=16000000
 
# 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
 

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

	
 
# TARGET_DEVICE: device to compile for
 
TARGET_DEVICE = STM32F042x6
 

	
 
#######################################
 
# 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 += -I$(CURDIR)
 
INCLUDES += -I$(CURDIR)/usb
 
INCLUDES += $(USB_INCLUDES)
 
INCLUDES += $(USER_INCLUDES)
 

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

	
 
# compile gcc flags
 
CFLAGS = $(DEFS) $(INCLUDES)
 
CFLAGS += -mcpu=$(CPU) -mthumb
display.c
Show inline comments
 
#include "stm32f0xx_hal.h"
 
#include "ssd1306.h"
 
#include "stringhelpers.h"
 
#include "display.h"
 
#include "config.h"
 
#include "states.h"
 
#include "syslib.h"
 
#include "flash.h"
 
#include "gpio.h"
 

	
 
uint8_t goto_mode = 2;
 

	
 
// State machine
 
uint8_t sw_btn_last = 0;
 
uint8_t sw_up_last = 0;
 
uint8_t sw_down_last = 0;
 
uint8_t sw_left_last = 0;
 
uint8_t sw_right_last = 0;
 

	
 
#define SW_BTN_PRESSED (sw_btn_last == 0 && sw_btn == 1) // rising edge on buttonpress
 
#define SW_UP_PRESSED (sw_up_last == 0 && sw_up == 1)
 
#define SW_DOWN_PRESSED (sw_down_last == 0 && sw_down == 1)
 
#define SW_LEFT_PRESSED (sw_left_last == 0 && sw_left == 1)
 
#define SW_RIGHT_PRESSED (sw_right_last == 0 && sw_right == 1)
 

	
 
///////////////////////////////////////////////////////////////////////////////////////
 
/// freaking multiple setpoint support ///
 
uint8_t step_duration[10] = {0,0,0,0,0,0,0,0,0,0};
 
int16_t step_setpoint[10] = {0,0,0,0,0,0,0,0,0,0};
 
uint8_t final_setpoint = 0;
 

	
 
// Multiple screens to set setpoint and duration on each screen
 
// press center to go to the next one, and press left or right or something to confirm
 

	
 
// When executing, complete on time AND(?) temperature. Maybe allow switching to OR via settings
 

	
 
////////////////////////////////////////////////////////////////////////////////////////////////
 

	
 
uint8_t trigger_drawsetpoint = 1;
 

	
 
int16_t last_temp = 21245;
 

	
 
void display_process(therm_settings_t* set, therm_status_t* status)
 
{
 
    uint8_t last_state = status->state;
 
    
 
    uint8_t temp_changed = status->temp != last_temp;
 
    last_temp = status->temp;
 

	
 
    uint8_t sw_btn = !HAL_GPIO_ReadPin(SW_BTN);
 
    uint8_t sw_up = !HAL_GPIO_ReadPin(SW_UP);
 
    uint8_t sw_down = !HAL_GPIO_ReadPin(SW_DOWN);
 
    uint8_t sw_left = !HAL_GPIO_ReadPin(SW_LEFT);
 
    uint8_t sw_right = !HAL_GPIO_ReadPin(SW_RIGHT);
 

	
 
    switch(status->state)
 
    {
 
        // Idle state
 
        case STATE_IDLE:
 
        {
 
            // Write text to OLED
 
            // [ therm :: idle ]
 
            ssd1306_DrawString("therm :: idle ", 0, 40);
 
            status->pid_enabled = 0;
 

	
 
            if(temp_changed) {
 
                char tempstr[6];
 
                itoa_fp(status->temp, status->temp_frac, tempstr);
 
                ssd1306_DrawString("Temp: ", 3, 40);
 
                ssd1306_DrawString("    ", 3, 72);
 
                ssd1306_DrawString(tempstr, 3, 72);
 
            }
 

	
 
            ssd1306_drawlogo();
 

	
 
            switch(goto_mode) {
 
                case 3:
 
                {
 
                    ssd1306_DrawString("-> loader   ", 1, 40);
 
                } break;
 

	
 
                case 2:
 
                {
 
                    ssd1306_DrawString("-> heat     ", 1, 40);
 
                } break;
 
@@ -178,135 +166,96 @@ void display_process(therm_settings_t* s
 
            ssd1306_DrawString("I=", 1, 45);
 
            ssd1306_DrawString("    ", 1, 57);
 
            ssd1306_DrawString(tempstr, 1, 57);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 
            
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_SETD;
 
            }
 
            else {
 
                user_input(&set->k_i);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 
        case STATE_SETD:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set d ]
 
            // [ d = 12         ]
 
            ssd1306_DrawString("Derivative", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->k_d, tempstr, 10);
 
            ssd1306_DrawString("D=", 1, 45);
 
            ssd1306_DrawString("    ", 1, 57);
 
            ssd1306_DrawString(tempstr, 1, 57);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_SETWINDUP;
 
            }
 
            else {
 
                user_input(&set->k_d);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 
        case STATE_SETSTEPS:
 
        {
 
            // Write text to OLED
 
            // [ step #1:: Duration: ### ]
 
            // [           Setpoint: ### ]
 
            char tempstr[6];
 

	
 
            itoa(final_setpoint, tempstr, 10);
 
            ssd1306_DrawString("Step #", 0, 0);
 
            ssd1306_DrawString(tempstr, 0, 40);
 

	
 
            ssd1306_DrawString("Duration: ", 0, 5);
 
            itoa(step_duration[final_setpoint], tempstr, 10);
 
            ssd1306_DrawString(tempstr, 0, 70);
 

	
 
            ssd1306_DrawString("Setpoint: ", 0, 0);
 
            itoa(step_setpoint[final_setpoint], tempstr, 10);
 
            ssd1306_DrawString(tempstr, 0, 70);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 
            
 
            // Button handler - TODO: increment max_step if pressed
 
            // return and go to next state otherwise
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_SETSTEPS;
 
                final_setpoint++;
 
            }
 
        //    else if(SW_LEFT_PRESSED) {
 
        //        state++; // go to next state or something
 
        //    }
 
            else {
 
                user_input(&set->k_p);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 

	
 
        } break;
 

	
 
        case STATE_SETWINDUP:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set windup ]
 
            // [ g = 12         ]
 
            ssd1306_DrawString("Windup Guard", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            char tempstr[6];
 
            itoa(set->windup_guard, tempstr, 10);
 
            ssd1306_DrawString("G=", 1, 45);
 
            ssd1306_DrawString("    ", 1, 57);
 
            ssd1306_DrawString(tempstr, 1, 57);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                status->state = STATE_SETBOOTTOBREW;
 
            }
 
            else {
 
                user_input(&set->windup_guard);
 
            }
 

	
 
            // Event Handler
 
            // N/A
 
 
 
        } break;
 

	
 
        case STATE_SETBOOTTOBREW:
 
        {
 
            // Write text to OLED
 
            // [ therm :: set windup ]
 
            // [ g = 12         ]
 
            ssd1306_DrawString("Start on Boot", 0, 40);
 
            ssd1306_drawlogo();
 

	
 
            ssd1306_DrawString("sob=", 1, 45);
 
            
 
            if(set->boottobrew)
 
                ssd1306_DrawString("Enabled ", 1, 70);
 
            else
 
                ssd1306_DrawString("Disabled", 1, 70);
 

	
 
            ssd1306_DrawString("Press to accept", 3, 40);
 

	
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
flash.c
Show inline comments
 
#include "stm32f0xx_hal.h"
 
#include "ssd1306.h"
 
#include "stm32f0xx_hal_flash.h"
 
#include "flash.h"
 

	
 
void flash_init(therm_settings_t* tosave)
 
{
 
    ssd1306_clearscreen();
 
    uint16_t size = sizeof(therm_settings_t)-1;
 
    uint32_t flash_adr = END_ADDR - size;
 
    flash_adr -= 2;
 
    uint8_t* flash_ptr = (uint8_t *)flash_adr;
 

	
 
    // Check if flash is blank
 
    uint16_t i = 0;
 
    uint16_t count = 0;
 

	
 
    char tempstr[10];
 
    itoa(flash_adr, tempstr, 10);
 
    ssd1306_DrawString(tempstr, 1, 0);
 

	
 
    uint16_t test;
 
    for(i=0;i<size;i++)
 
    {
 
        test = *flash_ptr;
 
        if(test==0xFF) count++;
 
    }
 

	
 
    ssd1306_DrawString("END LOOP ", 0, 0);
 

	
 
    // If blank, do nothing and just use values from RAM
 

	
 
    count = size + 1;
 
    // If not blank, check the checksums
 
    if(count != size) 
 
    {
 
        ssd1306_DrawString("FLASH NOT BLANK", 1, 0);
 
        // Calculate Checksums
 
    uint8_t cksum0=0,cksum1=0;
 
    uint8_t rdSum0=0,rdSum1=0;
 
        uint8_t cksum0=0,cksum1=0;
 
        uint8_t rdSum0=0,rdSum1=0;
 

	
 
        flash_adr = END_ADDR - size;
 
        flash_ptr = (uint8_t *)flash_adr;
 
        for(i=1; i < size; i++)
 
        {
 
            cksum0 += *flash_ptr++;
 
            cksum1 += cksum0;
 
        }
 

	
 
        // Read flash checksums
 
        flash_adr -= 2;
 
        flash_ptr = (uint8_t *)flash_adr;
 
        rdSum0 = *flash_ptr++;
 
        rdSum1 = *flash_ptr;
 

	
 
        // Compare Checksums values
 
        if((rdSum1==cksum1)&&(rdSum0==cksum0)) {
 
	    ssd1306_DrawString("CHECKSUM OK", 2, 0);
 
	    flash_read(tosave);
 
	}
 
        else {
 
	    ssd1306_DrawString("CHECKSUM BAD", 2, 0);
 
	    return; // If the checksum is bad, just use vals from RAM
 
	}
 

	
 
    }
 
    else {
 
        ssd1306_DrawString("FLASH BLANK", 1, 0);
 
    }
 
}
 

	
 

	
 
void flash_save(therm_settings_t* tosave)
 
{
 

	
 
	    ssd1306_DrawString("BEGIN SAVE", 2, 0);
 
            HAL_Delay(1500);
 
        flash_erase(tosave);
 
        flash_write(tosave);
 
        flash_checksum(tosave);
 
	    ssd1306_DrawString("END SAVE", 2, 0);
 
            HAL_Delay(1500);
 
    ssd1306_clearscreen();
 
    ssd1306_DrawString("BEGIN SAVE", 0, 0);
 
    HAL_Delay(1500);
 
    flash_erase(tosave);
 
    flash_write(tosave);
 
    flash_checksum(tosave);
 
    ssd1306_DrawString("END SAVE", 2, 0);
 
    HAL_Delay(1500);
 
}
 

	
 

	
 
void flash_read(therm_settings_t *tosave)
 
{
 
    ssd1306_clearscreen();
 
    ssd1306_DrawString("READING SAVE", 1, 0);
 
    char tempstr[10];
 
    itoa(sizeof(therm_settings_t), tempstr, 10);
 
    ssd1306_DrawString(tempstr, 2, 0);
 

	
 
    uint16_t size = sizeof(therm_settings_t)-1; // in Bytes
 
    uint32_t flash_adr = END_ADDR - size;
 
    uint8_t *flash_ptr = (uint8_t *)flash_adr;
 
    uint8_t *struct_ptr = (uint8_t*)tosave;
 

	
 
    uint16_t i;
 
    for(i=0;i<size;i++)
 
        *struct_ptr++ = *flash_ptr++;
 
    ssd1306_DrawString("READ COMPLETE", 3, 0);
 

	
 
}
 

	
 

	
 
void flash_write(therm_settings_t* tosave)
 
{
 

	
 
    HAL_FLASH_Unlock();
 

	
 
    uint16_t size = sizeof(therm_settings_t)-1; // in Bytes
 
    uint32_t start_address = END_ADDR-size; // write to end of page
 
    uint32_t struct_ptr = (uint32_t*) tosave;
 

	
 
    uint16_t  length;
 
    if(size%2==0)
 
        length = size/2;
 
    else
 
        length = size/2+1;
 

	
 
    uint16_t i;
 
    for(i=0;i<length;i++)
 
    {
 
        HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, start_address, struct_ptr);
 
        struct_ptr++;
 
        start_address +=2;
 
    }
 

	
 
    HAL_FLASH_Lock();
 
}
 

	
 

	
 
void flash_checksum(therm_settings_t* tosave)
 
{
 
    uint8_t cksum0=0,cksum1=0;
stm32f0xx_hal_conf.h
Show inline comments
 
@@ -4,97 +4,97 @@
 
  * @brief   HAL configuration template file.
 
  ******************************************************************************
 
  * @attention
 
  *
 
  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
 
  *
 
  * 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_HAL_CONF_H
 
#define __STM32F0xx_HAL_CONF_H
 
 
#ifdef __cplusplus
 
 extern "C" {
 
#endif
 
 
/* Exported types ------------------------------------------------------------*/
 
/* Exported constants --------------------------------------------------------*/
 
 
/* ########################## Module Selection ############################## */
 
/**
 
  * @brief This is the list of modules to be used in the HAL driver
 
  */
 
#define HAL_MODULE_ENABLED
 
//#define HAL_ADC_MODULE_ENABLED
 
#define HAL_CAN_MODULE_ENABLED
 
//#define HAL_CAN_MODULE_ENABLED
 
//#define HAL_CEC_MODULE_ENABLED
 
//#define HAL_COMP_MODULE_ENABLED
 
//#define HAL_CRC_MODULE_ENABLED
 
//#define HAL_CRYP_MODULE_ENABLED
 
//#define HAL_TSC_MODULE_ENABLED
 
//#define HAL_DAC_MODULE_ENABLED
 
//#define HAL_I2C_MODULE_ENABLED
 
//#define HAL_I2S_MODULE_ENABLED
 
//#define HAL_IWDG_MODULE_ENABLED
 
//#define HAL_LCD_MODULE_ENABLED
 
//#define HAL_LPTIM_MODULE_ENABLED
 
//#define HAL_RNG_MODULE_ENABLED
 
//#define HAL_RTC_MODULE_ENABLED
 
#define HAL_SPI_MODULE_ENABLED
 
#define HAL_TIM_MODULE_ENABLED
 
//#define HAL_UART_MODULE_ENABLED
 
//#define HAL_USART_MODULE_ENABLED
 
//#define HAL_IRDA_MODULE_ENABLED
 
//#define HAL_SMARTCARD_MODULE_ENABLED
 
//#define HAL_SMBUS_MODULE_ENABLED
 
//#define HAL_WWDG_MODULE_ENABLED
 
#define HAL_PCD_MODULE_ENABLED
 
#define HAL_CORTEX_MODULE_ENABLED
 
#define HAL_DMA_MODULE_ENABLED
 
#define HAL_FLASH_MODULE_ENABLED
 
#define HAL_GPIO_MODULE_ENABLED
 
#define HAL_PWR_MODULE_ENABLED
 
#define HAL_RCC_MODULE_ENABLED
 
 
/* ########################## HSE/HSI Values adaptation ##################### */
 
/**
 
  * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
 
  *        This value is used by the RCC HAL module to compute the system frequency
 
  *        (when HSE is used as system clock source, directly or through the PLL).
 
  */
 
#if !defined  (HSE_VALUE)
 
  #define HSE_VALUE    ((uint32_t)16000000) /*!< Value of the External oscillator in Hz */
 
#endif /* HSE_VALUE */
 
 
/**
 
  * @brief In the following line adjust the External High Speed oscillator (HSE) Startup
 
  *        Timeout value
 
  */
 
#if !defined  (HSE_STARTUP_TIMEOUT)
 
  #define HSE_STARTUP_TIMEOUT    ((uint32_t)5000)   /*!< Time out for HSE start up, in ms */
 
#endif /* HSE_STARTUP_TIMEOUT */
 
 
/**
stm32f0xx_hal_msp.c
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)