/** * @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) { } } }
/** * @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_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 */ /* 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) { } }
DSTATUS FATFS_SD_SDIO_disk_initialize(void) { Stat = STA_NOINIT; /* Configure the SDCARD device */ if (SD_Init() == MSD_OK) Stat &= ~STA_NOINIT; else Stat |= STA_NOINIT; return Stat; }
/** * @brief SDCARD Initialisation for FatFs * @param None * @retval err : Error status (0=> success, 1=> fail) */ uint32_t Storage_Init(void) { SD_Init(); /****************** FatFs Volume Acess ******************************/ if (f_mount(0, &fs)) { return 1; } return 0; }
/* This function will be called one time, when the hardware object is initialized by efs init(). This code should bring the hardware in a ready to use state. Optionally but recommended you should fill in the file->sectorCount feld with the number of sectors. This field is used to validate sectorrequests. */ esint8 if_initInterface(hwInterface* file, eint8* opts) { if (SD_Init() == SD_FALSE) return (-1); if (mci_read_configuration() == SD_FALSE) return (-2); file->sectorCount = CardConfig.sectorcnt; return 0; }
void sdmmc_sdcard_init() { DEBUGPRINT(topScreen, "sdmmc_sdcard_init ", handelSD.error, 10, 20 + 2*8, RGB(40, 40, 40), RGB(208, 208, 208)); InitSD(); //SD_Init2(); //Nand_Init(); Nand_Init(); DEBUGPRINT(topScreen, "nand_res ", nand_res, 10, 20 + 3*8, RGB(40, 40, 40), RGB(208, 208, 208)); SD_Init(); DEBUGPRINT(topScreen, "sd_res ", sd_res, 10, 20 + 4*8, RGB(40, 40, 40), RGB(208, 208, 208)); }
DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber (0..) */ ) { DSTATUS stat; int result; //result = MMC_disk_initialize(); SD_Init(); return 0; }
/*-----------------------------------------------------------------------*/ DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber (0..) */ ) { SD_Error Status; Status = SD_Init(); if(Status == SD_OK) return SD_OK; else return STA_NOINIT; }
SdioSecureDigitalCard::SdioSecureDigitalCard() { Nvic::configureIrq(SDIO_IRQn); errorProvider.clear(); // initialise the peripheral initialisePeripheral(); // configure peripheral SD_Init(); }
u8 bsp_FSInit(void) { u8 res=0; SD_Init(); res=f_mount(&fatfs_SDCARD,"0:/",1 ); if(res) return 1; res=f_open(&file_sdif, "0:/Akey.bin",FA_OPEN_EXISTING|FA_WRITE|FA_READ); if(res) return 2; f_close(&file_sdif); return 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 file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Initialize Leds mounted on STM320518-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* Initializes the SD/SPI communication */ Status = SD_Init(); /* If SD is responding */ if (Status == SD_RESPONSE_NO_ERROR) { /* Fill the buffer to send */ Fill_Buffer(Buffer_Block_Tx, BUFFERSIZE, 0x0); /* Write block of 512 bytes on address 0 */ Status = SD_WriteBlock(Buffer_Block_Tx, 0, BUFFERSIZE); /* Read block of 512 bytes from address 0 */ Status = SD_ReadBlock(Buffer_Block_Rx, 0, BUFFERSIZE); /* Check the corectness of written dada */ TransferStatus = Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, BUFFERSIZE); if (TransferStatus == PASSED) { /* OK: Turn on LD1 */ STM_EVAL_LEDOn(LED1); } else { /* Error: Turn on LD2 */ STM_EVAL_LEDOn(LED2); } } else { /* Error: Turn on LD2 */ STM_EVAL_LEDOn(LED2); } while (1) { } }
/** * @brief Initialize the middleware libraries and stacks * @param None * @retval None */ void MOD_LibInit(void) { NVIC_InitTypeDef NVIC_InitStructure; MOD_GetParam(GLOBAL_SETTINGS_MEM , &Global_Config.d32); /* Force settings change to apply them */ Global_Config.b.Configuration_Changed = 1; /* Starting USB Init. Process */ GL_State_Message((uint8_t *)"USB Host Starting. "); /*Init USB Host */ USBH_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USB_Host, &USBH_MSC_cb, &USBH_USR_cb); GL_State_Message((uint8_t *)"USB Host Started."); GL_State_Message((uint8_t *)"RTC and backup Starting. "); /* Init RTC and Backup */ if ( RTC_Configuration() == 0) { GL_State_Message((uint8_t *)"RTC and backup Started."); CONSOLE_LOG((uint8_t *)"[SYSTEM] RTC and backup Started."); } else { GL_State_Message((uint8_t *)"ERR : RTC could not be started."); CONSOLE_LOG((uint8_t *)"[ERR] RTC start-up FAILED ."); } 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); SD_Init(); if ( f_mount( 1, &MSD_fatfs ) != FR_OK ) { /* fatfs initialisation fails*/ CONSOLE_LOG((uint8_t *)"[FS] Cannot initialize FS on drive 1."); } else { CONSOLE_LOG((uint8_t *)"[FS] FS on drive 1 initialized."); } }
/*{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*} * Name: SH_Mngr * Desc: Run Soil simulation. Will run the Duff or the Exp simulation * code, based on presence of Duff. * Note Duff Sim: * The Fuel has to be run before coming here, because the Fuel * calculates the Post Duff Depth which DUff Sim needs to run. * Note Exp Heat: * The Fuel has to be run before coming here, which should * have detected the no Duff Depth/Load and run burnup which calculates * the heat and time need by Exp Heat. * Note-1: There use to be some Error_Window() type logic errors in the * soil code, it would have been hard and not worth it to do them * thru the functions so I did a global string. * In: a_SI...... * * Ret: 1 Ok, 0 Error {*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{*}{**/ int WINAPI SH_Mngr (d_SI *a_SI, d_SO *a_SO, char cr_TmpFN[], char cr_ErrMes[]) { d_SD s_SD; d_SE s_SE; char cr[40]; strcpy (gcr_SoiErr,""); SO_Init (a_SO); /* Init the output struct */ if ( !xstrcmpi(a_SI->cr_BrnIg,"NO")) { /* Burnup ran & didn't ignite */ SHA_Init_0 (); /* so 0 out this arrary so that */ return 1; } /* 0s come out in the report */ SHA_Init (); /* Init the Soil Heat Temp Array*/ if ( a_SI->f_DufDepPre > 0 ) /* Prefire Duff depth determines*/ goto DuffSim; /* if we run Duff or Exp simulat*/ /*.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/ /* Do the Exp Heat, because there is no duff depth */ strcpy (a_SO->cr_Model,e_SM_ZDuff); /* tells what soil model */ if ( !SE_Init (a_SI, &s_SE, cr_ErrMes)) /* Ready the SE input struct */ return 0; if ( !SE_Mngr (&s_SE,cr_TmpFN,cr_ErrMes)) /* Run it, makes Pt arrar& File */ return 0; goto Load; /*.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*/ /* Do the Duff Simulation Modes */ DuffSim: strcpy (a_SO->cr_Model,e_SM_Duff); if ( !SD_ChkSoiDuf(a_SI->f_DufDepPre, a_SI->f_DufDepPos, cr_ErrMes) ) return 0; if ( !SD_Init (&s_SD, a_SI, cr_ErrMes)) return 0; /* Duff Sim is done when there is a Duff Depth to use....................... */ if ( !SD_Mngr(&s_SD,cr_TmpFN,cr_ErrMes)) /* Run Soil Duff Simulation */ return 0; Load: SO_Load (a_SI, a_SO); /* Get Soil Outputs */ if ( strcmp (gcr_SoiErr,"") ) { /* See Note-1 above */ strcpy (cr_ErrMes,gcr_SoiErr); return 0; } return 1; }
/******************************************************************************* * Function Name : MAL_GetStatus * Description : Get status * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_GetStatus (uint8_t lun) { // NAND_IDTypeDef NAND_ID; uint32_t DeviceSizeMul = 0, NumberOfBlocks = 0; if (lun == 0) { if (SD_Init() == SD_OK) { SD_GetCardInfo(&SDCardInfo); SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); DeviceSizeMul = (SDCardInfo.SD_csd.DeviceSizeMul + 2); if(SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD) { Mass_Block_Count[0] = (SDCardInfo.SD_csd.DeviceSize + 1) * 1024; } else { NumberOfBlocks = ((1 << (SDCardInfo.SD_csd.RdBlockLen)) / 512); Mass_Block_Count[0] = ((SDCardInfo.SD_csd.DeviceSize + 1) * (1 << DeviceSizeMul) << (NumberOfBlocks/2)); } Mass_Block_Size[0] = 512; Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); if ( Status != SD_OK ) { return MAL_FAIL; } Mass_Memory_Size[0] = Mass_Block_Count[0] * Mass_Block_Size[0]; return MAL_OK; } } // else // { // FSMC_NAND_ReadID(&NAND_ID); // if (NAND_ID.Device_ID != 0 ) // { // /* only one zone is used */ // Mass_Block_Count[1] = NAND_ZONE_SIZE * NAND_BLOCK_SIZE * NAND_MAX_ZONE ; // Mass_Block_Size[1] = NAND_PAGE_SIZE; // Mass_Memory_Size[1] = (Mass_Block_Count[1] * Mass_Block_Size[1]); // return MAL_OK; // } // } return MAL_FAIL; }
// Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); // Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); // if ( Status != SD_OK ) // return MAL_FAIL; // Status = SD_SetDeviceMode(SD_DMA_MODE); // if ( Status != SD_OK ) // return MAL_FAIL; // Mass_Memory_Size[0] = Mass_Block_Count[0] * Mass_Block_Size[0]; // LED1 = 0; // if (dis_mem == 0) //显示TF卡的容量 由于是周期性更新状态,所以,加了条件,只显示一次容量值 // { // printf("\r\n Micro SD卡的容量是 %d MBytes\n" ,SDCardInfo.CardCapacity); // dis_mem = 1; // } // return MAL_OK; // } // } // LED1 = 0; // return MAL_FAIL; //} u16 MAL_GetStatus (u8 lun) { uint32_t DeviceSizeMul = 0, NumberOfBlocks = 0; switch (lun) { case 0: if (dis_mem == 0) //显示TF卡的容量 由于是周期性更新状态,所以,加了条件,只显示一次容量值 { if (SD_Init() == SD_OK) { SD_GetCardInfo(&SDCardInfo); SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); DeviceSizeMul = (SDCardInfo.SD_csd.DeviceSizeMul + 2); if (SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD) { Mass_Block_Count[0] = (SDCardInfo.SD_csd.DeviceSize + 1) * 1024; } else { NumberOfBlocks = ((1 << (SDCardInfo.SD_csd.RdBlockLen)) / 512); Mass_Block_Count[0] = ((SDCardInfo.SD_csd.DeviceSize + 1) * (1 << DeviceSizeMul) << (NumberOfBlocks / 2)); } Mass_Block_Size[0] = 512; Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); if ( Status != SD_OK ) return MAL_FAIL; Status = SD_SetDeviceMode(SD_DMA_MODE); if ( Status != SD_OK ) return MAL_FAIL; Mass_Memory_Size[0] = Mass_Block_Count[0] * Mass_Block_Size[0]; LED1 = 0; // if (dis_mem == 0) //显示TF卡的容量 由于是周期性更新状态,所以,加了条件,只显示一次容量值 // { printf("\r\n Micro SD卡的容量是 %lld MBytes\n" , SDCardInfo.CardCapacity >> 20); dis_mem = 1; // } return MAL_OK; } dis_mem = 1; } return MAL_OK; case 1: return MAL_OK; case 2: return MAL_FAIL; default: return MAL_FAIL; }
void SDIO_test(void) { SD_Error error; // interrupt config SD_NVIC_Configuration(); //SD init error = SD_Init(); printf("test SDIO without FS\n\r"); if(error == SD_OK) printf("SD_Init Success.\n\r"); else{ printf("SD_Init fail.\n\r"); printf("status:\t%d\n\r",error); } printf("CardType:\t%d\n\r",SDCardInfo.CardType); printf("CardCapacity:\t%d\n\r",SDCardInfo.CardCapacity); printf("CardBlockSize:\t%d\n\r",SDCardInfo.CardBlockSize); printf("ManufactureID:\t%d\n\r",SDCardInfo.SD_cid.ManufacturerID); printf("RCA:\t%d\n\r",SDCardInfo.RCA); while((error == SD_OK) && (uwSDCardOperation != SD_OPERATION_END)) { 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 single block test--------------------- */ case(SD_OPERATION_MULTI_BLOCK): { SD_MultiBlockTest(); uwSDCardOperation = SD_OPERATION_END; break; } } } }
/******************************************************************************* * Function Name : MAL_Init * Description : Initializes the Media on the STM32 * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: Status = SD_Init(); break; default: return MAL_FAIL; } return status; }
/******************************************************************************* * Function Name : MAL_GetStatus * Description : Get status * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_GetStatus (uint8_t lun) { ; uint32_t DeviceSizeMul = 0, NumberOfBlocks = 0; if (lun == 0) { if (SD_Init() == SD_OK) { SD_GetCardInfo(&SDCardInfo); SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); DeviceSizeMul = (SDCardInfo.SD_csd.DeviceSizeMul + 2); if(SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD) { Mass_Block_Count[0] = (SDCardInfo.SD_csd.DeviceSize + 1) * 1024; } else { NumberOfBlocks = ((1 << (SDCardInfo.SD_csd.RdBlockLen)) / 512); Mass_Block_Count[0] = ((SDCardInfo.SD_csd.DeviceSize + 1) * (1 << DeviceSizeMul) << (NumberOfBlocks/2)); } Mass_Block_Size[0] = 512; Mass_Memory_Size[0] = Mass_Block_Count[0] * Mass_Block_Size[0]; GPIO_SetBits(USB_LED_PORT, GPIO_Pin_7); Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); if ( Status != SD_OK ) { return MAL_FAIL; } Status = SD_SetDeviceMode(SD_DMA_MODE); if ( Status != SD_OK ) { return MAL_FAIL; } return MAL_OK; } } else { return MAL_OK; } GPIO_ResetBits(USB_LED_PORT, GPIO_Pin_7); return MAL_FAIL; }
/*-----------------------------------------------------------------------*/ 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; }
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 }
/** * @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); } }
/** * @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); } }
/* 配置系统的顺序 CPU 内部、底层硬件 外部接口 外部硬件(按键、显示) 读取外部配置数据 传感器系统(RTC 时钟) 操作系统 任务 驻留任务(如:传感器读取、恒温箱温控、掉电时间记录) 采样任务 监控任务 */ __task int32_t main( void ) { BIOS_Init(); beep(); RTOS_Init(); // 尽早执行 ConfigureLoad(); // 先确定仪器型号 CalibrateLoad(); // 读传感器前执行, 远程存储器中的参数,应等通讯初始化后再读。 SampleSetLoad(); // 恢复采样前执行 Display_Init(); DisplaySetGrayVolt( Configure.DisplayGray * 0.022f ); DisplaySetLight( Configure.DisplayLight ); DisplaySetTimeout( Configure.TimeoutLight ); Keyboard_Init(); // 配置完背光超时时间后再初始化 RTC_Init(); // 为避免启动过程中时钟失败造成的假死现象,放在显示初始化之后 SD_Init(); // SD卡读写初始化,放在开关机存取之前 PowerLog_Init(); // 开关机存取,时间初始化之后 SENSOR_Local_Init(); delay( 1000u ); //配合下位机初始化 <注意!要进行下位机测试来确定参数!>300 Animation(); // 开机动画 delay( 1600u ); ShowEdition(); // 确定型号之后,显示初始化之后 delay( 1400u ); SENSOR_Remote_Init(); // modbus通信初始化 delay( 100u ); HCBox_Init(); delay( 100u ); Sampler_BootResume(); // 时间配置完成之后,设置参数读入之后。 delay( 100u ); SamplerTypeSelect(); delay( 100u ); for(;;) { menu_Main(); // 转主菜单 } }
static int check_sdcard(void) { unsigned int DeviceSizeMul = 0, NumberOfBlocks = 0; SD_Error Status; if (SD_Init() == SD_OK) { SD_GetCardInfo(&SDIO_Info); SD_SelectDeselect((unsigned int) (SDIO_Info.RCA << 16)); DeviceSizeMul = (SDIO_Info.SD_csd.DeviceSizeMul + 2); if(SDIO_Info.CardType == SDIO_HIGH_CAPACITY_SD_CARD) { SDIO_Block_Count = (SDIO_Info.SD_csd.DeviceSize + 1) * 1024; SDIO_Block_Size = 1; } else { NumberOfBlocks = ((1 << (SDIO_Info.SD_csd.RdBlockLen)) / 512); SDIO_Block_Count = ((SDIO_Info.SD_csd.DeviceSize + 1) * (1 << DeviceSizeMul) << (NumberOfBlocks/2)); SDIO_Block_Size = 512; } Status = SD_SelectDeselect((unsigned int) (SDIO_Info.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); if ( Status != SD_OK ) { return -1; } Status = SD_SetDeviceMode(SD_DMA_MODE); if ( Status != SD_OK ) { return -1; } SDIO_Memory_Size = SDIO_Block_Count * SDIO_Block_Size; if( SDIO_Memory_Size >= (2*1024 * 1024 * 1024)) // * 512)) { return 0; // 卡大于2G } else return -1; } return -1; }
DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber (0..) */ ) { DSTATUS stat; int result; switch (pdrv) { case SD_CARD : result = SD_Init(); if (result == SD_OK)stat = RES_OK; // translate the reslut code here return stat; } return STA_NOINIT; }
void reload() { UINT8 file; volatile UINT8 u8Error; if ((u8Error = SD_Init()) != INIT_FAILS) { FAT_Read_Master_Block(); loadFiles(); SD_LOADED_BEEP(); } else { for (file=0; file<FILES_IN_LIST; file++) { emptyButton(file); } NO_SD_BEEP(); } redraw(); }
/**************************************************************************** * 名 称:void SD_TEST(void) * 功 能:SD卡测试函数 * 入口参数:无 * 出口参数:无 * 说 明: * 调用方法:无 ****************************************************************************/ void SD_TEST(void){ Status = SD_Init(); Status = SD_GetCardInfo(&SDCardInfo); Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); Status = SD_SetDeviceMode(SD_DMA_MODE); if (Status == SD_OK) { // 从地址0开始读取512字节 Status = SD_ReadBlock(Buffer_Block_Rx, 0x00, 512); } if (Status == SD_OK) { // 返回成功的话,串口输出SD卡测试成功信息 USART_OUT(USART1,"\r\nSD SDIO-4bit模式 测试TF卡成功! \n "); } }
DSTATUS disk_initialize ( BYTE pdrv /* Physical drive nmuber (0..) */ ) { /*DSTATUS stat; int result; switch (pdrv) { case ATA : result = ATA_disk_initialize(); // translate the reslut code here return stat; case MMC : result = MMC_disk_initialize(); // translate the reslut code here return stat; case USB : result = USB_disk_initialize(); // translate the reslut code here return stat; } return STA_NOINIT;*/ DSTATUS stat = RES_ERROR; if (pdrv == MMC) { int result = SD_Init(); // translate the reslut code here if (result == SD_OK) { stat = RES_OK; } } return stat; }
int8_t STORAGE_Init (uint8_t lun) { #ifndef USE_STM3210C_EVAL NVIC_InitTypeDef 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); #endif if( SD_Init() != 0) { return (-1); } return (0); }
int main(void) { SD_InitTypeDef SD_InitStruct1; SystemClockSetup(ClockSource_EX50M,CoreClock_100M); DelayInit(); LED_Init(LED_PinLookup_CHK60EVB, kNumOfLED); UART_DebugPortInit(UART4_RX_C14_TX_C15, 115200); DisplayCPUInfo(); UART_printf("Please Insert Card\r\n"); SD_InitStruct1.SD_BaudRate = 2000000; //等待SD卡初始化成功 while(SD_Init(&SD_InitStruct1) != ESDHC_OK); UART_printf("SD Size:%dMB\r\n", SD_InitStruct1.SD_Size); while(1) { } }