microsd 2.2.0
Loading...
Searching...
No Matches
microsd


microSD Click

microSD Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Aug 2023.
  • Type : SPI type

Software Support

Example Description

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

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.microSD

Example Key Functions

  • microsd_cfg_setup Config Object Initialization function.
    void microsd_cfg_setup(microsd_cfg_t *cfg)
    microSD configuration object setup function.
    microSD Click configuration object.
    Definition microsd.h:125
  • microsd_init Initialization function.
    err_t microsd_init ( microsd_t *ctx, microsd_cfg_t *cfg );
    err_t microsd_init(microsd_t *ctx, microsd_cfg_t *cfg)
    microSD initialization function.
    microSD Click context object.
    Definition microsd.h:111
  • microsd_check_card_detection This function checks and waits for a microSD card to be inserted to the Click board.
    void microsd_check_card_detection(microsd_t *ctx)
    microSD check card detection function.
    Definition main.c:326
  • microsd_create_directory This function creates a new directory at the selected absolute path. The path should contain a name of the directory to be created.
    void microsd_create_directory ( uint8_t *dir_path );
    void microsd_create_directory(uint8_t *dir_path)
    microSD create directory function.
    Definition main.c:381
  • microsd_display_directory This function reads and displays the content of the directory at the selected path.
    void microsd_display_directory ( uint8_t *dir_path );
    void microsd_display_directory(uint8_t *dir_path)
    microSD display directory function.
    Definition main.c:340

Application Init

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

void application_init ( void )
{
log_cfg_t log_cfg;
microsd_cfg_t microsd_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
microsd_cfg_setup( &microsd_cfg );
MICROSD_MAP_MIKROBUS( microsd_cfg, MIKROBUS_1 );
if ( MICROSD_ERROR == microsd_init( &microsd, &microsd_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
Delay_ms ( 1000 );
// Mount the initialized logical drive to the initialized physical drive and overall file system
#if FORMAT_CARD
// Format the logical drive previously mounted to file system with identifying ROOT drive number
#endif
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Create DIR1 directory
Delay_ms ( 500 );
// Create DIR2 directory
Delay_ms ( 500 );
// Create DIR4 directory
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Remove DIR4 directory
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Rename DIR2 to DIR3
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Create the FILE1
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
uint8_t rw_buffer[ BUFFER_SIZE ] = { 0 };
// Populate write buffer with bytes ranging from 0 to 255
for ( uint16_t cnt = 0; cnt < BUFFER_SIZE; cnt++ )
{
rw_buffer[ cnt ] = cnt & 0xFF;
}
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Create the FILE2
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Copy data from FILE1 to FILE2
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
// Create DIR5 directory
Delay_ms ( 500 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_info( &logger, " Application Task " );
}
#define MICROSD_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition microsd.h:96
void application_init(void)
Definition main.c:164
void microsd_mount_drive(microsd_t *ctx, uint8_t *path)
microSD mount drive function.
Definition main.c:499
#define PATH_DIR2
Definition main.c:37
#define PATH_FILE1
Definition main.c:41
void microsd_copy_file(uint8_t *src_file_path, uint8_t *dst_file_path)
microSD copy file function.
Definition main.c:451
void microsd_format_drive(uint8_t *path)
microSD format drive function.
Definition main.c:490
#define BUFFER_SIZE
Definition main.c:45
void microsd_remove_path(uint8_t *path)
microSD remove path function.
Definition main.c:390
#define PATH_DIR5
Definition main.c:40
#define PATH_ROOT
Definition main.c:35
void microsd_create_file(uint8_t *file_path)
microSD create file function.
Definition main.c:408
void microsd_write_to_file(uint8_t *file_path, uint8_t *data_in, uint32_t data_len)
microSD write to file function.
Definition main.c:425
#define PATH_DIR3
Definition main.c:38
#define PATH_DIR4
Definition main.c:39
#define PATH_DIR1
Definition main.c:36
void microsd_rename_path(uint8_t *old_path, uint8_t *new_path)
microSD rename path function.
Definition main.c:399
#define PATH_FILE2
Definition main.c:42
@ MICROSD_ERROR
Definition microsd.h:143

Application Task

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

void application_task ( void )
{
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
log_printf ( &logger, "\r\n\n" );
}
void application_task(void)
Definition main.c:289

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.