Exemplo n.º 1
0
/**
  * @brief  SD Card Configuration.
  * @param  None
  * @retval None
  */
static void SDCard_Config(void)
{
  uint32_t error = 0;
  uint32_t counter = 0x100;

  /* Configure the IO Expander */
  if (IOE16_Config() != IOE16_OK)
  {
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LCD_LINE_6, (uint8_t*)"    IO Expander FAILED         ");
    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t*)"    Please Reset the board and ");
    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)"    Start again...             ");
    while(1)
    {
    }
  }

  /* SDCard initialisation */
  SD_Init();

  /* Configure the SD detect pin */
  IOE16_IOPinConfig(SD_DETECT_PIN, Direction_IN);

  if (SD_Detect() == SD_NOT_PRESENT)
  {
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)"    Please insert SD Card.     ");

    while (SD_Detect() == SD_NOT_PRESENT)
    {
    }
  }

  /* FAT Initialization */
  do
  {
    /* SDCARD Initialisation */
    error = Storage_Init();
  }
  while ((error != 0) && (counter-- != 0));

  /* SD Card not formatted */
  if (counter == 0)
  {
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_RED);

    LCD_DisplayStringLine(LCD_LINE_7, (uint8_t*)"    SD Card not formatted.  ");
    LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)"    Reprogram your card.    ");
    while (1)
    {
    }
  }
}
Exemplo n.º 2
0
DSTATUS disk_status (
	BYTE drv		/* Physical drive nmuber (0..) */
)
{

	switch (drv) /* 用户自己添加应用代码 */
	{
	  case 0 :
		
	  /* translate the reslut code here	*/
			if(SD_Detect()==SD_PRESENT)
					return 0;
			else
					return STA_NOINIT;

	  case 1 :
	
	  /* translate the reslut code here	*/

	    return STA_NODISK;

	  case 2 :
	
	  /* translate the reslut code here	*/

	    return STA_NODISK;

	  default:

        break;
	}
	return STA_NOINIT;
	
}
Exemplo n.º 3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to 
       application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* Initialize LEDs available on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);  

  /* NVIC Configuration */
  NVIC_Configuration();

  /*------------------------------ SD Init ---------------------------------- */
  if((Status = SD_Init()) != SD_OK)
  {
    STM_EVAL_LEDOn(LED4); 
  }
        
  while((Status == SD_OK) && (uwSDCardOperation != SD_OPERATION_END) && (SD_Detect()== SD_PRESENT))
  {
    switch(uwSDCardOperation)
    {
      /*-------------------------- SD Erase Test ---------------------------- */
      case (SD_OPERATION_ERASE):
      {
        SD_EraseTest();
        uwSDCardOperation = SD_OPERATION_BLOCK;
        break;
      }
      /*-------------------------- SD Single Block Test --------------------- */
      case (SD_OPERATION_BLOCK):
      {
        SD_SingleBlockTest();
        uwSDCardOperation = SD_OPERATION_MULTI_BLOCK;
        break;
      }       
      /*-------------------------- SD Multi Blocks Test --------------------- */
      case (SD_OPERATION_MULTI_BLOCK):
      {
        SD_MultiBlockTest();
        uwSDCardOperation = SD_OPERATION_END;
        break;
      }              
    }
  }
  
  /* Infinite loop */
  while (1)
  {
  }
}
Exemplo n.º 4
0
DRESULT disk_read (
        BYTE drv,               /* Physical drive nmuber (0..) */
        BYTE *buff,             /* Data buffer to store read data */
        DWORD sector,   				/* Sector address (LBA) */
        BYTE count              /* Number of sectors to read (1..255) */
)
{
	SD_Error Status;

#ifdef DBGIO
	printf("disk_read %d %p %10d %d\n",drv,buff,sector,count);
#endif
	
	if (SD_Detect() != SD_PRESENT)
		return(RES_NOTRDY);

	if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer
	{
		DRESULT res = RES_OK;
		DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack

		while(count--)
		{
			res = disk_read(drv, (void *)scratch, sector++, 1);

			if (res != RES_OK)
				break;

			memcpy(buff, scratch, BLOCK_SIZE);

			buff += BLOCK_SIZE;
		}

		return(res);
	}

  Status = SD_ReadMultiBlocksFIXED(buff, sector, BLOCK_SIZE, count); // 4GB Compliant

	if (Status == SD_OK)
	{
		SDTransferState State;

		Status = SD_WaitReadOperation(); // Check if the Transfer is finished

		while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)

		if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK))
			return(RES_ERROR);
		else
			return(RES_OK);
	}
	else
		return(RES_ERROR);
}
Exemplo n.º 5
0
int main (void)
{
        initUsart ();
        logf ("Init\r\n");

        /*!< At this stage the microcontroller clock setting is already configured,
         this is done through SystemInit() function which is called from startup
         files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s)
         before to branch to application main. To reconfigure the default setting
         of SystemInit() function, refer to system_stm32f4xx.c file
         */

        /* NVIC Configuration */
        NVIC_Configuration ();
        logf ("NVIC_Configuration\r\n");

        /*------------------------------ SD Init ---------------------------------- */
        if ((Status = SD_Init ()) != SD_OK) {
                logf ("SD_Init failed\r\n");
        }
        else {
                logf ("SD_Init OK\r\n");
        }

        while ((Status == SD_OK) && (uwSDCardOperation != SD_OPERATION_END) && (SD_Detect () == SD_PRESENT)) {
                switch (uwSDCardOperation) {
                        /*-------------------------- SD Single Block Test --------------------- */
                        case (SD_OPERATION_BLOCK):
                        {
                                SD_SingleBlockTest ();
                                uwSDCardOperation = SD_OPERATION_ERASE;
                                break;
                        }
                        /*-------------------------- SD Erase Test ---------------------------- */
                        case (SD_OPERATION_ERASE):
                        {
                                SD_EraseTest ();
                                uwSDCardOperation = SD_OPERATION_MULTI_BLOCK;
                                break;
                        }
                        /*-------------------------- SD Multi Blocks Test --------------------- */
                        case (SD_OPERATION_MULTI_BLOCK):
                        {
                                SD_MultiBlockTest ();
                                uwSDCardOperation = SD_OPERATION_END;
                                break;
                        }
                }
        }

        /* Infinite loop */
        while (1) {
        }
}
Exemplo n.º 6
0
DSTATUS disk_status (
        BYTE drv                /* Physical drive nmuber (0..) */
)
{
	DSTATUS stat = 0;
	
	if (SD_Detect() != SD_PRESENT)
		stat |= STA_NODISK;

	// STA_NOTINIT - Subsystem not initailized
	// STA_PROTECTED - Write protected, MMC/SD switch if available
	
	return(stat);
}
Exemplo n.º 7
0
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (
	BYTE drv				/* Physical drive number (0..) */
)
{
	if ( drv )
		return STA_NOINIT;

	if ( SD_Detect() == SD_NOT_PRESENT )
		return STA_NODISK;

	if ( SD_Init() != SD_RESPONSE_NO_ERROR )
		return STA_NOINIT;

	return 0;
}
Exemplo n.º 8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* High speed internal clock prescaler: 1*/
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);

  /* Initialize I/Os in Output Mode for LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /***********************SPI and MSD Card initialization******************/

  while (SD_Detect() == SD_NOT_PRESENT);
  {
    /* Wait MicroSD card insertion */
  }

  Delay(0xFFFF);
  /* Init the flash micro SD*/
  Status = SD_Init();

  /***************************Block Read/Write******************************/
  /* Write block of 512 bytes on address 0 */
  SD_WriteBlock(TxBuffer, 0, BUFFER_SIZE);

  /* Read block of 512 bytes from address 0 */
  SD_ReadBlock(RxBuffer, 0, BUFFER_SIZE);

  /* Check data */
  TransferStatus = Buffercmp(TxBuffer, RxBuffer, BUFFER_SIZE);
  if (TransferStatus != SUCCESS)
  {
    while (1) /* Go to infinite loop when there is mismatch in data programming*/
    {
      STM_EVAL_LEDToggle(LED1);
      Delay((uint16_t)0xFFFF);
    }
  }
  while (1)
  {
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    Delay((uint16_t)0xFFFF);
  }
}
Exemplo n.º 9
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* Clock configuration -----------------------------------------*/
    CLK_Config();
    
    /* GPIO Configuration ------------------------------------------*/
    GPIO_Config();

		
   /***********************SPI and MSD Card initialization******************/

    while (SD_Detect() == SD_NOT_PRESENT);
    {
      /* Wait MicroSD card insertion */
    }

    Delay(0xFFFF);
    /* Init the flash micro SD*/
    Status = SD_Init();

  /***************************Block Read/Write******************************/
  /* Write block of 512 bytes on address 0 */
  SD_WriteBlock(TxBuffer, 0, BUFFER_SIZE);

  /* Read block of 512 bytes from address 0 */
  SD_ReadBlock(RxBuffer, 0, BUFFER_SIZE);

  /* Check data */
  TransferStatus = Buffercmp(TxBuffer, RxBuffer, BUFFER_SIZE);
  if (TransferStatus != SUCCESS)
  {
    while (1) /* Go to infinite loop when there is mismatch in data programming*/
    {
      STM_EVAL_LEDToggle(LED1);
      Delay((uint16_t)0xFFFF);
      Delay((uint16_t)0xFFFF);
    }
  }
  while (1)
  {
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    Delay((uint16_t)0xFFFF);
    Delay((uint16_t)0xFFFF);
  }
}
Exemplo n.º 10
0
void sd_file_init(void)
{
	sd_card.sd_fs_ok = OK; // 默认SD正常,未损坏
	sd_card.rw_enable = ENABLE;		// 允许读写操作
	sd_card.state = SD_Detect();		 /*!< Check GPIO to detect SD */


	sd_card.spi_init_flag = sd_spi_init();

	fatfs_int();
	
//	if(	sd_card.fatfs_init_flag == PASSED)
//	{
//		CreatCanDataFile("Data");
//		fr = f_mkdir("Blind");
//		if(fr == FR_OK || fr == FR_EXIST)
//			printf("> 创建文件夹 Blind 成功\r\n");
//		else
//			printf("> 创建文件夹 Blind 失败\r\n");
//		
//		show_sd_files();
//	}

}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* Initialize LEDs available on STM324xG-EVAL board *************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);  

  STM324xG_LCD_Init();
  LCD_Clear(Black);
  LCD_SetBackColor(Black);
  LCD_SetTextColor(White);

  /* Interrupt Config */
  NVIC_Configuration();

  /*------------------------------ SD Init ---------------------------------- */
  if((Status = SD_Init()) != SD_OK)
  {
    STM_EVAL_LEDOn(LED4); 
	LCD_SetTextColor(Red);
	LCD_DisplayStringLine(LCD_LINE_0, "SD_Init failed");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_0, "SD_Init ok");
  }
        
  while((Status == SD_OK) && (SDCardOperation != SD_OPERATION_END) && (SD_Detect()== SD_PRESENT))
  {
    switch(SDCardOperation)
    {
      /*-------------------------- SD Erase Test ---------------------------- */
      case (SD_OPERATION_ERASE):
      {
        SD_EraseTest();
        SDCardOperation = SD_OPERATION_BLOCK;
	    LCD_DisplayStringLine(LCD_LINE_1, "SD_EraseTest");
        break;
      }
      /*-------------------------- SD Single Block Test --------------------- */
      case (SD_OPERATION_BLOCK):
      {
        SD_SingleBlockTest();
        SDCardOperation = SD_OPERATION_MULTI_BLOCK;
		LCD_DisplayStringLine(LCD_LINE_1, "SD_SingleBlockTest");
        break;
      }       
      /*-------------------------- SD Multi Blocks Test --------------------- */
      case (SD_OPERATION_MULTI_BLOCK):
      {
        SD_MultiBlockTest();
        SDCardOperation = SD_OPERATION_END;
		LCD_DisplayStringLine(LCD_LINE_1, "SD_MultiBlockTest");
        break;
      }              
    }
	delay(10000000);
  }
  
  LCD_DisplayStringLine(LCD_LINE_3, "End");
  /* Infinite loop */
  while (1)
  {}
}
Exemplo n.º 12
0
/**************************************************************/
//程 序 名: main()
//开 发 者: MingH
//入口参数: 无
//功能说明: 主函数
//**************************************************************/
int main(void)
{
	unsigned char err_code;
	RCC_Config();		// 时钟初始化配置
	Beep_Init();		// 蜂鸣器初始化配置
	Touch_Init();
	Pcie_Gpio_Init();
	Tim3_Init();
	
	RGB_Init();     //RGB 初始化
	RCC_GetClocksFreq(&RCC_ClockFreq);		
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);	
	USB2Serial_Init(); 	// 串口初始化配置
	Pwm_Init();
	Adc_Init();
	I2C_GPIO_Configuration();
	err_code = LIS3DH_Init();
	
	if (NO_ERROR == err_code)
	{
		printf("\r\nLIS3DH Init is succeed! \r\n");
	}
	else
	{
		printf("\r\nLIS3DH Init is failed! \r\n");
	}
	
	RTC_Init(); 		// RTC 初始化配置


	if(SD_Init() == SD_OK) {
	
		printf ("\r\n发现SD卡!\r\n");
	}
	else {
		printf("\r\n没有发现 SD 卡设备! \r\n");
	}
	printf("\r\n\r\n");
	save_sd_detect = SD_Detect(); //初始化SD卡插入状态
	
	SysTick_Delay_ms(500);
	TIM_Cmd(TIM1, DISABLE);
	TIM_CtrlPWMOutputs(TIM1, DISABLE);
	while (1)
	{
		if(read_sd_detect_flag){
			
			if (save_sd_detect != SD_Detect()){
				/* 蜂鸣器响 */
				TIM_Cmd(TIM1, ENABLE);
				TIM_CtrlPWMOutputs(TIM1, ENABLE);
				sd_detect_change = 1; //SD卡插入状态有变
				buzzer_delay = 0;
				if (SD_Detect() != SD_NOT_PRESENT){
						if(SD_Init() == SD_OK) {
							printf ("\r\n发现SD卡!\r\n");
						}
						else {
							printf("\r\n没有发现 SD 卡设备! \r\n");
						}
						printf("\r\n\r\n");
				}
			}
			save_sd_detect = SD_Detect();
			read_sd_detect_flag = 0;
		}
		
		
		Time_Show();	
		Test_Pcie_Gpio();
		Touch_Key_Proc();
		
		if (read_lis3dh_flag){
			Collect_Data(ACCdata);
			for (i=0; i<3; i++){
				if (oldACCdata[i] < ACCdata[i]){
					ACCdiff[i] = ACCdata[i] - oldACCdata[i];
				}
				else{
					ACCdiff[i] = oldACCdata[i] - ACCdata[i];
				}
			}
			RGB_Control(ACCdiff[0]<<1, ACCdiff[1]<<1, ACCdiff[2]<<1);
			for (i=0; i<3; i++){
				oldACCdata[i] = ACCdata[i];
			}
			read_lis3dh_flag = 0;
		}
		if (one_second_flag){
			printf("X=%d, Y=%d, Z=%d\r\n\r\n", ACCdata[1], ACCdata[0], ACCdata[2]);
			Adc_Proc();
			one_second_flag = 0;
		}
	}
}