microsd 2.1.0.0
main.c File Reference

microSD Click example More...

#include "board.h"
#include "log.h"
#include "microsd.h"

Macros

#define FORMAT_CARD   0
 
#define PATH_ROOT   "3:/"
 
#define PATH_DIR1   PATH_ROOT "_DIR1_/"
 
#define PATH_DIR2   PATH_DIR1 "_DIR2_/"
 
#define PATH_DIR3   PATH_DIR1 "_DIR3_/"
 
#define PATH_DIR4   PATH_ROOT "_DIR4_/"
 
#define PATH_DIR5   PATH_DIR1 "_DIR5_/"
 
#define PATH_FILE1   PATH_ROOT "_FILE1_.TXT"
 
#define PATH_FILE2   PATH_DIR3 "_FILE2_.CSV"
 
#define BUFFER_SIZE   256
 

Functions

void microsd_check_card_detection (microsd_t *ctx)
 microSD check card detection function.
 
void microsd_display_directory (uint8_t *dir_path)
 microSD display directory function.
 
void microsd_create_directory (uint8_t *dir_path)
 microSD create directory function.
 
void microsd_remove_path (uint8_t *path)
 microSD remove path function.
 
void microsd_rename_path (uint8_t *old_path, uint8_t *new_path)
 microSD rename path function.
 
void microsd_create_file (uint8_t *file_path)
 microSD create file function.
 
void microsd_write_to_file (uint8_t *file_path, uint8_t *data_in, uint32_t data_len)
 microSD write to file function.
 
void microsd_copy_file (uint8_t *src_file_path, uint8_t *dst_file_path)
 microSD copy file function.
 
void microsd_format_drive (uint8_t *path)
 microSD format drive function.
 
void microsd_mount_drive (microsd_t *ctx, uint8_t *path)
 microSD mount drive function.
 
void microsd_unmount_drive (uint8_t *path)
 microSD unmount drive function.
 
void application_init (void)
 
void application_task (void)
 
int main (void)
 

Detailed Description

microSD Click example

Description

This example demonstrates a basic file system functionality and operations with files and directories using a microSD click board.

The demo application is composed of two sections :

Application Init

Initializes the driver and logger and performs a several operations with file system that demonstrates the basic usage of microSD click board.

Application Task

Reads and displays on the USB UART the contents of all directories created during application init.

Author
Stefan Filipovic

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   256

◆ FORMAT_CARD

#define FORMAT_CARD   0

◆ PATH_DIR1

#define PATH_DIR1   PATH_ROOT "_DIR1_/"

◆ PATH_DIR2

#define PATH_DIR2   PATH_DIR1 "_DIR2_/"

◆ PATH_DIR3

#define PATH_DIR3   PATH_DIR1 "_DIR3_/"

◆ PATH_DIR4

#define PATH_DIR4   PATH_ROOT "_DIR4_/"

◆ PATH_DIR5

#define PATH_DIR5   PATH_DIR1 "_DIR5_/"

◆ PATH_FILE1

#define PATH_FILE1   PATH_ROOT "_FILE1_.TXT"

◆ PATH_FILE2

#define PATH_FILE2   PATH_DIR3 "_FILE2_.CSV"

◆ PATH_ROOT

#define PATH_ROOT   "3:/"

Function Documentation

◆ application_init()

void application_init ( void )

< Logger config object.

< Click config object.

Logger initialization. Default baud rate: 115200 Default log level: LOG_LEVEL_DEBUG

Note
If USB_UART_RX and USB_UART_TX are defined as HAL_PIN_NC, you will need to define them manually for log to work. See LOG_MAP_USB_UART macro definition for detailed explanation.

◆ application_task()

void application_task ( void )

◆ main()

int main ( void )

◆ microsd_check_card_detection()

void microsd_check_card_detection ( microsd_t * ctx)

microSD check card detection function.

This function checks and waits for a microSD card to be inserted to the click board.

Parameters
[in]ctx: Click context object. See microsd_t object definition for detailed explanation.
Returns
None.
Note
None.

◆ microsd_copy_file()

void microsd_copy_file ( uint8_t * src_file_path,
uint8_t * dst_file_path )

microSD copy file function.

This function copies the content of a file from the selected absolute path specified by the src_file_path parameter, to the absolute path specified by the dst_file_path parameter.

Parameters
[in]src_file_path: The source file absolute path.
[in]dst_file_path: The destination file absolute path.
Returns
None.
Note
None.

◆ microsd_create_directory()

void microsd_create_directory ( uint8_t * dir_path)

microSD create directory function.

This function creates a new directory at the selected absolute path. The path should contain a name of the directory to be created.

Parameters
[in]dir_path: The absolute path to the directory to be created.
Returns
None.
Note
None.

◆ microsd_create_file()

void microsd_create_file ( uint8_t * file_path)

microSD create file function.

This function creates a new file at the selected absolute path. The path should contain a name of the file to be created.

Parameters
[in]file_path: The absolute path to the file to be created.
Returns
None.
Note
None.

◆ microsd_display_directory()

void microsd_display_directory ( uint8_t * dir_path)

microSD display directory function.

This function reads and displays the content of the directory at the selected path.

Parameters
[in]dir_path: The absolute path to the directory to be displayed.
Returns
None.
Note
None.

◆ microsd_format_drive()

void microsd_format_drive ( uint8_t * path)

microSD format drive function.

This function formats the logical drive previously mounted to file system with identifying drive number.

Parameters
[in]path: The ROOT path of drive to be formatted.
Returns
None.
Note
None.

◆ microsd_mount_drive()

void microsd_mount_drive ( microsd_t * ctx,
uint8_t * path )

microSD mount drive function.

This function mounts the initialized logical drive to the initialized physical drive and overall file system.

Parameters
[in]ctx: Click context object. See microsd_t object definition for detailed explanation.
[in]path: The ROOT path of drive to be mounted.
Returns
None.
Note
None.

◆ microsd_remove_path()

void microsd_remove_path ( uint8_t * path)

microSD remove path function.

This function removes a file or a directory from the selected absolute path.

Parameters
[in]path: The absolute path to the file or directory to be removed.
Returns
None.
Note
None.

◆ microsd_rename_path()

void microsd_rename_path ( uint8_t * old_path,
uint8_t * new_path )

microSD rename path function.

This function renames a file or a directory from the selected absolute path specified by the old_path parameter, to the absolute path specified by the new_path parameter.

Parameters
[in]old_path: The old path to the file or directory to be renamed.
[in]new_path: The new path to the file or directory.
Returns
None.
Note
None.

◆ microsd_unmount_drive()

void microsd_unmount_drive ( uint8_t * path)

microSD unmount drive function.

This function unmounts the mounted logical drive from the file system.

Parameters
[in]path: The ROOT path of drive to be unmounted.
Returns
None.
Note
None.

◆ microsd_write_to_file()

void microsd_write_to_file ( uint8_t * file_path,
uint8_t * data_in,
uint32_t data_len )

microSD write to file function.

This function writes a desired number of data bytes to the end of file at the selected absolute path.

Parameters
[in]file_path: The absolute path to the file.
[in]data_in: The data buffer to be written.
[in]data_len: Number of data bytes to be written.
Returns
None.
Note
None.