Changeset - f7aa98ec64f4
[Not reviewed]
default
1 3 0
Ethan Zonca - 10 years ago 2014-07-10 17:23:37
ez@ethanzonca.com
Added system configuration from ST configuration excel file
4 files changed with 30 insertions and 560 deletions:
0 comments (0 inline, 0 general)
libraries/CMSIS/Device/ST/STM32L1xx/Source/Templates/system_stm32l1xx.c
Show inline comments
 
deleted file
main.c
Show inline comments
 
@@ -6,12 +6,13 @@ static __IO uint32_t TimingDelay;
 
uint8_t BlinkSpeed = 0;
 
 
 
/* Main */
 
int main(void)
 
{
 
   SystemInit();
 
   RCC_ClocksTypeDef RCC_Clocks;
 
  
 
  /* Configure LED3 and LED4 on STM32L100C-Discovery */
 
  STM_EVAL_LEDInit(LED3);
 
  STM_EVAL_LEDInit(LED4);
 
  
 
@@ -24,15 +25,15 @@ int main(void)
 
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
 
 
 /* Initiate Blink Speed variable */ 
 
  BlinkSpeed = 1;
 
 
 /* Init lcd driver */
 
  SSD1303_Init();
 
  SSD1303_DrawPoint(3,3,1);
 
  SSD1303_DrawPoint(5,5,0);
 
//  SSD1303_Init();
 
//  SSD1303_DrawPoint(3,3,1);
 
//  SSD1303_DrawPoint(5,5,0);
 
  
 
  STM_EVAL_LEDOn(LED4);
 
  Delay(1000);
 
  STM_EVAL_LEDOff(LED4);
 
  Delay(1000);
 
ssd1306.c
Show inline comments
 
@@ -23,14 +23,13 @@
 
#define   SSD1303_Y_PIXEL   64
 
 
/* Private macro -------------------------------------------------------------*/
 
#define   SSD1303_Buffer    (_SSD1303_Buffer + SSD1303_COLUMN_MARGIN_START)
 
 
/* Private variables ---------------------------------------------------------*/
 
static  uint8_t  _SSD1303_Buffer[SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER 
 
+ SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END] = {0};
 
static  uint8_t  _SSD1303_Buffer[SSD1303_COLUMN_NUMBER*SSD1303_PAGE_NUMBER + SSD1303_COLUMN_MARGIN_START + SSD1303_COLUMN_MARGIN_END] = {0};
 
static  uint8_t  pageIndex = 0;
 
static  uint8_t  iS_SSD_On = 0;
 
static  uint8_t  pre_on = 0;
 
static  uint8_t  curContrast = 0xCC;
 
static  uint8_t  lastContrast = 0xCC;
 
 
@@ -78,12 +77,16 @@ void WriteData(unsigned char data)
 
* Input          : None
 
* Output         : None
 
* Return         : None
 
*******************************************************************************/
 
void SSD1303_Init(void)
 
{
 
 
  /* Initialize SPI2 */
 
  // TODO
 
 
  /* Generate a reset */
 
  SSD_Reset_Low();
 
  uint32_t i ;
 
  for(i=5000;--i;);
 
  SSD_Reset_High();
 
  
system_stm32l1xx.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * @file    system_stm32l1xx.c
 
  * @author  MCD Application Team
 
  * @version V1.0.0
 
  * @date    29-July-2013
 
  * @version V1.2.0
 
  * @date    10-July-2014
 
  * @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
 
  *          This file contains the system clock configuration for STM32L1xx Ultra
 
  *          Low power devices, and is generated by the clock configuration 
 
  *          tool STM32L1xx_Clock_Configuration_V1.1.0.xls
 
  *          tool  STM32L1xx_Clock_Configuration_V1.2.0.xls
 
  *             
 
  * 1.  This file provides two functions and one global variable to be called from 
 
  *     user application:
 
  *      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
 
  *                      and Divider factors, AHB/APBx prescalers and Flash settings),
 
  *                      depending on the configuration made in the clock xls tool. 
 
@@ -40,13 +40,13 @@
 
  *    value to your own configuration.
 
  * 
 
  * 5. This file configures the system clock as follows:  
 
  *=============================================================================
 
  *                         System Clock Configuration
 
  *=============================================================================
 
  *        System Clock source          | PLL(HSI)
 
  *        System Clock source          | PLL(HSE)
 
  *----------------------------------------------------------------------------- 
 
  *        SYSCLK                       | 32000000 Hz
 
  *----------------------------------------------------------------------------- 
 
  *        HCLK                         | 32000000 Hz
 
  *----------------------------------------------------------------------------- 
 
  *        AHB Prescaler                | 1
 
@@ -54,26 +54,25 @@
 
  *        APB1 Prescaler               | 1
 
  *----------------------------------------------------------------------------- 
 
  *        APB2 Prescaler               | 1
 
  *----------------------------------------------------------------------------- 
 
  *        HSE Frequency                | 8000000 Hz
 
  *----------------------------------------------------------------------------- 
 
  *        PLL DIV                      | 2
 
  *        PLL DIV                      | 3
 
  *----------------------------------------------------------------------------- 
 
  *        PLL MUL                      | 4
 
  *        PLL MUL                      | 12
 
  *----------------------------------------------------------------------------- 
 
  *        VDD                          | 3.3 V
 
  *----------------------------------------------------------------------------- 
 
  *        Vcore                        | 1.8 V (Range 1)
 
  *----------------------------------------------------------------------------- 
 
  *        Flash Latency                | 1 WS
 
  *----------------------------------------------------------------------------- 
 
  *        Require 48MHz for USB clock  | Disabled
 
  *        Require 48MHz for USB clock  | Enabled
 
  *----------------------------------------------------------------------------- 
 
  *=============================================================================
 
  ******************************************************************************
 
  * @attention
 
  *
 
  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
 
  *
 
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 
  * You may not use this file except in compliance with the License.
 
@@ -295,52 +294,51 @@ void SystemCoreClockUpdate (void)
 
  *         is reset to the default reset state (done in SystemInit() function).             
 
  * @param  None
 
  * @retval None
 
  */
 
static void SetSysClock(void)
 
{
 
  __IO uint32_t StartUpCounter = 0, HSIStatus = 0;
 
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;
 
  
 
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
 
  /* Enable HSI */
 
  RCC->CR |= ((uint32_t)RCC_CR_HSION);
 
  /* Enable HSE */
 
  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 
 
 
  /* Wait till HSI is ready and if Time out is reached exit */
 
  /* Wait till HSE is ready and if Time out is reached exit */
 
  do
 
  {
 
    HSIStatus = RCC->CR & RCC_CR_HSIRDY;
 
  } while((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));
 
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
 
    StartUpCounter++;
 
  } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
 
 
  if ((RCC->CR & RCC_CR_HSIRDY) != RESET)
 
  if ((RCC->CR & RCC_CR_HSERDY) != RESET)
 
  {
 
    HSIStatus = (uint32_t)0x01;
 
    HSEStatus = (uint32_t)0x01;
 
  }
 
  else
 
  {
 
    HSIStatus = (uint32_t)0x00;
 
    HSEStatus = (uint32_t)0x00;
 
  }
 
    
 
  if (HSIStatus == (uint32_t)0x01)
 
  if (HSEStatus == (uint32_t)0x01)
 
  {
 
    /* Enable 64-bit access */
 
    FLASH->ACR |= FLASH_ACR_ACC64;
 
    
 
    /* Enable Prefetch Buffer */
 
    FLASH->ACR |= FLASH_ACR_PRFTEN;
 
 
    /* Flash 1 wait state */
 
    FLASH->ACR |= FLASH_ACR_LATENCY;
 
    
 
 
    /* Power enable */
 
    RCC->APB1ENR |= RCC_APB1ENR_PWREN;
 
  
 
    /* Select the Voltage Range 1 (1.8 V) */
 
    PWR->CR = PWR_CR_VOS_0;
 
  
 
  
 
    /* Wait Until the Voltage Regulator is ready */
 
    while((PWR->CSR & PWR_CSR_VOSF) != RESET)
 
    {
 
    }
 
      
 
    /* HCLK = SYSCLK /1*/
 
@@ -352,13 +350,13 @@ static void SetSysClock(void)
 
    /* PCLK1 = HCLK /1*/
 
    RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
 
    
 
    /*  PLL configuration */
 
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL |
 
                                        RCC_CFGR_PLLDIV));
 
    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSI | RCC_CFGR_PLLMUL4 | RCC_CFGR_PLLDIV2);
 
    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMUL12 | RCC_CFGR_PLLDIV3);
 
 
    /* Enable PLL */
 
    RCC->CR |= RCC_CR_PLLON;
 
 
    /* Wait till PLL is ready */
 
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
 
@@ -373,13 +371,13 @@ static void SetSysClock(void)
 
    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
 
    {
 
    }
 
  }
 
  else
 
  {
 
    /* If HSI fails to start-up, the application will have wrong clock
 
    /* If HSE fails to start-up, the application will have wrong clock
 
       configuration. User can add here some code to deal with this error */
 
  }
 
}
 
 
/**
 
  * @}
 
@@ -391,6 +389,7 @@ static void SetSysClock(void)
 
 
/**
 
  * @}
 
  */
 
 
/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
 

	
0 comments (0 inline, 0 general)