Changeset - 6f724d71c0ec
[Not reviewed]
default
0 2 0
Ethan Zonca - 10 years ago 2014-08-15 23:15:19
ez@ethanzonca.com
Stripped out some code and added USB init. May have bricked IC.
2 files changed with 7 insertions and 88 deletions:
0 comments (0 inline, 0 general)
hw_config.c
Show inline comments
 
@@ -59,41 +59,35 @@ extern LINE_CODING linecoding;
 
* Description    : Configures Main system clocks & power
 
* Input          : None.
 
* Return         : None.
 
*******************************************************************************/
 
void Set_System(void)
 
{
 
#if !defined(STM32L1XX_MD) && !defined(STM32L1XX_HD) && !defined(STM32L1XX_MD_PLUS)
 
  GPIO_InitTypeDef GPIO_InitStructure;
 
#endif /* STM32L1XX_MD && STM32L1XX_XD */  
 
 
#if defined(USB_USE_EXTERNAL_PULLUP)
 
  GPIO_InitTypeDef  GPIO_InitStructure;
 
#endif /* USB_USE_EXTERNAL_PULLUP */ 
 
  
 
  /*!< At this stage the microcontroller clock setting is already configured, 
 
       this is done through SystemInit() function which is called from startup
 
       file (startup_stm32f10x_xx.s) before to branch to application main.
 
       To reconfigure the default setting of SystemInit() function, refer to
 
       system_stm32f10x.c file
 
     */   
 
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD)|| defined(STM32L1XX_MD_PLUS) || defined(STM32F37X) || defined(STM32F30X)
 
  /* Enable the SYSCFG module clock */
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
 
#endif /* STM32L1XX_XD */ 
 
   
 
#if !defined(STM32L1XX_MD) && !defined(STM32L1XX_HD) && !defined(STM32L1XX_MD_PLUS) && !defined(STM32F37X) && !defined(STM32F30X)
 
  /* Enable USB_DISCONNECT GPIO clock */
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
 
  //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
 
 
  /* Configure USB pull-up pin */
 
  GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
 
  GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
 
#endif /* STM32L1XX_MD && STM32L1XX_XD */
 
  //GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
 
  //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
 
  //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
 
  //GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
 
   
 
#if defined(USB_USE_EXTERNAL_PULLUP)
 
  /* Enable the USB disconnect GPIO clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
 
 
  /* USB_DISCONNECT used as USB pull-up */
 
@@ -102,39 +96,12 @@ void Set_System(void)
 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
 
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);  
 
#endif /* USB_USE_EXTERNAL_PULLUP */ 
 
  
 
#if defined(STM32F37X) || defined(STM32F30X)
 
  
 
  /* Enable the USB disconnect GPIO clock */
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
 
  
 
  /*Set PA11,12 as IN - USB_DM,DP*/ 
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
 
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  
 
  /*SET PA11,12 for USB: USB_DM,DP*/
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_14);
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_14);
 
  
 
  /* USB_DISCONNECT used as USB pull-up */
 
  GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
 
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
 
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
  GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
 
#endif /* STM32F37X  && STM32F30X)*/
 
 
 
   /* Configure the EXTI line 18 connected internally to the USB IP */
 
  EXTI_ClearITPendingBit(EXTI_Line18);
 
  EXTI_InitStructure.EXTI_Line = EXTI_Line18;
 
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
 
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
 
  EXTI_Init(&EXTI_InitStructure); 
 
@@ -145,23 +112,14 @@ void Set_System(void)
 
* Description    : Configures USB Clock input (48MHz)
 
* Input          : None.
 
* Return         : None.
 
*******************************************************************************/
 
void Set_USBClock(void)
 
{
 
#if defined(STM32L1XX_MD) || defined(STM32L1XX_HD) || defined(STM32L1XX_MD_PLUS) 
 
  /* Enable USB clock */
 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
 
  
 
#else 
 
  /* Select USBCLK source */
 
  RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
 
  
 
  /* Enable the USB clock */
 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
 
#endif /* STM32L1XX_MD */
 
}
 
 
/*******************************************************************************
 
* Function Name  : Enter_LowPowerMode
 
* Description    : Power-off system clocks and power while entering suspend mode
 
* Input          : None.
 
@@ -207,83 +165,42 @@ void USB_Interrupts_Config(void)
 
{
 
NVIC_InitTypeDef NVIC_InitStructure;
 
 
  /* 2 bit for pre-emption priority, 2 bits for subpriority */
 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
 
 
 
#if defined(STM32L1XX_MD)|| defined(STM32L1XX_HD) || defined(STM32L1XX_MD_PLUS)
 
  /* Enable the USB interrupt */
 
  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
 
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
  NVIC_Init(&NVIC_InitStructure);
 
 
  /* Enable the USB Wake-up interrupt */
 
  NVIC_InitStructure.NVIC_IRQChannel = USB_FS_WKUP_IRQn;
 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
 
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
  NVIC_Init(&NVIC_InitStructure);
 
 
#elif defined(STM32F37X)
 
  /* Enable the USB interrupt */
 
  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
 
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
  NVIC_Init(&NVIC_InitStructure);
 
  
 
  /* Enable the USB Wake-up interrupt */
 
  NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
 
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
  NVIC_Init(&NVIC_InitStructure);
 
  
 
#else
 
  /* Enable the USB interrupt */
 
  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
 
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
  NVIC_Init(&NVIC_InitStructure);
 
  
 
  /* Enable the USB Wake-up interrupt */
 
  NVIC_InitStructure.NVIC_IRQChannel = USBWakeUp_IRQn;
 
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
 
  NVIC_Init(&NVIC_InitStructure);   
 
#endif
 
}
 
 
/*******************************************************************************
 
* Function Name  : USB_Cable_Config
 
* Description    : Software Connection/Disconnection of USB Cable
 
* Input          : None.
 
* Return         : Status
 
*******************************************************************************/
 
void USB_Cable_Config (FunctionalState NewState)
 
{
 
#if defined(STM32L1XX_MD) || defined (STM32L1XX_HD)|| (STM32L1XX_MD_PLUS)
 
  if (NewState != DISABLE)
 
  {
 
    STM32L15_USB_CONNECT;
 
  }
 
  else
 
  {
 
    STM32L15_USB_DISCONNECT;
 
  }  
 
  
 
#else /* USE_STM3210B_EVAL or USE_STM3210E_EVAL */
 
  if (NewState != DISABLE)
 
  {
 
    GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
 
  }
 
  else
 
  {
 
    GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
 
  }
 
#endif /* STM32L1XX_MD */
 
}
 
 
/*******************************************************************************
 
* Function Name  : Get_SerialNum.
 
* Description    : Create the serial number string descriptor.
 
* Input          : None.
main.c
Show inline comments
 
@@ -42,12 +42,14 @@ int main(void)
 
    SystemInit();
 
 
    init_gpio();
 
 
    Set_USBClock();
 
    USB_Interrupts_Config();
 
    USB_Init();
 
 
    GPIO_SetBits(LED_POWER);
 
    USB_Init(); // freezes here... maybe clock issue?
 
 
    RCC_ClocksTypeDef RCC_Clocks;
 
 
    // SysTick end of count event each 1ms
0 comments (0 inline, 0 general)