Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Examples): Update examples with CLI to use new CLI library #770

Merged
merged 14 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 146 additions & 19 deletions Examples/MAX32650/SDHC_FAT/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
## Description

This example demonstrates formatting and modifying the filesystem on an SD card.

Use the a terminal window to select the operation(s) to perform on the SD card.

This example demonstrates the SDHC FAT Filesystem. The terminal prompts with a list of user-selectable tasks to run on the inserted Micro SD Card.

## Software

Expand All @@ -24,23 +21,153 @@ Universal instructions on building, flashing, and debugging this project can be
## Expected Output

```
***** 32650 SDHC FAT Filesystem Example *****
***** MAX32650 SDHC FAT Filesystem Example *****
Card inserted.
Card Initialized.
Card type: SDHC
SD clock ratio (at card) 4:1

Choose one of the following options:
0. Find the Size of the SD Card and Free Space
1. Format the Card
2. Manually Mount Card
3. List Contents of Current Directory
4. Create a Directory
5. Move into a Directory (cd)
6. Create a File of Random Data
7. Add Random Data to an Existing File
8. Delete a File
9. Format Card and Run Exmaple of FatFS Operations
10. Unmount Card and Quit
SDHC Ready!
CLI Initialized! Enter 'help' to see a list of available commands.

$ help
help

size:
Usage: size
Description: Find the Size of the SD Card and Free Space


format:
Usage: format
Description: Format the Card


mount:
Usage: mount
Description: Manually Mount Card


ls:
Usage: ls
Description: list the contents of the current directory


mkdir:
Usage: mkdir <directory name>
Description: Create a directory


file_create:
Usage: file_create <file name> <number of bytes to add>
Description: Create a file of random data


cd:
Usage: cd <directory name>
Description: Move into a directory


add_data:
Usage: add_data <file name> <number of bytes to add>
Description: Add random Data to an Existing File


del:
Usage: del <file name>
Description: Delete a file


fatfs:
Usage: fatfs
Description: Format Card and Run Example of FatFS Operations


unmount:
Usage: unmount
Description: Unmount card


$ format
format


*****THE DRIVE WILL BE FORMATTED IN 5 SECONDS*****
**************PRESS ANY KEY TO ABORT**************

FORMATTING DRIVE
Drive formatted.
SD card mounted.
SD card unmounted.

$ size
size
SD card mounted.
Disk Size: 31162880 bytes
Available: 31162848 bytes

$ mount
mount
SD card mounted.

$ mkdir Analog_devices
mkdir Analog_devices
Creating directory...
Directory Analog_devices created.

$ cd Analog_Devices
cd Analog_Devices
Changed to Analog_Devices

$ file_create ADI 30
file_create ADI 30
Creating file ADI with length 30
File opened!
30 bytes written to file!
File Closed!

$ add_data ADI 30
add_data ADI 30
File opened!
30 bytes written to file
File closed.

$ ls
ls
Listing Contents of /Analog_devices -
/Analog_devices/ADI

Finished listing contents

$ del ADI
del ADI
Deleted file ADI

$ fatfs
fatfs


*****THE DRIVE WILL BE FORMATTED IN 5 SECONDS*****
**************PRESS ANY KEY TO ABORT**************

FORMATTING DRIVE
Drive formatted.
SD card mounted.
SD card unmounted.
SD card mounted.
SD Card Opened!
File opened!
256 bytes written to file!
File Closed!
Creating Directory...
Renaming File...
Attempting to read back file...
Read Back 256 bytes
Message: dwfl-owoXGcTZ,5z,Sy8lfsNqDGrzio'O6vntRMoWODcIKP!C'y7tF.'W88ZjR81BpiibPhokQfa3w'cvmnr0EgE1MNDIhXKfBJGP6b?0tvHEPK-WNc7yuPdFNL6FPq10',Q,GSf3jSyY?MU0wv'FToTI!ct.E6Q4nbVuavg6h'48D5sR5mcepxf1l!MesddI7aZ9s?KIVnybRwZ.UBJpX1b?5oXP9wLKZcgW-k,gZ5HMIMwAcy!n9S?E57m0zvI
File Closed!

$ unmount
unmount
SD card unmounted.

$
```

65 changes: 65 additions & 0 deletions Examples/MAX32650/SDHC_FAT/include/sdhc_example.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/******************************************************************************
* Copyright (C) 2023 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
******************************************************************************/

#ifndef EXAMPLES_MAX32650_SDHC_FAT_INCLUDE_SDHC_EXAMPLE_H_
#define EXAMPLES_MAX32650_SDHC_FAT_INCLUDE_SDHC_EXAMPLE_H_

int sdhc_init(void);

void generateMessage(unsigned length);

int mount();

int umount();

int formatSDHC();

int getSize();

int ls();

int createFile(char *file_name, unsigned int length);

int appendFile(char *file_name, unsigned int length);

int mkdir(char *dir_name);

int cd(char *dir_name);

int deleteFile(char *file_name);

int example();

void waitCardInserted();

#endif // EXAMPLES_MAX32650_SDHC_FAT_INCLUDE_SDHC_EXAMPLE_H_
68 changes: 68 additions & 0 deletions Examples/MAX32650/SDHC_FAT/include/user-cli.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/******************************************************************************
* Copyright (C) 2023 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
******************************************************************************/

#ifndef EXAMPLES_MAX32650_SDHC_FAT_INCLUDE_USER_CLI_H_
#define EXAMPLES_MAX32650_SDHC_FAT_INCLUDE_USER_CLI_H_

/* -------------------------------------------------- */
// GLOBAL VARIABLE
/* -------------------------------------------------- */
extern const command_t user_commands[];
extern const unsigned int num_user_commands;

/* -------------------------------------------------- */
// FUNCTION PROTOTYPES
/* -------------------------------------------------- */
int handle_size(int argc, char *argv[]);

int handle_format(int argc, char *argv[]);

int handle_mount(int argc, char *argv[]);

int handle_ls(int argc, char *argv[]);

int handle_mkdir(int argc, char *argv[]);

int handle_createfile(int argc, char *argv[]);

int handle_cd(int argc, char *argv[]);

int handle_add_data(int argc, char *argv[]);

int handle_del(int argc, char *argv[]);

int handle_fatfs(int argc, char *argv[]);

int handle_unmount(int argc, char *argv[]);

#endif // EXAMPLES_MAX32650_SDHC_FAT_INCLUDE_USER_CLI_H_
Loading
Loading