Changeset - 0ee0ed9a3b7d
[Not reviewed]
default
0 3 0
Ethan Zonca - 10 years ago 2014-09-25 21:34:24
ez@ethanzonca.com
Added clock startup failure check
3 files changed with 14 insertions and 7 deletions:
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -9,13 +9,12 @@
 
#include "usb_lib.h"
 
#include "usb_desc.h"
 
#include "usb_pwr.h"
 
#include "stringhelpers.h"
 
 
// TODO: Grab buttonpresses with interrupts
 
// TODO: Eliminate screen buffer since we aren't using it...
 
 
// USB Supporting Vars
 
extern __IO uint8_t Receive_Buffer[64];
 
extern __IO  uint32_t Receive_length ;
 
extern __IO  uint32_t length ;
 
uint8_t Send_Buffer[64];
 
@@ -36,13 +35,12 @@ volatile uint32_t ticks = 0;
 
// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
 
uint32_t change_time_reset = 0;
 
#define CHANGE_PERIOD_MS 100
 
#define CHANGE_ELAPSED (ticks - change_time_reset) > CHANGE_PERIOD_MS
 
#define CHANGE_RESET change_time_reset = ticks
 
 
 
int16_t setpoint_brew = 0;
 
int16_t setpoint_steam = 0;
 
 
// State definition
 
enum state {
 
    STATE_IDLE = 0,
 
@@ -101,15 +99,24 @@ int main(void)
 
    init_spi();
 
 
    // Init OLED over SPI
 
    ssd1306_Init();
 
    ssd1306_clearscreen();
 
 
    // Check for problems on startup
 
    if(clock_fail) {
 
        ssd1306_DrawString("ERROR: Check Xtal", 3, 0);
 
        delay(2000);
 
    }
 
 
    // Startup screen 
 
    ssd1306_DrawString("therm v0.1", 1, 40);
 
    ssd1306_DrawString("protofusion.org/therm", 3, 0);
 
 
 
 
    delay(1500);
 
    ssd1306_clearscreen();
 
    
 
    restore_settings();
 
    if(boottobrew)
 
      state = STATE_PREHEAT_BREW; // Go to brew instead of idle if configured thusly
 
@@ -367,25 +374,21 @@ void restore_settings()
 
}
 
 
 
void user_input(uint16_t* to_modify)
 
{
 
    if(CHANGE_ELAPSED) {
 
 
        // TODO: Make function that takes reference to a var and increase/decreases it based on buttonpress
 
        if(!GPIO_ReadInputDataBit(SW_UP) ) {
 
            CHANGE_RESET;
 
            (*to_modify)++;
 
        }
 
        else if(!GPIO_ReadInputDataBit(SW_DOWN) && (*to_modify) > 0) {
 
            CHANGE_RESET;
 
            (*to_modify)--;
 
        }
 
 
    }
 
 
}
 
 
void machine()
 
{
 
    uint8_t last_state = state;
 
 
@@ -752,13 +755,12 @@ void TimingDelay_Decrement(void)
 
  { 
 
    TimingDelay--;
 
  }
 
  ticks++;
 
}
 
 
 
void init_spi(void)
 
{
 
    SPI_InitTypeDef  SPI_InitStructure;
 
 
    // OLED IC
 
    SPI_Cmd(SPI1, DISABLE); 
system_stm32l1xx.c
Show inline comments
 
@@ -292,12 +292,14 @@ void SystemCoreClockUpdate (void)
 
  *         settings.
 
  * @note   This function should be called only once the RCC clock configuration  
 
  *         is reset to the default reset state (done in SystemInit() function).             
 
  * @param  None
 
  * @retval None
 
  */
 
uint8_t clock_fail = 0;
 

	
 
static void SetSysClock(void)
 
{
 
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
 
  
 
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
 
  /* Enable HSE */
 
@@ -371,12 +373,13 @@ static void SetSysClock(void)
 
    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
 
    {
 
    }
 
  }
 
  else
 
  {
 
	clock_fail = 1;
 
//	while(1);
 
    /* If HSE fails to start-up, the application will have wrong clock
 
       configuration. User can add here some code to deal with this error */
 
  }
 
}
 

	
system_stm32l1xx.h
Show inline comments
 
@@ -55,12 +55,14 @@
 
/** @addtogroup STM32L1xx_System_Exported_types
 
  * @{
 
  */
 
 
extern uint32_t SystemCoreClock;          /*!< System Clock Frequency (Core Clock) */
 
 
extern uint8_t clock_fail;
 
 
/**
 
  * @}
 
  */
 
 
/** @addtogroup STM32L1xx_System_Exported_Constants
 
  * @{
0 comments (0 inline, 0 general)