Changeset - 08c52ee196d1
[Not reviewed]
cortex-f0
0 3 1
Ethan Zonca - 10 years ago 2015-01-03 13:46:06
ez@ethanzonca.com
Added cube, etc
4 files changed with 184 insertions and 20 deletions:
0 comments (0 inline, 0 general)
eeprom_min.c
Show inline comments
 
#include <inttypes.h>
 

	
 
/*
 
void Minimal_EEPROM_Unlock(void)
 
{
 
  if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET)
 
  {
 
    /* Unlocking the Data memory and FLASH_PECR register access*/
 
    // Unlocking the Data memory and FLASH_PECR register access
 
    FLASH->PEKEYR = FLASH_PEKEY1;
 
    FLASH->PEKEYR = FLASH_PEKEY2;
 
  }
 
}
 

	
 
void Minimal_EEPROM_Lock(void)
 
{
 
  /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */
 

	
 
  // Set the PELOCK Bit to lock the data memory and FLASH_PECR register access 
 
  FLASH->PECR |= FLASH_PECR_PELOCK;
 
}
 

	
 
FLASH_Status Minimal_FLASH_GetStatus(void)
 
{
 
  FLASH_Status FLASHstatus = FLASH_COMPLETE;
 

	
 
  if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
 
  {
 
    FLASHstatus = FLASH_BUSY;
 
  }
 
  else
 
@@ -32,56 +35,56 @@ FLASH_Status Minimal_FLASH_GetStatus(voi
 
    else
 
    {
 
      if((FLASH->SR & (uint32_t)0x1E00) != (uint32_t)0x00)
 
      {
 
        FLASHstatus = FLASH_ERROR_PROGRAM;
 
      }
 
      else
 
      {
 
        FLASHstatus = FLASH_COMPLETE;
 
      }
 
    }
 
  }
 
  /* Return the FLASH Status */
 
  // Return the FLASH Status 
 
  return FLASHstatus;
 
}
 

	
 
FLASH_Status Minimal_FLASH_WaitForLastOperation(uint32_t Timeout)
 
{
 
  __IO FLASH_Status status = FLASH_COMPLETE;
 

	
 
  /* Check for the FLASH Status */
 
  // Check for the FLASH Status 
 
  status = Minimal_FLASH_GetStatus();
 

	
 
  /* Wait for a FLASH operation to complete or a TIMEOUT to occur */
 
  // Wait for a FLASH operation to complete or a TIMEOUT to occur 
 
  while((status == FLASH_BUSY) && (Timeout != 0x00))
 
  {
 
    status = Minimal_FLASH_GetStatus();
 
    Timeout--;
 
  }
 

	
 
  if(Timeout == 0x00 )
 
  {
 
    status = FLASH_TIMEOUT;
 
  }
 
  /* Return the operation status */
 
  // Return the operation status 
 
  return status;
 
}
 

	
 

	
 
void Minimal_EEPROM_ProgramWord(uint32_t Address, uint32_t Data)
 
{
 
  // Wait for last operation to be completed 
 
  FLASH_Status status = FLASH_COMPLETE;
 
  status = Minimal_FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
 

	
 
  if(status == FLASH_COMPLETE)
 
  {
 
    *(__IO uint32_t *)Address = Data;
 

	
 
    // Wait for last operation to be completed 
 
    status = Minimal_FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
 
  }
 
  // Return the Write Status 
 
  return status;
 
}
 

	
 
*/
gpio.c
Show inline comments
 
@@ -118,29 +118,29 @@ void init_gpio(void) {
 
  //Configure GPIO pin alternate function 
 
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
 
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
 
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
 

	
 

	
 
  /** USB GPIO Configuration  
 
  PA11   ------> USB_DM
 
  PA12   ------> USB_DP
 
  */
 

	
 
  /*Enable or disable the AHB peripheral clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
  //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 

	
 
  GPIO_InitTypeDef GPIO_InitStruct3;
 
  //GPIO_InitTypeDef GPIO_InitStruct3;
 
  
 
  /*Configure GPIO pin : PA */
 
  GPIO_InitStruct3.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;
 
  GPIO_InitStruct3.GPIO_Mode = GPIO_Mode_AF;
 
  GPIO_InitStruct3.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_InitStruct3.GPIO_Speed = GPIO_Speed_10MHz;
 
  GPIO_InitStruct3.GPIO_OType = GPIO_OType_PP;
 
  GPIO_Init(GPIOA, &GPIO_InitStruct3);
 
  GPIO_SetBits(GPIOA, GPIO_Pin_12); // emz test
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USB);
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USB);
 
  //GPIO_InitStruct3.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12;
 
  //GPIO_InitStruct3.GPIO_Mode = GPIO_Mode_AF;
 
  //GPIO_InitStruct3.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  //GPIO_InitStruct3.GPIO_Speed = GPIO_Speed_10MHz;
 
  //GPIO_InitStruct3.GPIO_OType = GPIO_OType_PP;
 
  //GPIO_Init(GPIOA, &GPIO_InitStruct3);
 
  //GPIO_SetBits(GPIOA, GPIO_Pin_12); // emz test
 
  //GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USB);
 
  //GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USB);
 
}
 

	
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
main.c
Show inline comments
 
@@ -334,73 +334,77 @@ 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)
 
 
void save_settings()
 
{
 
/*
 
   Minimal_EEPROM_Unlock();
 
    // Try programming a word at an address divisible by 4
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_BOOTTOBREW, boottobrew);
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_WINDUP_GUARD, windup_guard);
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_K_P, k_p);
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_K_I, k_i);
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_K_D, k_d);
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_UNITS, temp_units);
 
    Minimal_EEPROM_Lock();
 
*/
 
}
 
 
void save_setpoints()
 
{
 
/*
 
 
    Minimal_EEPROM_Unlock();
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_BREWTEMP, setpoint_brew);
 
    Minimal_EEPROM_ProgramWord(EEPROM_BASE_ADDR + EEPROM_ADDR_STEAMTEMP, setpoint_steam); 
 
    Minimal_EEPROM_Lock();
 
*/
 
}
 
 
 
// TODO: Make a struct that has all settings in it. Pass by ref to this func in a library.
 
void restore_settings()
 
{
 
    Minimal_EEPROM_Unlock();
 
/*    Minimal_EEPROM_Unlock();
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    boottobrew = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_BOOTTOBREW));
 
    
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    windup_guard = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_WINDUP_GUARD));
 
    
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    k_p = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_K_P));
 
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    k_i = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_K_I));
 
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    k_d = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_K_D));
 
    
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    setpoint_brew = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_BREWTEMP));
 
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    setpoint_steam = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_STEAMTEMP));    
 
    while(Minimal_FLASH_GetStatus()==FLASH_BUSY);
 
    temp_units = (*(__IO uint32_t*)(EEPROM_BASE_ADDR + EEPROM_ADDR_UNITS));    
 
 
    Minimal_EEPROM_Lock();
 
    Minimal_EEPROM_Lock(); */
 
}
 
 
int16_t last_temp = 21245;
 
 
 
///////////////////////////////////////////////////////////////////////////////////////
 
/// 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
therm-cube.ioc
Show inline comments
 
new file 100644
 
#MicroXplorer Configuration settings - do not modify
 
#Fri Nov 14 22:42:15 EST 2014
 
File.Version=4
 
KeepUserPlacement=false
 
Mcu.Family=STM32F0
 
Mcu.IP0=NVIC
 
Mcu.IP1=RCC
 
Mcu.IP2=SPI1
 
Mcu.IP3=SYS
 
Mcu.IP4=USART1
 
Mcu.IP5=USB
 
Mcu.IP6=USB_DEVICE
 
Mcu.IPNb=7
 
Mcu.Name=STM32F042K(4-6)Ux
 
Mcu.Package=UFQFPN32
 
Mcu.Pin0=PA1
 
Mcu.Pin1=PA2
 
Mcu.Pin10=PA12
 
Mcu.Pin11=PA13
 
Mcu.Pin12=PA14
 
Mcu.Pin13=PA15
 
Mcu.Pin14=PB3
 
Mcu.Pin15=PB4
 
Mcu.Pin16=PB5
 
Mcu.Pin17=PB6
 
Mcu.Pin18=PB7
 
Mcu.Pin19=PB8
 
Mcu.Pin2=PA3
 
Mcu.Pin20=VP_RCC_USB
 
Mcu.Pin21=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
 
Mcu.Pin3=PA4
 
Mcu.Pin4=PA5
 
Mcu.Pin5=PA6
 
Mcu.Pin6=PA7
 
Mcu.Pin7=PA9
 
Mcu.Pin8=PA10
 
Mcu.Pin9=PA11
 
Mcu.PinsNb=22
 
Mcu.UserName=STM32F042K6Ux
 
NVIC.SysTick_IRQn=true\:0\:0
 
NVIC.USB_IRQn=true\:0\:0
 
PA1.Locked=true
 
PA1.Signal=GPIO_Output
 
PA10.Locked=true
 
PA10.Mode=Asynchronous
 
PA10.Signal=USART1_RX
 
PA11.Locked=true
 
PA11.Mode=Device
 
PA11.Signal=USB_DM
 
PA12.Mode=Device
 
PA12.Signal=USB_DP
 
PA13.Locked=true
 
PA13.Mode=Serial-WireDebug
 
PA13.Signal=SYS_SWDIO
 
PA14.Mode=Serial-WireDebug
 
PA14.Signal=SYS_SWCLK
 
PA15.Locked=true
 
PA15.Signal=GPIO_Output
 
PA2.Locked=true
 
PA2.Signal=GPIO_Output
 
PA3.Locked=true
 
PA3.Signal=GPIO_Output
 
PA4.Locked=true
 
PA4.Signal=GPIO_Output
 
PA5.Locked=true
 
PA5.Mode=Full_Duplex_Master
 
PA5.Signal=SPI1_SCK
 
PA6.Locked=true
 
PA6.Mode=Full_Duplex_Master
 
PA6.Signal=SPI1_MISO
 
PA7.Locked=true
 
PA7.Mode=Full_Duplex_Master
 
PA7.Signal=SPI1_MOSI
 
PA9.Locked=true
 
PA9.Mode=Asynchronous
 
PA9.Signal=USART1_TX
 
PB3.Locked=true
 
PB3.Signal=GPIO_Input
 
PB4.Locked=true
 
PB4.Signal=GPIO_Input
 
PB5.Locked=true
 
PB5.Signal=GPIO_Input
 
PB6.Locked=true
 
PB6.Signal=GPIO_Input
 
PB7.Locked=true
 
PB7.Signal=GPIO_Input
 
PB8.Locked=true
 
PB8.Signal=GPIO_Output
 
PCC.Family=STM32F0
 
PCC.MCU=STM32F042K(4-6)Ux
 
PCC.MXVersion=4.4.0
 
PCC.PartNumber=STM32F042K6Ux
 
PCC.Seq0=0
 
PCC.SubFamily=STM32F0x2
 
PCC.Temperature=25
 
PCC.Vdd=3.6
 
RCC.CECEnable-ClockTree=false
 
RCC.EnableHSE-ClockTree=false
 
RCC.EnableHSERTCDevisor-ClockTree=false
 
RCC.EnableLSE-ClockTree=false
 
RCC.EnableLSERTC-ClockTree=false
 
RCC.EnableMCOMultDivisor-ClockTree=false
 
RCC.FLatency-AdvancedSettings=FLASH_LATENCY_0
 
RCC.FamilyName=M
 
RCC.HSEState-ClockTree=RCC_HSE_OFF
 
RCC.HSI14State-ClockTree=RCC_HSI14_OFF
 
RCC.HSI48State-ClockTree=RCC_HSI48_ON
 
RCC.HSIState-ClockTree=RCC_HSI_ON
 
RCC.I2C1Enable-ClockTree=false
 
RCC.IPParameters=OscillatorTypeHSE-ClockTree,RTCEnable-ClockTree,EnableLSE-ClockTree,CECEnable-ClockTree,ReloadValue-AdvancedSettings,PLLCLKFreq_Value,FamilyName,PREFETCH_ENABLE-AdvancedSettings,OscillatorTypeHSI48-ClockTree,USBEnable-ClockTree,HSI14State-ClockTree,PLLMCOFreq_Value,IWDGEnable-ClockTree,HSI48State-ClockTree,FLatency-AdvancedSettings,EnableLSERTC-ClockTree,USART2Enable-ClockTree,Source-AdvancedSettings,VCOOutput2Freq_Value,MCOEnable-ClockTree,OscillatorTypeHSI-ClockTree,EnableMCOMultDivisor-ClockTree,I2C1Enable-ClockTree,HSIState-ClockTree,LSIState-ClockTree,PLLState-ClockTree,RCC_PERIPHCLK_USART1Var-ClockTree,USART1Enable-ClockTree,HSEState-ClockTree,EnableHSE-ClockTree,EnableHSERTCDevisor-ClockTree,OscillatorTypeLSI-ClockTree
 
RCC.IWDGEnable-ClockTree=false
 
RCC.LSIState-ClockTree=RCC_LSI_OFF
 
RCC.MCOEnable-ClockTree=false
 
RCC.OscillatorTypeHSE-ClockTree=
 
RCC.OscillatorTypeHSI-ClockTree=RCC_OSCILLATORTYPE_HSI
 
RCC.OscillatorTypeHSI48-ClockTree=RCC_OSCILLATORTYPE_HSI48
 
RCC.OscillatorTypeLSI-ClockTree=
 
RCC.PLLCLKFreq_Value=16000000
 
RCC.PLLMCOFreq_Value=16000000
 
RCC.PLLState-ClockTree=RCC_PLL_OFF
 
RCC.PREFETCH_ENABLE-AdvancedSettings=0
 
RCC.RCC_PERIPHCLK_USART1Var-ClockTree=RCC_PERIPHCLK_USART1
 
RCC.RTCEnable-ClockTree=false
 
RCC.ReloadValue-AdvancedSettings=__HAL_RCC_CRS_CALCULATE_RELOADVALUE(48000000,
 
RCC.Source-AdvancedSettings=RCC_CRS_SYNC_SOURCE_USB
 
RCC.USART1Enable-ClockTree=true
 
RCC.USART2Enable-ClockTree=false
 
RCC.USBEnable-ClockTree=true
 
RCC.VCOOutput2Freq_Value=8000000
 
SPI1.DataSize-Full_Duplex_Master=SPI_DATASIZE_8BIT
 
SPI1.Direction-Full_Duplex_Master=SPI_DIRECTION_2LINES
 
SPI1.IPParameters=Direction-Full_Duplex_Master,VirtualType-Full_Duplex_Master,TIMode-Full_Duplex_Master,Mode-Full_Duplex_Master,DataSize-Full_Duplex_Master,NSS-Full_Duplex_Master
 
SPI1.Mode-Full_Duplex_Master=SPI_MODE_MASTER
 
SPI1.NSS-Full_Duplex_Master=SPI_NSS_SOFT
 
SPI1.TIMode-Full_Duplex_Master=SPI_TIMODE_DISABLED
 
SPI1.VirtualType-Full_Duplex_Master=VM_MASTER
 
USART1.BaudRate=115200
 
USART1.HwFlowCtl-Asynchronous=UART_HWCONTROL_NONE
 
USART1.IPParameters=VirtualMode-Asynchronous,BaudRate,HwFlowCtl-Asynchronous,WordLength-Asynchronous
 
USART1.VirtualMode-Asynchronous=VM_ASYNC
 
USART1.WordLength-Asynchronous=UART_WORDLENGTH_7B
 
USB.IPParameters=phy_itface-Device,speed-Device
 
USB.phy_itface-Device=PCD_PHY_EMBEDDED
 
USB.speed-Device=PCD_SPEED_FULL
 
USB_DEVICE.CLASS_NAME-CDC_FS=CDC
 
USB_DEVICE.IPParameters=CLASS_NAME-CDC_FS,VirtualModeFS,VirtualMode,USBD_HandleTypeDef,hUsbDevice-CDC_FS,USBD_HandleTypeDef-CDC_FS,VirtualModeFS-CDC_FS,VirtualMode-CDC_FS
 
USB_DEVICE.USBD_HandleTypeDef=hUsbDeviceFS
 
USB_DEVICE.USBD_HandleTypeDef-CDC_FS=hUsbDeviceFS
 
USB_DEVICE.VirtualMode=Cdc
 
USB_DEVICE.VirtualMode-CDC_FS=Cdc
 
USB_DEVICE.VirtualModeFS=Cdc_FS
 
USB_DEVICE.VirtualModeFS-CDC_FS=Cdc_FS
 
USB_DEVICE.hUsbDevice-CDC_FS=hDeviceDuSmolt
 
VP_RCC_USB.Mode=CRS SYNC Source USB
 
VP_RCC_USB.Signal=RCC_USB
 
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS
 
VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS
0 comments (0 inline, 0 general)