Beispiel #1
0
/*******************************************************************************
* Function Name  : Set_System
* Description    : Configures Main system clocks & power
* Input          : None.
* Return         : None.
*******************************************************************************/
void Set_System(void)
{
  /* RCC configuration */
  RCC_Config();

  /* Enable and GPIOD clock */
  USB_Disconnect_Config();

  /* MAL configuration */
  MAL_Config();
}
Beispiel #2
0
/*******************************************************************************
* Function Name  : Set_System
* Description    : Configures Main system clocks & power
* Input          : None.
* Return         : None.
*******************************************************************************/
void Set_System(void)
{

  /* RCC configuration */
  RCC_Config();

  #if defined (USE_STM3210B_EVAL) || defined (USE_STM3210E_EVAL)  
  /* Enable and Disconnect Line GPIO clock */
  USB_Disconnect_Config();
  #endif /* (USE_STM3210B_EVAL) || (USE_STM3210E_EVAL) */

  /* MAL configuration */
  MAL_Config();
}
void OTPWriter_Init(void)
{
	u16 res;

#ifndef OTPWriter_IAP
	HS_PacketInfo PacketInfo;
#endif
	delay_init(72);
	//NVIC_Configuration();
	USB_Disconnect_Config();	  //USB软连接断开控制引脚
	//Console_init();
#ifdef OTPWriter_IAP
    u8 key = 0;
	printf("%s\r\n", SysInfo_OTPWriter_IAP);

	key = g_KEY.IsReleased();

	if(key==1)
	{
		MSD0_SPI_Configuration();
		//挂载文件系统
		disk_initialize(0);
		res = f_mount(0,&fs);
		if(res != FR_OK){
			printf("mount filesystem 0 failed : %d\r\n",res);
		}

		OTPWriter_IAP_from_SD();
		Execute_New_program();
	}
	else
		Execute_New_program();

#else		 //#ifdef OTPWriter_IAP
	printf("%s\r\n", SysInfo_OTPWriter);
	usb_init();
	//OTP_SPI_Init();
	MSD0_SPI_Configuration();
	//挂载文件系统
	disk_initialize(0);
	res = f_mount(0,&fs);
	if(res != FR_OK){
		printf("mount filesystem 0 failed : %d\r\n",res);
	}
	LED_Light(5);
#endif
}
/*******************************************************************************
* Function Name  : Mass_Storage_Start
* Description    : Starts the mass storage demo.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Mass_Storage_Start (void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  
#if 1  
  /* Enable and GPIOD clock */
  USB_Disconnect_Config();
#endif  

  

  /* MAL configuration */
  MAL_Config();

  Set_USBClock();

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  USB_Init();

  

}
Beispiel #5
0
void Board_main(void)
{   
  
  
    uint8_t i;
    uint16_t flash_flag = 0;
    uint16_t copy_file_flag = 0;
    
    /* RCC system reset(for debug purpose) */
    RCC_DeInit();
    
    /* Enable HSE */
    RCC_HSEConfig(RCC_HSE_ON);
    
    /* Wait till HSE is ready */
    HSEStartUpStatus = RCC_WaitForHSEStartUp();
    
    if(HSEStartUpStatus == SUCCESS)
    {
    #if 0
        /* Enable Prefetch Buffer */
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
	FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
        /* Flash 2 wait state */
        FLASH_SetLatency(FLASH_Latency_2);

	#else
     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
	FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Enable);
	        /* Flash 2 wait state */
        /*FLASH_SetLatency(FLASH_Latency_2);*/
	FLASH_SetLatency(FLASH_Latency_0);	/*abin@ */
	#endif
        

        
        /* HCLK = SYSCLK */
        RCC_HCLKConfig(RCC_SYSCLK_Div1); 
        
        /* PCLK2 = HCLK */
        RCC_PCLK2Config(RCC_HCLK_Div1); 
        
        /* PCLK1 = HCLK/2 */
        RCC_PCLK1Config(RCC_HCLK_Div2);


	#if 0
        /* PLLCLK = 8MHz * 9 = 72 MHz */
	/*abin:note*/
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
//        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_8);
        
        /* Enable PLL */ 
        RCC_PLLCmd(ENABLE);
      
        /* Wait till PLL is ready */
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
        {
        }
        
        /* Select PLL as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
	        /* Wait till PLL is used as system clock source */
        while(RCC_GetSYSCLKSource() != 0x08)
        {
        }	
	#else
 RCC_PLLCmd(DISABLE);
	        /* Select HSE as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
	        /* Wait till PLL is used as system clock source */
        while(RCC_GetSYSCLKSource() != 0x04)
        {
        }	
         #endif
		  

    }
    
    /* Enable GPIOA, GPIOB, and AFIO clocks */
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO, ENABLE);
    
        /* Enable DMA1 ,DMA2 clock */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2, ENABLE);
    
    /* Enable ADC1 ADC2,and GPIOC clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 |RCC_APB2Periph_ADC2| RCC_APB2Periph_GPIOC, ENABLE);


    /* Enable PWR and BKP clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
  
    /* Enable write access to Backup domain */
    PWR_BackupAccessCmd(ENABLE);
    
    /* Clear Tamper pin Event(TE) pending flag */
    BKP_ClearFlag();

     #if ABIN_DEBUG
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  STM_EVAL_COMInit(COM1, &USART_InitStructure);

  /* Output a message on Hyperterminal using printf function */
  //sys_printf("\n\r abin 8M is ok moify flash latency :USART Init end \n\r");    
    
#endif 
  
    /*------------------- Resources Initialization -----------------------------*/
    /* GPIO Configuration */
    GPIO_Config();
  //sys_printf("\n\r abin mul2 :GPIO_Config \n\r");    

#if ABIN_CPU_UPGRADE2HIGHSPEED_OPTION
   USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
   if(USB_Plugin_State == 1)
   {
       //sys_printf("\n\r abin switch to high speed !!\n\r"); 
      UpgradeToHighSpeed(); 
     
   }
#endif

    /* Interrupt Configuration */
    InterruptConfig();
    
    /* Configure the systick */    
    SysTick_Configuration();
    
    /*------------------- Drivers Initialization -------------------------------*/
    
    /* Initialize the Low Power application */
    LowPower_Init();
    
    
    /* Enable WKUP pin */
    PWR_WakeUpPinCmd(ENABLE);
    
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
    
    
    RTC_Init();  
    
    
    /* If HSE is not detected at program startup */
    if(HSEStartUpStatus == ERROR)
    {
        /* Generate NMI exception */
        SCB->ICSR |= SCB_ICSR_NMIPENDSET;
    }  
    

    USB_Disconnect_Config();       
    GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);/*???abin@20100714*/
    
    WakupPin_Init();
    
          //sys_printf("\n\r abin before CheckPowerOnReason\n\r"); 
    CheckPowerOnReason();


      //sys_printf("\n\r abin after CheckPowerOnReason\n\r");    
    
      
    Board_ADC_Init();        

        
    /*init the flag*/  
    flash_flag = *(uint16_t *)FLASH_READY_ADDRESS;
    if( flash_flag != FLAG_FLASH_READY)
    {
    	     //sys_printf("\n\r abin ready to erase flash \n\r");  
        FLASH_Unlock();
        FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);	        
        //Erase the 32 page 32K
        for(i = 0;i< DATA_PAGES;i++)
        {
        	 //sys_printf("\n\r abin ready to erase aa"); 
            FLASH_ErasePage(DATA_LOGGER_ADDRESS_START + i * 1024);/*数据在Page1...page32存放*/
        }
        FLASH_ErasePage(FLASH_READY_ADDRESS); /*abin@20100715 没添加保护*/
        FLASH_ProgramHalfWord(FLASH_READY_ADDRESS , FLAG_FLASH_READY);

        FLASH_ErasePage(REOCRD_COUNT_ADDRESS);        
        FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , 0x0000);
        
        FLASH_Lock();
         //sys_printf("\n\r abin mul2 :erase flash end!!!\n\r"); 
    }
    
     //sys_printf("\n\r abin ready to erase flash end \n\r");  
    USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
    
    if(USB_Plugin_State == 0)
    {
        
      
        record_count =   *(uint16_t *)REOCRD_COUNT_ADDRESS;
        
        if(record_count >= 15428)
        {
            //Write the full flag
            //Do nothing....          
          while(1)
          {
           //sys_printf("\n\r sample end !!!!!!!!!!!!!!!!!!!!!\n\r"); 
            Led_One_By_One(4);
			/*应该进入standy 模式 abin@20100715*/
          }
        }
        else
        {
        //sys_printf("\n\r abin ready to add sample count \n\r");  
            FLASH_Unlock();
            FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);	        
            FLASH_ProgramHalfWord(DATA_LOGGER_ADDRESS_START + record_count * 2, GetTemperature());
            //Erase first
            FLASH_ErasePage(REOCRD_COUNT_ADDRESS);
            //Update the count
            record_count = record_count + 1;
            
            FLASH_ProgramHalfWord(REOCRD_COUNT_ADDRESS , record_count);
            FLASH_Lock();
            
            //sys_printf("\n\r abin add sample count :end\n\r"); 
        }
        

      	     //sys_printf("\n\r %000\n\r");
      GPIO_SetBits(GPIOA, GPIO_Pin_1);
	  #if 0
      Delay(25);
	  #else
      Delay(5);
	  
	  #endif
	  	     //sys_printf("\n\r %111\n\r");

    }
    else
    {
      
        Enable_SDcard();
        /*
        if there is usb connect, copy the data to sdcard. and start the mass storage
        */
        
        copy_file_flag =   *(uint16_t *)COPY_FILE_ADDRESS;

        if(copy_file_flag == FLAG_FILE_COPYED)
        {

              Write_Copy_File_Flag(FLAG_FILE_NO_COPYED);                    

              USB_Disconnect_Config();       
              GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
              Delay(10);
              GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN);
              
               /* Enable and GPIOD clock */
               Mass_Storage_Start ();                  
               while( bDeviceState != CONFIGURED)
               {
                  Led_Both(1);
               }
               
               USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
               while(    USB_Plugin_State == 1)/* U-DISK success ,then CPU Loop in here*/
              {
                        USB_Plugin_State = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14);
                        Led_One_By_One(1);
                         //sys_printf("\n\r abin :mul2  u disk !!!\n\r"); 
              }
              PowerOff();    
              Write_Copy_File_Flag(FLAG_FILE_NO_COPYED);                    
               
        }
        else
        {
              Write_Copy_File_Flag(FLAG_FILE_COPYED);
              Led_Green_Flink(3);
              NAND_FAT();  
              CreateDataLoggerFile();                          
              Write_Copy_File_Flag(FLAG_FILE_COPYED);
              //sys_printf("\n\r abin :mul2  NAND_FAT!!!\n\r"); 
        }
         //sys_printf("\n\r abin :mul2  Disable_SDcard!!!\n\r"); 
        Disable_SDcard();        
        BKP_WriteBackupRegister(BKP_POWER_ON, FLAG_POWER_OFF); 
        PWR_EnterSTANDBYMode();    

        /* Generate a system reset */  
        //NVIC_SystemReset();    
    }
    
     //sys_printf("\n\r @111 \n\r"); 
    /* Set the RTC Alarm after 60s */
    RTC_SetAlarm(RTC_GetCounter()+ 3);
	     //sys_printf("\n\r @222:RTC_GetCounter()=0x%x \n\r",RTC_GetCounter()); 

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    	     //sys_printf("\n\r @333\n\r");
    PWR_EnterSTANDBYMode();    
    
    
}
/*******************************************************************************
* Function Name  : Mass_Storage_Start
* Description    : Starts the mass storage demo.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Mass_Storage_Start (void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Disble the JoyStick interrupts */
  IntExtOnOffConfig(DISABLE);


  while(ReadKey() != NOKEY)
  {
  }

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Clear the LCD screen */
  LCD_Clear(White);

  LCD_SetDisplayWindow(160, 223, 128, 128);
 
  LCD_NORDisplay(USB_ICON);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Disable LCD Window mode */
  LCD_WindowModeDisable();
  
  /* Set the Back Color */
  LCD_SetBackColor(Blue);
  /* Set the Text Color */
  LCD_SetTextColor(White); 

  
  /* Display the "  Plug the USB   " message */
  LCD_DisplayStringLine(Line8, " Plug the USB Cable ");
  LCD_DisplayStringLine(Line9, "Exit:  Push JoyStick");
    
  /* Enable and GPIOD clock */
  USB_Disconnect_Config();
  
  /* MAL configuration */
  MAL_Config();

  Set_USBClock();

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  USB_Init();

  while (bDeviceState != CONFIGURED)
  {
    if(ReadKey() != NOKEY)
    {
      PowerOff();
      LCD_Clear(White);
      DisplayMenu();
      IntExtOnOffConfig(ENABLE);
      return;
    }
  }

  LCD_ClearLine(Line9);
  /* Display the "To stop Press SEL" message */
  LCD_DisplayStringLine(Line8, "  To stop Press SEL ");

  /* Loop until SEL key pressed */
  while(ReadKey() != SEL)
  {
  }

  PowerOff();
  
  LCD_Clear(White);
  DisplayMenu();
  IntExtOnOffConfig(ENABLE);
}