/*******Test_Module_TYPE == Test_LED END*******/ ///*******Test_Module_TYPE == Test_IMU*******/ void Module_setup(void) { u32 total,free; Modules_Power_Control(ALL_Module,1); USART_INIT(115200,3,ENABLE); //serial port 2 initialize, baud rate 9600 ,enable receive interupt (bluebooth) USART_INIT(9600,2,ENABLE); //Initializes the IMU all modules IMU_INIT(IMU_ALL_IC); GPS_Config(); LED_Init(); if(SD_Init()!= SD_OK){ printf("SD Init failed!\r\n"); } else printf("SD Init OK!\r\n"); exfuns_init(); f_mount(fs[0],"0:",1); if(exf_getfree((u8 *)"0",&total,&free)) { printf("SD Card Fatfs Error!\r\n"); } else{ printf("SD Total Size: %d MB\r\n",total>>10); printf("SD Free Size: %d MB\r\n",free>>10); } }
void fatfs_int(void) { uint8_t timeout =2; char buf[120]; sd_card.fatfs_init_flag = FAILED; if (sd_card.spi_init_flag == FAILED) return; printf("\r\n> load fatfs.\r\n\r\n"); exfuns_init(); //为fatfs相关变量申请内存 printf("mount sd card ...\r\n"); fr = f_mount(0,fs[0]); //挂载SD卡 if(fr == FR_OK) { printf(" -- Register work area for the drive 0 \r\n"); sd_card.Warn.Bit.err_mount = PASSED; while(exf_getfree("0",&sd_card.totalSize,&sd_card.freeSize)) //得到SD卡的总容量和剩余容量 { delay_ms(1000); printf("check sd\r\n"); delay_ms(1000); printf("check sd\r\n"); delay_ms(1000); printf("check sd\r\n"); timeout--; if(timeout == 0) break; } printf(" -- Total Size: %dMB\r\n",sd_card.totalSize>>10); //显示SD卡总容量 MB printf(" -- Free Size: %dMB\r\n",sd_card.freeSize>>10); //显示SD卡剩余容量 MB }
void SDCard_Init(void) { u32 total,free; u8 res=0; W25QXX_Init(); //初始化W25Q128 my_mem_init(SRAMIN); //初始化内部内存池 my_mem_init(SRAMCCM); //初始化CCM内存池 while(SD_Init())//检测不到SD卡 { LCD_ShowString(30,150,200,16,16,"SD Card Error!"); delay_ms(500); LCD_ShowString(30,150,200,16,16,"Please Check! "); delay_ms(500); LED0=!LED0;//DS0闪烁 } exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 res=f_mount(fs[1],"1:",1); //挂载FLASH. if(res==0X0D)//FLASH磁盘,FAT文件系统错误,重新格式化FLASH { LCD_ShowString(30,150,200,16,16,"Flash Disk Formatting..."); //格式化FLASH res=f_mkfs("1:",1,4096);//格式化FLASH,1,盘符;1,不需要引导区,8个扇区为1个簇 if(res==0) { f_setlabel((const TCHAR *)"1:ALIENTEK"); //设置Flash磁盘的名字为:ALIENTEK LCD_ShowString(30,150,200,16,16,"Flash Disk Format Finish"); //格式化完成 }else LCD_ShowString(30,150,200,16,16,"Flash Disk Format Error "); //格式化失败 delay_ms(1000); } LCD_Fill(30,150,240,150+16,WHITE); //清除显示 while(exf_getfree("0",&total,&free)) //得到SD卡的总容量和剩余容量 { LCD_ShowString(30,150,200,16,16,"SD Card Fatfs Error!"); delay_ms(200); LCD_Fill(30,150,240,150+16,WHITE); //清除显示 delay_ms(200); LED0=!LED0;//DS0闪烁 } POINT_COLOR=BLUE;//设置字体为蓝色 LCD_ShowString(30,150,200,16,16,"FATFS OK!"); LCD_ShowString(30,170,200,16,16,"SD Total Size: MB"); LCD_ShowString(30,190,200,16,16,"SD Free Size: MB"); LCD_ShowNum(30+8*14,170,total>>10,5,16); //显示SD卡总容量 MB LCD_ShowNum(30+8*14,190,free>>10,5,16); //显示SD卡剩余容量 MB }
/*******Test_Module_TYPE == Test_GPS END *******/ ///*********Test_Module_TYPE == Test_SD**************/ void Module_setup_sd(void) { u32 total,free; //open bule power for testing // Modules_Power_Control(Zigbee_Power,1); USART_INIT(115200,3,ENABLE); // //open SD power Modules_Power_Control(SD_Power,1); Modules_Power_Control(IMU_Blue_Power,1); Modules_Power_Control(GPS_Power,1); //Initializes serial port 2 USART_INIT(9600,2,ENABLE); //Initializes the IMU all modules IMU_INIT(IMU_ALL_IC); GPS_Config(); printf("Before SDCARD init\r\n"); // //³õʼ»¯SD¿¨ SD initialize if(SD_Init()!= SD_OK){ printf("SD Init failed!\r\n"); } else printf("SD Init OK!\r\n"); exfuns_init(); f_mount(fs[0],"0:",1); if(exf_getfree((u8 *)"0",&total,&free)) { printf("SD Card Fatfs Error!\r\n"); } else{ printf("SD Total Size: %d MB\r\n",total>>10); printf("SD Free Size: %d MB\r\n",free>>10); } }
void disk_size(unsigned long* total,unsigned long* free) { exf_getfree((u8*)"0",(u32*)total,(u32*)free); }