Keil™, An ARM® Company

RL-ARM User's Guide

Technical Support

On-Line Manuals

RL-ARM User's Guide

RL-RTX RL-FlashFS RL-TCPnet RL-CAN Example Programs Library Reference Data Types BIT BOOL CAN_ERROR CAN_msg FILE S8 S16 S32 S64 U8 U16 U32 U64 Include Files can_cfg.h file_config.h net_config.h rtl.h rtx_can.h rtx_config.h stdio.h Reference _alloc_box _calloc_box _declare_box _declare_box8 _free_box _init_box _init_box8 arp_cache_ip CAN_init CAN_receive CAN_request CAN_rx_object CAN_send CAN_set CAN_start CAN_tx_object cgi_func cgi_process_data cgi_process_var cgx_content_type com_getchar com_putchar com_tx_active dhcp_disable fanalyse fcheck fclose fdefrag fdelete feof ferror ffind fflush fformat ffree fgetc fgets finit fopen fprintf fputc fputs fread frename fs_EraseSector fs_get_date fs_get_time fs_Init fs_ProgramPage fs_spi_EraseSector fs_spi_Init fs_spi_ProgramPage fs_spi_ReadData fscanf fseek ftell ftp_fclose ftp_fdelete ftp_ffind ftp_fopen ftp_fread ftp_frename ftp_fwrite fwrite get_host_by_name http_accept_host http_date http_fclose http_fgets http_finfo http_fopen http_fread http_get_content_type http_get_info http_get_lang http_get_session http_get_var igmp_join igmp_leave init_ethernet init_modem init_serial init_TcpNet int_disable_eth int_enable_eth interrupt_ethernet isr_evt_set isr_mbx_check isr_mbx_receive isr_mbx_send isr_sem_send main_TcpNet mci_init mci_read_config mci_read_sect mci_write_sect modem_dial modem_hangup modem_listen modem_online modem_process modem_run os_dly_wait os_evt_clr os_evt_get os_evt_set os_evt_wait_and os_evt_wait_or os_itv_set os_itv_wait os_mbx_check os_mbx_declare os_mbx_init os_mbx_send os_mbx_wait os_mut_init os_mut_release os_mut_wait os_sem_init os_sem_send os_sem_wait os_sys_init os_sys_init_prio os_sys_init_user os_tmr_call os_tmr_create os_tmr_kill os_tsk_create os_tsk_create_ex os_tsk_create_user os_tsk_create_user_ex os_tsk_delete os_tsk_delete_self os_tsk_pass os_tsk_prio os_tsk_prio_self os_tsk_self poll_ethernet ppp_close ppp_connect ppp_is_up ppp_listen rewind send_frame slip_close slip_connect slip_is_up slip_listen smtp_accept_auth smtp_cbfunc smtp_connect snmp_trap spi_hi_speed spi_init spi_send spi_ss tcp_abort tcp_check_send tcp_close tcp_connect tcp_get_buf tcp_get_socket tcp_get_state tcp_listen tcp_max_dsize tcp_release_socket tcp_reset_window tcp_send tftp_fclose tftp_fopen tftp_fread tftp_fwrite timer_tick tnet_cbfunc tnet_ccmp tnet_get_info tnet_msg_poll tnet_process_cmd tnet_set_delay tsk_lock tsk_unlock udp_close udp_get_buf udp_get_socket udp_mcast_ttl udp_open udp_release_socket udp_send ungetc Library Files Appendix

fformat

Summary
#include <rtl.h>

int fformat (
    const char *drive);    /* drive to format */
Description

The fformat function formats the Flash File System storage media on the specified drive. If the drive string is empty (""), fformat uses the default drive specified in the FILE_CONFIG.C configuration file.

The following values are supported for the drive:

DriveDescription
"F:"Embedded Flash drive.
"S:"SPI Flash drive.
"R:"Ram drive.
"M:"Memory Card drive.

All Flash File System drives must be formatted before any files are created on the devices.

  • Flash devices must be formatted once when the system is started the first time. They are erased sector by sector as specified in the FS_FLASHDEV.C configuration file.
  • RAM devices must be formatted every time when the system starts. They are cleared sector by sector to an erased value (0x00 by default).
  • Non-volatile and zero-power RAM devices must be formatted once when the system is started the first time. Since these devices are battery backed up and do not lose their contents when power is removed. They do not require reformatting each time the system starts. Non-volatile and zero-power RAM devices are cleared sector by sector to an erased value (0x00 by default).
  • The Memory Card must be formatted before its first use. If a Memory Card has been formatted once, there is no need to format it again. The function formats the Memory Card optimized for 12-bit or 16-bit FAT type. Cluster size and Cluster 2 alignment are optimized for the best Card performance. The Flash File System supports SD and MMC Flash Memory Cards with a maximum capacity of 4 GBytes.

The fformat function is in the RL-FlashFS library. The prototype is defined in rtl.h.

Note

  • The fformat function erases all files written to the drive.
  • The fformat function closes all opened files on the drive. All existing file handles become invalid. Reading or writing to such files after formatting the drive may produce unpredictable results or file corruption.
  • When formatting a Memory Card, you can specify a drive label in the argument drive using the format "M:Drive_Label". The label is written to the drive after the formatting completes. The drive label must have a maximum length of 11 characters and cannot include spaces or special characters.
  • The fformat function for Memory Card can accept additional paramters in the argument string:
    • /FAT32 - tells the format function to format the Memory Card using 32-bit FAT file system.
    • /WIPE - tells the format function to clear all the saved data on the Memory Card. All sectors on the Memory Card are overwritten with the default value of 0xFF. Note that this command might take long time to execute on high capacity memory cards.
    The following example will format the Memory Card with 12-bit or 16-bit FAT file system and clear all the data:

    fformat ("M:SD_CARD /WIPE");
    
Return Value

The fformat function returns a value of 0 when formatting is successful. A non-zero return value indicates an error was encountered.

See Also

fcheck, fdelete

Example
#include <rtl.h>

void tst_fformat (void) {

  /* Format a Flash Drive. */
  if (fformat ("F:") != 0) {
    printf ("Flash File System format failed.\n");
  }
  else {
    printf ("Flash File System initialized.\n");
  }

  /* Format an SD Memory Card with Volume Label. */
  if (fformat ("M:SD_CARD") != 0) {
    printf ("SD Memory Card format failed.\n");
  }
  else {
    printf ("SD Memory Card formatted.\n");
  }
}