Skip to content

Commit

Permalink
feat(Examples): Add CLI Library to MSDK (#679)
Browse files Browse the repository at this point in the history
Co-authored-by: Suraj-Ajjampur <[email protected]>
Co-authored-by: Suraj-Ajjampur <[email protected]>
Co-authored-by: Scheiffler <[email protected]>
Co-authored-by: Jacob Scheiffler <[email protected]>
Co-authored-by: Jake Carter <[email protected]>
  • Loading branch information
6 people authored Sep 21, 2023
1 parent fb6d137 commit 7cc3386
Show file tree
Hide file tree
Showing 17 changed files with 1,627 additions and 607 deletions.
3 changes: 3 additions & 0 deletions Documentation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class CommonExampleInfo(ExampleInfo):
print(f.name)
if (f.name != "README.md"): shutil.copy(f, here) # Workaround for https://github.com/mkdocs/mkdocs/issues/3313

(here / "Libraries" / "CLI").mkdir(exist_ok=True)
shutil.copy(Path("Libraries") / "CLI" / "README.md", here / "Libraries" / "CLI" / "README.md") # TODO: Less hard-coded way of pulling these in

# String replace "##__EXAMPLES_LIST__##" with autogenerated tables
# Note: We use the copy for the site build in the Documentation folder so that the
# tracked "source" doc in the root of the repo is unmodified.
Expand Down
5 changes: 3 additions & 2 deletions Examples/MAX78000/SDHC_FTHR/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/PeriphDrivers/Include/${TARGET}/&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/Boards/${TARGET}/Include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/Boards/${TARGET}/${BOARD}/Include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/SDHC/Include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/SDHC/ff14/Source&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/SDHC/Include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/SDHC/ff14/Source&quot;"/>
<listOptionValue builtIn="false" value="&quot;${MAXIM_PATH}/Libraries/CLI/inc&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="gnu.c.compiler.option.preprocessor.def.symbols.1784350960" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.154347489" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
Expand Down
6 changes: 4 additions & 2 deletions Examples/MAX78000/SDHC_FTHR/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/SDHC/Include",
"${config:MAXIM_PATH}/Libraries/SDHC/ff14/Source"
"${config:MAXIM_PATH}/Libraries/SDHC/ff13/Source",
"${config:MAXIM_PATH}/Libraries/CLI/inc"
],
"C_Cpp.default.browse.path": [
"${workspaceFolder}",
Expand All @@ -68,7 +69,8 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/MiscDrivers",
"${config:MAXIM_PATH}/Libraries/SDHC/ff14/Source"
"${config:MAXIM_PATH}/Libraries/SDHC/ff13/Source",
"${config:MAXIM_PATH}/Libraries/CLI/src"
],
"C_Cpp.default.defines": [

Expand Down
149 changes: 148 additions & 1 deletion Examples/MAX78000/SDHC_FTHR/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Description

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

### Project Usage
Expand All @@ -8,4 +10,149 @@ Universal instructions on building, flashing, and debugging this project can be

### Project-Specific Build Notes

* This project comes pre-configured for the MAX78000EVKIT. See [Board Support Packages](https://analog-devices-msdk.github.io/msdk/USERGUIDE/#board-support-packages) in the UG for instructions on changing the target board.
* This project comes pre-configured for the MAX78000FTHR. See [Board Support Packages](https://analog-devices-msdk.github.io/msdk/USERGUIDE/#board-support-packages) in the UG for instructions on changing the target board.

## Required Connections

- Connect a USB cable between the PC and the CN1 (USB/PWR) connector.
- Open a terminal application on the PC and connect to the EV kit's console UART at 115200, 8-N-1.
- Insert the SD card into the Micro SD Card Connector.

## Expected Output

```
***** MAX78000 SDHC FAT Filesystem Example *****
Card inserted.
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: 7760896 bytes
Available: 7760864 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 25
add_data ADI 25
File opened!
25 bytes written to file
File closed.
$ ls
ls
Listing Contents of 0:/Analog_Devices -
0:/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: sjVNXdwfl-owoXGcTZ,5z,Sy8lfsNqDGrzio'O6vntRMoWODcIKP!C'y7tF.'W88ZjR81BpiibPhokQfa3w'cvmnr0EgE1MNDIhXKfBJGP6b?0tvHEPK-WNc7yuPdFNL6FPq10',Q,GSf3jSyY?MU0wv'FToTI!ct.E6Q4nbVuavg6h'48D5sR5mcepxf1l!MesddI7aZ9s?KIVnybRwZ.UBJpX1b?5oXP9wLKZcgW-k,gZ5HMIMwAcy!n9S?E57Analog_Devices
File Closed!
$ unmount
unmount
SD card unmounted.
```

83 changes: 83 additions & 0 deletions Examples/MAX78000/SDHC_FTHR/include/sdhc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/******************************************************************************
* 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_MAX78000_SDHC_FTHR_INCLUDE_SDHC_H_
#define EXAMPLES_MAX78000_SDHC_FTHR_INCLUDE_SDHC_H_

/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "board.h"
#include "mxc_delay.h"
#include "mxc_device.h"
#include "gpio.h"
#include "uart.h"
#include "ff.h"

/***** Definitions *****/

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define MAXLEN 256

/***** FUNCTION PROTOTYPES *****/

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_MAX78000_SDHC_FTHR_INCLUDE_SDHC_H_
67 changes: 67 additions & 0 deletions Examples/MAX78000/SDHC_FTHR/include/user-cli.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/******************************************************************************
* 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_MAX78000_SDHC_FTHR_INCLUDE_USER_CLI_H_
#define EXAMPLES_MAX78000_SDHC_FTHR_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_MAX78000_SDHC_FTHR_INCLUDE_USER_CLI_H_
Loading

0 comments on commit 7cc3386

Please sign in to comment.