diff --git a/Examples/MAX78002/SDHC_FAT/.cproject b/Examples/MAX78002/SDHC_FAT/.cproject
index 78ee393285c..bea51aab45b 100644
--- a/Examples/MAX78002/SDHC_FAT/.cproject
+++ b/Examples/MAX78002/SDHC_FAT/.cproject
@@ -32,8 +32,10 @@
-
-
+
+
+
+
diff --git a/Examples/MAX78002/SDHC_FAT/.vscode/settings.json b/Examples/MAX78002/SDHC_FAT/.vscode/settings.json
index cbc720d9df8..b599fd0255e 100755
--- a/Examples/MAX78002/SDHC_FAT/.vscode/settings.json
+++ b/Examples/MAX78002/SDHC_FAT/.vscode/settings.json
@@ -53,10 +53,9 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PMIC",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
+ "${config:MAXIM_PATH}/Libraries/CLI/inc",
"${config:MAXIM_PATH}/Libraries/SDHC/Include",
- "${config:MAXIM_PATH}/Libraries/SDHC/ff13/Source",
- "${config:MAXIM_PATH}/Libraries/MiscDrivers/EEPROM",
- "${config:MAXIM_PATH}/Libraries/MiscDrivers/CODEC"
+ "${config:MAXIM_PATH}/Libraries/SDHC/ff15/Source"
],
"C_Cpp.default.browse.path": [
"${workspaceFolder}",
@@ -70,10 +69,8 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/MiscDrivers",
- "${config:MAXIM_PATH}/Libraries/SDHC/ff13/Source",
- "${config:MAXIM_PATH}/Libraries/MiscDrivers/ADC",
- "${config:MAXIM_PATH}/Libraries/MiscDrivers/EEPROM",
- "${config:MAXIM_PATH}/Libraries/MiscDrivers/CODEC"
+ "${config:MAXIM_PATH}/Libraries/CLI/src",
+ "${config:MAXIM_PATH}/Libraries/SDHC/ff15/Source"
],
"C_Cpp.default.defines": [
diff --git a/Examples/MAX78002/SDHC_FAT/include/app-sdhc.h b/Examples/MAX78002/SDHC_FAT/include/app-sdhc.h
new file mode 100644
index 00000000000..c2544408c45
--- /dev/null
+++ b/Examples/MAX78002/SDHC_FAT/include/app-sdhc.h
@@ -0,0 +1,70 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2023 Analog Devices, Inc. All Rights Reserved. This software
+ * is proprietary to Analog Devices, Inc. and its licensors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#ifndef EXAMPLES_MAX78002_SDHC_FAT_INCLUDE_APP_SDHC_H_
+#define EXAMPLES_MAX78002_SDHC_FAT_INCLUDE_APP_SDHC_H_
+
+/***** Includes *****/
+#include
+#include
+#include
+#include
+
+#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_MAX78002_SDHC_FAT_INCLUDE_APP_SDHC_H_
diff --git a/Examples/MAX78002/SDHC_FAT/include/user-cli.h b/Examples/MAX78002/SDHC_FAT/include/user-cli.h
new file mode 100644
index 00000000000..f49c42df30d
--- /dev/null
+++ b/Examples/MAX78002/SDHC_FAT/include/user-cli.h
@@ -0,0 +1,54 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2023 Analog Devices, Inc. All Rights Reserved. This software
+ * is proprietary to Analog Devices, Inc. and its licensors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#ifndef EXAMPLES_MAX78002_SDHC_FAT_INCLUDE_USER_CLI_H_
+#define EXAMPLES_MAX78002_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_MAX78002_SDHC_FAT_INCLUDE_USER_CLI_H_
diff --git a/Examples/MAX78002/SDHC_FAT/main.c b/Examples/MAX78002/SDHC_FAT/main.c
index 032ef6f9079..c52c11c4a99 100644
--- a/Examples/MAX78002/SDHC_FAT/main.c
+++ b/Examples/MAX78002/SDHC_FAT/main.c
@@ -54,489 +54,40 @@
* @brief read and write sdhc
* @details This example uses the sdhc and ffat to read/write the file system on
* an SD card. The Fat library used supports long filenames (see ffconf.h)
- * the max length is 256 characters.
+ * the max length is 256 characters. It uses the CLI library for taking user
+ * user commands.
*
* You must connect an sd card to the sd card slot.
*/
/***** Includes *****/
-#include
-#include
-#include
-#include
-#include "mxc_device.h"
-#include "mxc_sys.h"
-#include "mxc_delay.h"
-#include "mxc_errors.h"
-#include "sdhc_regs.h"
-#include "led.h"
-#include "tmr.h"
+#include "board.h"
+#include "cli.h"
+#include "nvic_table.h"
+#include "sdhc.h"
#include "uart.h"
-#include "gpio.h"
+#include "user-cli.h"
#include "sdhc_lib.h"
-#include "ff.h"
-
-/***** Definitions *****/
-
-#define STRINGIFY(x) #x
-#define TOSTRING(x) STRINGIFY(x)
-
-#define MAXLEN 256
+#include "gpio.h"
+#include "mxc_sys.h"
-/***** Globals *****/
-FATFS *fs; //FFat Filesystem Object
-FATFS fs_obj;
-FIL file; //FFat File Object
-FRESULT err; //FFat Result (Struct)
-FILINFO fno; //FFat File Information Object
-DIR dir; //FFat Directory Object
-TCHAR message[MAXLEN], directory[MAXLEN], cwd[MAXLEN], filename[MAXLEN], volume_label[24],
- volume = '0';
-TCHAR *FF_ERRORS[20];
-DWORD clusters_free = 0, sectors_free = 0, sectors_total = 0, volume_sn = 0;
-UINT bytes_written = 0, bytes_read = 0, mounted = 0;
-BYTE work[4096];
-static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!";
-#ifdef BOARD_EVKIT_V1
mxc_gpio_cfg_t SDPowerEnablePin = { MXC_GPIO1, MXC_GPIO_PIN_15, MXC_GPIO_FUNC_OUT,
MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO };
-#else
-#error No board definition found. Is board.h included?
-#endif
-/***** FUNCTIONS *****/
-
-void generateMessage(unsigned length)
-{
- for (int i = 0; i < length; i++) {
- /*Generate some random data to put in file*/
- message[i] = charset[rand() % (sizeof(charset) - 1)];
- }
-}
-
-int mount()
-{
- fs = &fs_obj;
- if ((err = f_mount(fs, "", 1)) != FR_OK) { //Mount the default drive to fs now
- printf("Error opening SD card: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- } else {
- printf("SD card mounted.\n");
- mounted = 1;
- }
-
- f_getcwd(cwd, sizeof(cwd)); //Set the Current working directory
-
- return err;
-}
-
-int umount()
-{
- if ((err = f_mount(NULL, "", 0)) != FR_OK) { //Unmount the default drive from its mount point
- printf("Error unmounting volume: %s\n", FF_ERRORS[err]);
- } else {
- printf("SD card unmounted.\n");
- mounted = 0;
- }
-
- return err;
-}
-
-int formatSDHC()
-{
- printf("\n\n*****THE DRIVE WILL BE FORMATTED IN 5 SECONDS*****\n");
- printf("**************PRESS ANY KEY TO ABORT**************\n\n");
- MXC_UART_ClearRXFIFO(MXC_UART0);
- MXC_TMR_Delay(MXC_TMR0, MXC_DELAY_MSEC(5000));
- if (MXC_UART_GetRXFIFOAvailable(MXC_UART0) > 0) {
- return E_ABORT;
- }
-
- printf("FORMATTING DRIVE\n");
-
- MKFS_PARM format_options = { .fmt = FM_ANY };
-
- if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
- FR_OK) { //Format the default drive to FAT32
- printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
- } else {
- printf("Drive formatted.\n");
- }
-
- mount();
-
- if ((err = f_setlabel("MAXIM")) != FR_OK) {
- printf("Error setting drive label: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- }
-
- umount();
-
- return err;
-}
-
-int getSize()
-{
- if (!mounted) {
- mount();
- }
-
- if ((err = f_getfree(&volume, &clusters_free, &fs)) != FR_OK) {
- printf("Error finding free size of card: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- }
-
- sectors_total = (fs->n_fatent - 2) * fs->csize;
- sectors_free = clusters_free * fs->csize;
-
- printf("Disk Size: %u bytes\n", sectors_total / 2);
- printf("Available: %u bytes\n", sectors_free / 2);
-
- return err;
-}
-
-int ls()
-{
- if (!mounted) {
- mount();
- }
-
- printf("Listing Contents of %s - \n", cwd);
-
- if ((err = f_opendir(&dir, cwd)) == FR_OK) {
- while (1) {
- err = f_readdir(&dir, &fno);
- if (err != FR_OK || fno.fname[0] == 0)
- break;
-
- printf("%s/%s", cwd, fno.fname);
-
- if (fno.fattrib & AM_DIR) {
- printf("/");
- }
-
- printf("\n");
- }
- f_closedir(&dir);
- } else {
- printf("Error opening directory!\n");
- return err;
- }
-
- printf("\nFinished listing contents\n");
-
- return err;
-}
-
-int createFile()
-{
- unsigned int length = 128;
-
- if (!mounted) {
- mount();
- }
-
- printf("Enter the name of the text file: \n");
- scanf("%255s", filename);
- printf("Enter the length of the file: (256 max)\n");
- scanf("%d", &length);
- printf("Creating file %s with length %d\n", filename, length);
-
- if ((err = f_open(&file, (const TCHAR *)filename, FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) {
- printf("Error opening file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("File opened!\n");
-
- generateMessage(length);
-
- if ((err = f_write(&file, &message, length, &bytes_written)) != FR_OK) {
- printf("Error writing file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("%d bytes written to file!\n", bytes_written);
-
- if ((err = f_close(&file)) != FR_OK) {
- printf("Error closing file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("File Closed!\n");
- return err;
-}
-
-int appendFile()
-{
- unsigned int length = 0;
-
- if (!mounted) {
- mount();
- }
-
- printf("Type name of file to append: \n");
- scanf("%255s", filename);
- printf("Type length of random data to append: \n");
- scanf("%d", &length);
-
- if ((err = f_stat((const TCHAR *)filename, &fno)) == FR_NO_FILE) {
- printf("File %s doesn't exist!\n", (const TCHAR *)filename);
- return err;
- }
- if ((err = f_open(&file, (const TCHAR *)filename, FA_OPEN_APPEND | FA_WRITE)) != FR_OK) {
- printf("Error opening file %s\n", FF_ERRORS[err]);
- return err;
- }
- printf("File opened!\n");
-
- generateMessage(length);
-
- if ((err = f_write(&file, &message, length, &bytes_written)) != FR_OK) {
- printf("Error writing file: %s\n", FF_ERRORS[err]);
- return err;
- }
- printf("%d bytes written to file\n", bytes_written);
-
- if ((err = f_close(&file)) != FR_OK) {
- printf("Error closing file: %s\n", FF_ERRORS[err]);
- return err;
- }
- printf("File closed.\n");
- return err;
-}
-
-int mkdir()
-{
- if (!mounted) {
- mount();
- }
-
- printf("Enter directory name: \n");
- scanf("%255s", directory);
-
- err = f_stat((const TCHAR *)directory, &fno);
- if (err == FR_NO_FILE) {
- printf("Creating directory...\n");
-
- if ((err = f_mkdir((const TCHAR *)directory)) != FR_OK) {
- printf("Error creating directory: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- } else {
- printf("Directory %s created.\n", directory);
- }
-
- } else {
- printf("Directory already exists.\n");
- }
- return err;
-}
-
-int cd()
-{
- if (!mounted) {
- mount();
- }
-
- printf("Directory to change into: \n");
- scanf("%255s", directory);
-
- if ((err = f_stat((const TCHAR *)directory, &fno)) == FR_NO_FILE) {
- printf("Directory doesn't exist (Did you mean mkdir?)\n");
- return err;
- }
-
- if ((err = f_chdir((const TCHAR *)directory)) != FR_OK) {
- printf("Error in chdir: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- printf("Changed to %s\n", directory);
- f_getcwd(cwd, sizeof(cwd));
-
- return err;
-}
-
-int delete ()
-{
- if (!mounted) {
- mount();
- }
-
- printf("File or directory to delete (always recursive!)\n");
- scanf("%255s", filename);
-
- if ((err = f_stat((const TCHAR *)filename, &fno)) == FR_NO_FILE) {
- printf("File or directory doesn't exist\n");
- return err;
- }
-
- if ((err = f_unlink(filename)) != FR_OK) {
- printf("Error deleting file\n");
- return err;
- }
- printf("Deleted file %s\n", filename);
- return err;
-}
-
-int example()
-{
- unsigned int length = 256;
-
- if ((err = formatSDHC()) != FR_OK) {
- printf("Error Formatting SD Card: %s\n", FF_ERRORS[err]);
- return err;
- }
-
- //open SD Card
- if ((err = mount()) != FR_OK) {
- printf("Error opening SD Card: %s\n", FF_ERRORS[err]);
- return err;
- }
- printf("SD Card Opened!\n");
-
- if ((err = f_setlabel("MAXIM")) != FR_OK) {
- printf("Error setting drive label: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- if ((err = f_getfree(&volume, &clusters_free, &fs)) != FR_OK) {
- printf("Error finding free size of card: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- if ((err = f_getlabel(&volume, volume_label, &volume_sn)) != FR_OK) {
- printf("Error reading drive label: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- if ((err = f_open(&file, "0:HelloWorld.txt", FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) {
- printf("Error opening file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("File opened!\n");
-
- generateMessage(length);
-
- if ((err = f_write(&file, &message, length, &bytes_written)) != FR_OK) {
- printf("Error writing file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("%d bytes written to file!\n", bytes_written);
-
- if ((err = f_close(&file)) != FR_OK) {
- printf("Error closing file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("File Closed!\n");
-
- if ((err = f_chmod("HelloWorld.txt", 0, AM_RDO | AM_ARC | AM_SYS | AM_HID)) != FR_OK) {
- printf("Error in chmod: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- err = f_stat("MaximSDHC", &fno);
- if (err == FR_NO_FILE) {
- printf("Creating Directory...\n");
- if ((err = f_mkdir("MaximSDHC")) != FR_OK) {
- printf("Error creating directory: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- }
-
- printf("Renaming File...\n");
- if ((err = f_rename("0:HelloWorld.txt", "0:MaximSDHC/HelloMaxim.txt")) !=
- FR_OK) { //cr: clearify 0:file notation
- printf("Error moving file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- if ((err = f_chdir("/MaximSDHC")) != FR_OK) {
- printf("Error in chdir: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- printf("Attempting to read back file...\n");
- if ((err = f_open(&file, "HelloMaxim.txt", FA_READ)) != FR_OK) {
- printf("Error opening file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- if ((err = f_read(&file, &message, bytes_written, &bytes_read)) != FR_OK) {
- printf("Error reading file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
-
- printf("Read Back %d bytes\n", bytes_read);
- printf("Message: ");
- printf("%s", message);
- printf("\n");
-
- if ((err = f_close(&file)) != FR_OK) {
- printf("Error closing file: %s\n", FF_ERRORS[err]);
- f_mount(NULL, "", 0);
- return err;
- }
- printf("File Closed!\n");
-
- //unmount SD Card
- //f_mount(fs, "", 0);
- if ((err = f_mount(NULL, "", 0)) != FR_OK) {
- printf("Error unmounting volume: %s\n", FF_ERRORS[err]);
- return err;
- }
-
- return 0;
-}
/******************************************************************************/
int main(void)
{
mxc_sdhc_cfg_t cfg;
-
- FF_ERRORS[0] = "FR_OK";
- FF_ERRORS[1] = "FR_DISK_ERR";
- FF_ERRORS[2] = "FR_INT_ERR";
- FF_ERRORS[3] = "FR_NOT_READY";
- FF_ERRORS[4] = "FR_NO_FILE";
- FF_ERRORS[5] = "FR_NO_PATH";
- FF_ERRORS[6] = "FR_INVLAID_NAME";
- FF_ERRORS[7] = "FR_DENIED";
- FF_ERRORS[8] = "FR_EXIST";
- FF_ERRORS[9] = "FR_INVALID_OBJECT";
- FF_ERRORS[10] = "FR_WRITE_PROTECTED";
- FF_ERRORS[11] = "FR_INVALID_DRIVE";
- FF_ERRORS[12] = "FR_NOT_ENABLED";
- FF_ERRORS[13] = "FR_NO_FILESYSTEM";
- FF_ERRORS[14] = "FR_MKFS_ABORTED";
- FF_ERRORS[15] = "FR_TIMEOUT";
- FF_ERRORS[16] = "FR_LOCKED";
- FF_ERRORS[17] = "FR_NOT_ENOUGH_CORE";
- FF_ERRORS[18] = "FR_TOO_MANY_OPEN_FILES";
- FF_ERRORS[19] = "FR_INVALID_PARAMETER";
- srand(12347439);
- int run = 1, input = -1;
-
- printf("\n\n***** " TOSTRING(TARGET) " SDHC FAT Filesystem Example *****\n");
+ int err;
+ printf("\n\n***** MAX78000 SDHC FAT Filesystem Example *****\n");
// Enable Power To Card
+ printf("Enabling card power...\n");
MXC_GPIO_Config(&SDPowerEnablePin);
MXC_GPIO_OutClr(MXC_GPIO1, SDPowerEnablePin.mask);
// Initialize SDHC peripheral
+ printf("Initializing SDHC peripheral...\n");
cfg.bus_voltage = MXC_SDHC_Bus_Voltage_3_3;
cfg.block_gap = 0;
cfg.clk_div =
@@ -547,14 +98,16 @@ int main(void)
}
// wait for card to be inserted
+ printf("Waiting for card to be inserted...\n");
while (!MXC_SDHC_Card_Inserted()) {}
printf("Card inserted.\n");
// set up card to get it ready for a transaction
- if (MXC_SDHC_Lib_InitCard(10) == E_NO_ERROR) {
+ printf("Initializing card...\n");
+ if ((err = MXC_SDHC_Lib_InitCard(10)) == E_NO_ERROR) {
printf("Card Initialized.\n");
} else {
- printf("No card response! Remove card, reset EvKit, and try again.\n");
+ printf("SDHC Library initialization failed with error %i\n", err);
return -1;
}
@@ -565,76 +118,15 @@ int main(void)
printf("Card type: MMC/eMMC\n");
}
- while (run) {
- f_getcwd(cwd, sizeof(cwd));
+ // Wait for any printfs to complete
+ while (MXC_UART_GetActive(MXC_UART_GET_UART(CONSOLE_UART))) {}
- printf("\nChoose one of the following options: \n");
- printf("0. Find the Size of the SD Card and Free Space\n");
- printf("1. Format the Card\n");
- printf("2. Manually Mount Card\n");
- printf("3. List Contents of Current Directory\n");
- printf("4. Create a Directory\n");
- printf("5. Move into a Directory (cd)\n");
- printf("6. Create a File of Random Data\n");
- printf("7. Add Random Data to an Existing File\n");
- printf("8. Delete a File\n");
- printf("9. Format Card and Run Exmaple of FatFS Operations\n");
- printf("10. Unmount Card and Quit\n");
- printf("%s>>", cwd);
-
- input = -1;
- scanf("%d", &input);
- printf("%d\n", input);
-
- err = 0;
-
- switch (input) {
- case 0:
- getSize();
- break;
- case 1:
- formatSDHC();
- break;
- case 3:
- ls();
- break;
- case 6:
- createFile();
- break;
- case 7:
- appendFile();
- break;
- case 4:
- mkdir();
- break;
- case 5:
- cd();
- break;
- case 9:
- example();
- break;
- case 10:
- umount();
- run = 0;
- break;
- case 2:
- mount();
- break;
- case 8:
- delete ();
- break;
- default:
- printf("Invalid Selection %d!\n", input);
- err = -1;
- break;
- }
- if (err >= 0 && err <= 20) {
- printf("Function Returned with code: %d\n", FF_ERRORS[err]);
- } else {
- printf("Function Returned with code: %d\n", err);
- }
- MXC_TMR_Delay(MXC_TMR0, MXC_DELAY_MSEC(500));
+ // Initialize CLI
+ if ((err = MXC_CLI_Init(MXC_UART_GET_UART(CONSOLE_UART), user_commands, num_user_commands)) !=
+ E_NO_ERROR) {
+ return err;
}
- printf("End of example, please try to read the card.\n");
- return 0;
+
+ // Run CLI
+ while (1) {}
}
diff --git a/Examples/MAX78002/SDHC_FAT/project.mk b/Examples/MAX78002/SDHC_FAT/project.mk
index 9398e395fec..79f69c992cc 100644
--- a/Examples/MAX78002/SDHC_FAT/project.mk
+++ b/Examples/MAX78002/SDHC_FAT/project.mk
@@ -13,8 +13,13 @@
# Add your config here!
+# Enable CLI library
+LIB_CLI = 1
# Enable SDHC library
LIB_SDHC = 1
# Use FatFS R0.15
FATFS_VERSION = ff15
+# Set 30Mhz SDHC clock frequency since MAX78002 initializes with 60Mhz system clock by default.
+# SDHC_CLK_FREQ can be increased to 60Mhz if the system clock is switched to the 120Mhz IPO.
+SDHC_CLK_FREQ = 30000000
diff --git a/Examples/MAX78002/SDHC_FAT/src/app-sdhc.c b/Examples/MAX78002/SDHC_FAT/src/app-sdhc.c
new file mode 100644
index 00000000000..688bbd3bee8
--- /dev/null
+++ b/Examples/MAX78002/SDHC_FAT/src/app-sdhc.c
@@ -0,0 +1,485 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2023 Analog Devices, Inc. All Rights Reserved. This software
+ * is proprietary to Analog Devices, Inc. and its licensors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include "app-sdhc.h"
+
+/***** Globals *****/
+FATFS *fs; //FFat Filesystem Object
+FATFS fs_obj;
+FIL file; //FFat File Object
+FRESULT err; //FFat Result (Struct)
+FILINFO fno; //FFat File Information Object
+DIR dir; //FFat Directory Object
+TCHAR *FF_ERRORS[20];
+BYTE work[4096];
+
+DWORD clusters_free = 0, sectors_free = 0, sectors_total = 0, volume_sn = 0;
+UINT bytes_written = 0, bytes_read = 0, mounted = 0;
+
+static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!";
+TCHAR message[MAXLEN], directory[MAXLEN], cwd[MAXLEN], filename[MAXLEN], volume_label[24],
+ volume = '0';
+
+// /***** FUNCTIONS *****/
+
+void generateMessage(unsigned length)
+{
+ for (int i = 0; i < length; i++) {
+ /*Generate some random data to put in file*/
+ message[i] = charset[rand() % (sizeof(charset) - 1)];
+ }
+}
+
+int mount()
+{
+ fs = &fs_obj;
+
+ if ((err = f_mount(fs, "", 1)) != FR_OK) { //Mount the default drive to fs now
+ printf("Error opening SD card: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ } else {
+ printf("SD card mounted.\n");
+ mounted = 1;
+ }
+
+ f_getcwd(cwd, sizeof(cwd)); //Set the Current working directory
+
+ return err;
+}
+
+int umount()
+{
+ if ((err = f_mount(NULL, "", 0)) != FR_OK) { //Unmount the default drive from its mount point
+ printf("Error unmounting volume: %s\n", FF_ERRORS[err]);
+ } else {
+ printf("SD card unmounted.\n");
+ mounted = 0;
+ }
+
+ return err;
+}
+
+int formatSDHC()
+{
+ printf("\n\n*****THE DRIVE WILL BE FORMATTED IN 5 SECONDS*****\n");
+ printf("**************PRESS ANY KEY TO ABORT**************\n\n");
+ MXC_UART_ClearRXFIFO(MXC_UART0);
+ MXC_Delay(MSEC(5000));
+
+ if (MXC_UART_GetRXFIFOAvailable(MXC_UART0) > 0) {
+ return E_ABORT;
+ }
+
+ printf("FORMATTING DRIVE\n");
+
+ MKFS_PARM format_options = { .fmt = FM_ANY };
+
+ if ((err = f_mkfs("", &format_options, work, sizeof(work))) != FR_OK) {
+ printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
+ } else {
+ printf("Drive formatted.\n");
+ }
+
+ mount();
+
+ if ((err = f_setlabel("MAXIM")) != FR_OK) {
+ printf("Error setting drive label: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ }
+
+ umount();
+
+ return err;
+}
+
+int getSize()
+{
+ if (!mounted) {
+ mount();
+ }
+
+ if ((err = f_getfree(&volume, &clusters_free, &fs)) != FR_OK) {
+ printf("Error finding free size of card: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ }
+
+ sectors_total = (fs->n_fatent - 2) * fs->csize;
+ sectors_free = clusters_free * fs->csize;
+
+ printf("Disk Size: %u bytes\n", sectors_total / 2);
+ printf("Available: %u bytes\n", sectors_free / 2);
+
+ return err;
+}
+
+int ls()
+{
+ if (!mounted) {
+ mount();
+ }
+
+ printf("Listing Contents of %s - \n", cwd);
+
+ if ((err = f_opendir(&dir, cwd)) == FR_OK) {
+ while (1) {
+ err = f_readdir(&dir, &fno);
+
+ if (err != FR_OK || fno.fname[0] == 0) {
+ break;
+ }
+
+ printf("%s/%s", cwd, fno.fname);
+
+ if (fno.fattrib & AM_DIR) {
+ printf("/");
+ }
+
+ printf("\n");
+ }
+
+ f_closedir(&dir);
+ } else {
+ printf("Error opening directory! %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ printf("\nFinished listing contents\n");
+
+ return err;
+}
+
+int createFile(char *file_name, unsigned int length)
+{
+ // unsigned int length = 128;
+
+ if (!mounted) {
+ mount();
+ }
+
+ snprintf(filename, MAXLEN, "%s", file_name);
+
+ if (length > MAXLEN) {
+ printf("Error. File size limit for this example is %d bytes.\n", MAXLEN);
+ return FR_INVALID_PARAMETER;
+ }
+
+ printf("Creating file %s with length %d\n", filename, length);
+
+ if ((err = f_open(&file, (const TCHAR *)filename, FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) {
+ printf("Error opening file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("File opened!\n");
+
+ generateMessage(length);
+
+ if ((err = f_write(&file, &message, length, &bytes_written)) != FR_OK) {
+ printf("Error writing file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("%d bytes written to file!\n", bytes_written);
+
+ if ((err = f_close(&file)) != FR_OK) {
+ printf("Error closing file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("File Closed!\n");
+ return err;
+}
+
+int appendFile(char *file_name, unsigned int length)
+{
+ if (!mounted) {
+ mount();
+ }
+
+ snprintf(filename, MAXLEN, "%s", file_name);
+
+ if ((err = f_stat((const TCHAR *)filename, &fno)) == FR_NO_FILE) {
+ printf("File %s doesn't exist!\n", (const TCHAR *)filename);
+ return err;
+ }
+
+ if (length > MAXLEN) {
+ printf("Error. Size limit for this example is %d bytes.\n", MAXLEN);
+ return FR_INVALID_PARAMETER;
+ }
+
+ if ((err = f_open(&file, (const TCHAR *)filename, FA_OPEN_APPEND | FA_WRITE)) != FR_OK) {
+ printf("Error opening file %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ printf("File opened!\n");
+
+ generateMessage(length);
+
+ if ((err = f_write(&file, &message, length, &bytes_written)) != FR_OK) {
+ printf("Error writing file: %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ printf("%d bytes written to file\n", bytes_written);
+
+ if ((err = f_close(&file)) != FR_OK) {
+ printf("Error closing file: %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ printf("File closed.\n");
+ return err;
+}
+
+int mkdir(char *dir_name)
+{
+ if (!mounted) {
+ mount();
+ }
+
+ snprintf(directory, MAXLEN, "%s", dir_name);
+
+ err = f_stat((const TCHAR *)directory, &fno);
+
+ if (err == FR_NO_FILE) {
+ printf("Creating directory...\n");
+
+ if ((err = f_mkdir((const TCHAR *)directory)) != FR_OK) {
+ printf("Error creating directory: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ } else {
+ printf("Directory %s created.\n", directory);
+ }
+
+ } else {
+ printf("Directory already exists.\n");
+ }
+
+ return err;
+}
+
+int cd(char *dir_name)
+{
+ if (!mounted) {
+ mount();
+ }
+
+ snprintf(directory, MAXLEN, "%s", dir_name);
+
+ if ((err = f_stat((const TCHAR *)directory, &fno)) == FR_NO_FILE) {
+ printf("Directory doesn't exist (Did you mean mkdir?)\n");
+ return err;
+ }
+
+ if ((err = f_chdir((const TCHAR *)directory)) != FR_OK) {
+ printf("Error in chdir: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("Changed to %s\n", directory);
+ f_getcwd(cwd, sizeof(cwd));
+
+ return err;
+}
+
+int deleteFile(char *file_name)
+{
+ if (!mounted) {
+ mount();
+ }
+
+ snprintf(filename, MAXLEN, "%s", file_name);
+
+ if ((err = f_stat((const TCHAR *)filename, &fno)) == FR_NO_FILE) {
+ printf("File or directory doesn't exist\n");
+ return err;
+ }
+
+ if ((err = f_unlink(filename)) != FR_OK) {
+ printf("Error deleting file\n");
+ return err;
+ }
+
+ printf("Deleted file %s\n", filename);
+ return err;
+}
+
+int example()
+{
+ unsigned int length = 256;
+
+ if ((err = formatSDHC()) != FR_OK) {
+ printf("Error Formatting SD Card: %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ //open SD Card
+ if ((err = mount()) != FR_OK) {
+ printf("Error opening SD Card: %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ printf("SD Card Opened!\n");
+
+ if ((err = f_setlabel("MAXIM")) != FR_OK) {
+ printf("Error setting drive label: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ if ((err = f_getfree(&volume, &clusters_free, &fs)) != FR_OK) {
+ printf("Error finding free size of card: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ if ((err = f_getlabel(&volume, volume_label, &volume_sn)) != FR_OK) {
+ printf("Error reading drive label: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ if ((err = f_open(&file, "0:HelloWorld.txt", FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) {
+ printf("Error opening file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("File opened!\n");
+
+ generateMessage(length);
+
+ if ((err = f_write(&file, &message, length, &bytes_written)) != FR_OK) {
+ printf("Error writing file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("%d bytes written to file!\n", bytes_written);
+
+ if ((err = f_close(&file)) != FR_OK) {
+ printf("Error closing file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("File Closed!\n");
+
+ if ((err = f_chmod("HelloWorld.txt", 0, AM_RDO | AM_ARC | AM_SYS | AM_HID)) != FR_OK) {
+ printf("Error in chmod: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ err = f_stat("MaximSDHC", &fno);
+
+ if (err == FR_NO_FILE) {
+ printf("Creating Directory...\n");
+
+ if ((err = f_mkdir("MaximSDHC")) != FR_OK) {
+ printf("Error creating directory: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+ }
+
+ printf("Renaming File...\n");
+
+ if ((err = f_rename("0:HelloWorld.txt", "0:MaximSDHC/HelloMaxim.txt")) !=
+ FR_OK) { //cr: clearify 0:file notation
+ printf("Error moving file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ if ((err = f_chdir("/MaximSDHC")) != FR_OK) {
+ printf("Error in chdir: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("Attempting to read back file...\n");
+
+ if ((err = f_open(&file, "HelloMaxim.txt", FA_READ)) != FR_OK) {
+ printf("Error opening file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ if ((err = f_read(&file, &message, bytes_written, &bytes_read)) != FR_OK) {
+ printf("Error reading file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("Read Back %d bytes\n", bytes_read);
+ printf("Message: ");
+ printf("%s", message);
+ printf("\n");
+
+ if ((err = f_close(&file)) != FR_OK) {
+ printf("Error closing file: %s\n", FF_ERRORS[err]);
+ f_mount(NULL, "", 0);
+ return err;
+ }
+
+ printf("File Closed!\n");
+
+ //unmount SD Card
+ //f_mount(fs, "", 0);
+ if ((err = f_mount(NULL, "", 0)) != FR_OK) {
+ printf("Error unmounting volume: %s\n", FF_ERRORS[err]);
+ return err;
+ }
+
+ return 0;
+}
+
+void waitCardInserted()
+{
+ // On the MAX78000FTHR board, P0.12 will be pulled low when a card is inserted.
+ mxc_gpio_cfg_t cardDetect;
+ cardDetect.port = MXC_GPIO0;
+ cardDetect.mask = MXC_GPIO_PIN_12;
+ cardDetect.func = MXC_GPIO_FUNC_IN;
+ cardDetect.pad = MXC_GPIO_PAD_NONE;
+ cardDetect.vssel = MXC_GPIO_VSSEL_VDDIOH;
+
+ MXC_GPIO_Config(&cardDetect);
+
+ // Exit function if card is already inserted
+ if (MXC_GPIO_InGet(MXC_GPIO0, MXC_GPIO_PIN_12) == 0) {
+ return;
+ }
+
+ printf("Insert SD card to continue.\n");
+
+ while (MXC_GPIO_InGet(MXC_GPIO0, MXC_GPIO_PIN_12) != 0) {
+ // Spin waiting for card to be inserted.
+ }
+
+ // Card has been detected, exit the function.
+}
diff --git a/Examples/MAX78002/SDHC_FAT/src/user-cli.c b/Examples/MAX78002/SDHC_FAT/src/user-cli.c
new file mode 100644
index 00000000000..085b03c4f21
--- /dev/null
+++ b/Examples/MAX78002/SDHC_FAT/src/user-cli.c
@@ -0,0 +1,153 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2023 Analog Devices, Inc. All Rights Reserved. This software
+ * is proprietary to Analog Devices, Inc. and its licensors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+#include
+#include "cli.h"
+#include "app-sdhc.h"
+#include "user-cli.h"
+
+const command_t user_commands[] = {
+ { "size", "size", "Find the Size of the SD Card and Free Space", handle_size },
+ { "format", "format", "Format the Card", handle_format },
+ { "mount", "mount", "Manually Mount Card", handle_mount },
+ { "ls", "ls", "list the contents of the current directory", handle_ls },
+ { "mkdir", "mkdir ", "Create a directory", handle_mkdir },
+ { "file_create", "file_create ",
+ "Create a file of random data", handle_createfile },
+ { "cd", "cd ", "Move into a directory", handle_cd },
+ { "add_data", "add_data ",
+ "Add random Data to an Existing File", handle_add_data },
+ { "del", "del ", "Delete a file", handle_del },
+ { "fatfs", "fatfs", "Format Card and Run Example of FatFS Operations", handle_fatfs },
+ { "unmount", "unmount", "Unmount card", handle_unmount },
+};
+
+const unsigned int num_user_commands = sizeof(user_commands) / sizeof(command_t);
+
+int handle_size(int argc, char *argv[])
+{
+ if (argc != 1) {
+ printf("Incorrect usage. Too many parameters.\n");
+ return E_INVALID;
+ }
+
+ return getSize();
+}
+
+int handle_format(int argc, char *argv[])
+{
+ if (argc != 1) {
+ printf("Incorrect usage. Too many parameters.\n");
+ return E_INVALID;
+ }
+
+ return formatSDHC();
+}
+
+int handle_mount(int argc, char *argv[])
+{
+ if (argc != 1) {
+ printf("Incorrect usage. Too many parameters.\n");
+ return E_INVALID;
+ }
+
+ return mount();
+}
+
+int handle_ls(int argc, char *argv[])
+{
+ if (argc != 1) {
+ printf("Incorrect usage. Too many parameters.\n");
+ return E_INVALID;
+ }
+
+ return ls();
+}
+
+int handle_mkdir(int argc, char *argv[])
+{
+ if (argc != 2) {
+ printf("Incorrect usage. Please provide directory name.\n");
+ return E_INVALID;
+ }
+
+ return mkdir(argv[1]);
+}
+
+int handle_createfile(int argc, char *argv[])
+{
+ if (argc != 3) {
+ printf("Incorrect usage. Please provide filename and length.\n");
+ return E_INVALID;
+ }
+
+ unsigned int length = atoi(argv[2]);
+ return createFile(argv[1], length);
+}
+
+int handle_cd(int argc, char *argv[])
+{
+ if (argc != 2) {
+ printf("Incorrect usage. Please provide directory name.\n");
+ return E_INVALID;
+ }
+
+ return cd(argv[1]);
+}
+
+int handle_add_data(int argc, char *argv[])
+{
+ if (argc != 3) {
+ printf("Incorrect usage. Please provide filename and length.\n");
+ return E_INVALID;
+ }
+
+ unsigned int length = atoi(argv[2]);
+ return appendFile(argv[1], length);
+}
+
+int handle_del(int argc, char *argv[])
+{
+ if (argc != 2) {
+ printf("Incorrect usage. Please provide filename.\n");
+ return E_INVALID;
+ }
+
+ return deleteFile(argv[1]);
+}
+
+int handle_fatfs(int argc, char *argv[])
+{
+ if (argc != 1) {
+ printf("Incorrect usage. Too many parameters.\n");
+ return E_INVALID;
+ }
+
+ return example();
+}
+
+int handle_unmount(int argc, char *argv[])
+{
+ if (argc != 1) {
+ printf("Incorrect usage. Too many parameters.\n");
+ return E_INVALID;
+ }
+
+ return umount();
+}
diff --git a/Examples/MAX78002/SDHC_Raw/.cproject b/Examples/MAX78002/SDHC_Raw/.cproject
index ed363dd5496..4e936218df2 100644
--- a/Examples/MAX78002/SDHC_Raw/.cproject
+++ b/Examples/MAX78002/SDHC_Raw/.cproject
@@ -33,7 +33,7 @@
-
+
diff --git a/Examples/MAX78002/SDHC_Raw/.vscode/settings.json b/Examples/MAX78002/SDHC_Raw/.vscode/settings.json
index cbc720d9df8..4344728afa1 100755
--- a/Examples/MAX78002/SDHC_Raw/.vscode/settings.json
+++ b/Examples/MAX78002/SDHC_Raw/.vscode/settings.json
@@ -54,7 +54,7 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/SDHC/Include",
- "${config:MAXIM_PATH}/Libraries/SDHC/ff13/Source",
+ "${config:MAXIM_PATH}/Libraries/SDHC/ff15/Source",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/EEPROM",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/CODEC"
],
@@ -70,7 +70,7 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/MiscDrivers",
- "${config:MAXIM_PATH}/Libraries/SDHC/ff13/Source",
+ "${config:MAXIM_PATH}/Libraries/SDHC/ff15/Source",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/ADC",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/EEPROM",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/CODEC"
diff --git a/Examples/MAX78002/SDHC_Raw/main.c b/Examples/MAX78002/SDHC_Raw/main.c
index 2f57636d7ce..36b22683d54 100644
--- a/Examples/MAX78002/SDHC_Raw/main.c
+++ b/Examples/MAX78002/SDHC_Raw/main.c
@@ -295,15 +295,6 @@ int main(void)
printf("Card type: MMC/eMMC\n");
}
- /* Configure for fastest possible clock, must not exceed 52 MHz for eMMC */
- if (SystemCoreClock > 96000000) {
- printf("SD clock ratio (at card) 4:1\n");
- MXC_SDHC_Set_Clock_Config(1);
- } else {
- printf("SD clock ratio (at card) 2:1\n");
- MXC_SDHC_Set_Clock_Config(0);
- }
-
/*** 1-bit data bus ***/
printf("--> 1-bit data bus example <--\n");
diff --git a/Examples/MAX78002/SDHC_Raw/project.mk b/Examples/MAX78002/SDHC_Raw/project.mk
index b8211c3c0bc..d5fd4657f88 100644
--- a/Examples/MAX78002/SDHC_Raw/project.mk
+++ b/Examples/MAX78002/SDHC_Raw/project.mk
@@ -14,4 +14,5 @@
# Add your config here!
LIB_SDHC = 1
-
+# Set 10Mhz clock frequency
+SDHC_CLK_FREQ = 10000000
diff --git a/Libraries/CLI/libinfo.json b/Libraries/CLI/libinfo.json
new file mode 100644
index 00000000000..59d9517c71b
--- /dev/null
+++ b/Libraries/CLI/libinfo.json
@@ -0,0 +1,10 @@
+{
+ "name":"CLI",
+ "ipaths":[
+ "inc"
+ ],
+ "vpaths":[
+ "src"
+ ],
+ "whitelist":"False"
+}
diff --git a/Libraries/PeriphDrivers/Source/SDHC/sdhc_ai87.c b/Libraries/PeriphDrivers/Source/SDHC/sdhc_ai87.c
index 10afe968c25..b4ae6591770 100644
--- a/Libraries/PeriphDrivers/Source/SDHC/sdhc_ai87.c
+++ b/Libraries/PeriphDrivers/Source/SDHC/sdhc_ai87.c
@@ -103,11 +103,11 @@ unsigned int MXC_SDHC_Get_Input_Clock_Freq(void)
// register description for MXC_GCR->pclkdiv marks the usual SDHC divider as reserved.
// We will follow figure 4-1 for now.
- // if (MXC_GCR->pclkdiv & MXC_F_GCR_PCLKDIV_SDHC) {
- // return SystemCoreClock >> 2; // Div by 4
- // } else {
- // return SystemCoreClock >> 1; // Div by 2
- // }
+ if (MXC_GCR->pclkdiv & MXC_F_GCR_PCLKDIS1_SDHC) {
+ return SystemCoreClock >> 2; // Div by 4
+ } else {
+ return SystemCoreClock >> 1; // Div by 2
+ }
return SystemCoreClock;
}
diff --git a/Libraries/SDHC/Source/sdhc_lib.c b/Libraries/SDHC/Source/sdhc_lib.c
index e1340b432be..94a46f654ab 100644
--- a/Libraries/SDHC/Source/sdhc_lib.c
+++ b/Libraries/SDHC/Source/sdhc_lib.c
@@ -456,8 +456,9 @@ int MXC_SDHC_Lib_InitCard(int retries)
// First, there is a GCR register setting to determine the input clock to the peripheral.
// This varies between micros, so a native implementation for each one is maintained in
// sdhc_mexx.c
- unsigned int sdhc_clk_freq = MXC_SDHC_Get_Input_Clock_Freq();
- unsigned int sdhc_clk_div = sdhc_clk_freq / (2 * SDHC_CLK_FREQ);
+ unsigned int sdhc_input_clk_freq = MXC_SDHC_Get_Input_Clock_Freq();
+ MXC_ASSERT(sdhc_input_clk_freq >= SDHC_CLK_FREQ);
+ unsigned int sdhc_clk_div = sdhc_input_clk_freq / (2 * SDHC_CLK_FREQ);
MXC_SDHC_Set_Clock_Config(sdhc_clk_div);
return E_NO_ERROR;
diff --git a/Libraries/SDHC/ff13/fat32.mk b/Libraries/SDHC/ff13/fat32.mk
index dd2d625f682..9c4ad6dfbe2 100644
--- a/Libraries/SDHC/ff13/fat32.mk
+++ b/Libraries/SDHC/ff13/fat32.mk
@@ -91,6 +91,9 @@ LIBS += ${FAT32_DRIVER_BUILD_DIR}/FAT32.a
IPATH += ${FAT32_DRIVER_DIR}/Source
# Add rule to build the Driver Library
-${FAT32_DRIVER_BUILD_DIR}/FAT32.a: FORCE
+${FAT32_DRIVER_BUILD_DIR}/FAT32.a: $(PROJECTMK)
$(MAKE) -C ${FAT32_DRIVER_DIR} lib BUILD_DIR=${FAT32_DRIVER_BUILD_DIR} BOARD=${BOARD}
+distclean:
+ $(MAKE) -C ${SDHC_DRIVER_DIR} clean
+
diff --git a/Libraries/SDHC/ff14/fat32.mk b/Libraries/SDHC/ff14/fat32.mk
index ec23cbbb2c9..e8fd395656f 100644
--- a/Libraries/SDHC/ff14/fat32.mk
+++ b/Libraries/SDHC/ff14/fat32.mk
@@ -91,6 +91,8 @@ LIBS += ${FAT32_DRIVER_BUILD_DIR}/FAT32.a
IPATH += ${FAT32_DRIVER_DIR}/Source
# Add rule to build the Driver Library
-${FAT32_DRIVER_BUILD_DIR}/FAT32.a: FORCE
+${FAT32_DRIVER_BUILD_DIR}/FAT32.a: $(PROJECTMK)
$(MAKE) -C ${FAT32_DRIVER_DIR} lib BUILD_DIR=${FAT32_DRIVER_BUILD_DIR} BOARD=${BOARD}
+distclean:
+ $(MAKE) -C ${SDHC_DRIVER_DIR} clean
diff --git a/Libraries/SDHC/ff15/fat32.mk b/Libraries/SDHC/ff15/fat32.mk
index 3a5201303e5..a28443316fb 100644
--- a/Libraries/SDHC/ff15/fat32.mk
+++ b/Libraries/SDHC/ff15/fat32.mk
@@ -89,6 +89,9 @@ LIBS += ${FAT32_DRIVER_BUILD_DIR}/FAT32.a
IPATH += ${FAT32_DRIVER_DIR}/source
# Add rule to build the Driver Library
-${FAT32_DRIVER_BUILD_DIR}/FAT32.a: FORCE
+${FAT32_DRIVER_BUILD_DIR}/FAT32.a: $(PROJECTMK)
$(MAKE) -C ${FAT32_DRIVER_DIR} lib BUILD_DIR=${FAT32_DRIVER_BUILD_DIR} BOARD=${BOARD}
+distclean:
+ $(MAKE) -C ${SDHC_DRIVER_DIR} clean
+
diff --git a/Libraries/SDHC/sdhc.mk b/Libraries/SDHC/sdhc.mk
index a34ea2f451d..1ce0fca3430 100644
--- a/Libraries/SDHC/sdhc.mk
+++ b/Libraries/SDHC/sdhc.mk
@@ -91,6 +91,8 @@ LIBS += ${SDHC_DRIVER_BUILD_DIR}/sdhc.a
IPATH += ${SDHC_DRIVER_DIR}/Include
# Add rule to build the Driver Library
-${SDHC_DRIVER_BUILD_DIR}/sdhc.a: FORCE
- $(MAKE) -C ${SDHC_DRIVER_DIR} lib BUILD_DIR=${SDHC_DRIVER_BUILD_DIR} BOARD=${BOARD}
+${SDHC_DRIVER_BUILD_DIR}/sdhc.a: $(PROJECTMK)
+ $(MAKE) -C ${SDHC_DRIVER_DIR} lib BUILD_DIR=${SDHC_DRIVER_BUILD_DIR} BOARD=${BOARD} PROJECTMK=$(PROJECTMK)
+distclean:
+ $(MAKE) -C ${SDHC_DRIVER_DIR} clean
diff --git a/Libraries/libs.mk b/Libraries/libs.mk
index 85e0d919fa2..d9bd7cb781b 100644
--- a/Libraries/libs.mk
+++ b/Libraries/libs.mk
@@ -173,7 +173,7 @@ endif
FAT32_DRIVER_DIR ?= $(SDHC_DRIVER_DIR)/$(FATFS_VERSION)
# Set default SDHC clock frequency (40Mhz)
-SDHC_CLK_FREQ ?= 40000000
+SDHC_CLK_FREQ ?= 30000000
PROJ_CFLAGS += -DSDHC_CLK_FREQ=$(SDHC_CLK_FREQ)
# Include the SDHC library
diff --git a/USERGUIDE.md b/USERGUIDE.md
index a83c6a3c649..a3ee7068b21 100644
--- a/USERGUIDE.md
+++ b/USERGUIDE.md
@@ -2298,7 +2298,7 @@ Once enabled, the following [build configuration variables](#build-configuration
| Configuration Variable | Description | Details |
| ---------------------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
| `FATFS_VERSION` | Specify the version of [FatFS](http://elm-chan.org/fsw/ff/00index_e.html) to use | FatFS is a generic FAT/exFAT filesystem that comes as a sub-component of the SDHC library. This variable can be used to change the [version](http://elm-chan.org/fsw/ff/updates.html) to use. Acceptable values are `ff13` (R0.13), `ff14` (R0.14b), or `ff15` (R0.15) |
-| `SDHC_CLK_FREQ` | Sets the clock freq. for the SDHC library (Hz) | Sets the target clock frequency in units of Hz (Default is 40Mhz). Reducing the SDHC clock frequency is a good troubleshooting step when debugging communication issues. |
+| `SDHC_CLK_FREQ` | Sets the clock freq. for the SDHC library (Hz) | Sets the target clock frequency in units of Hz (Default is 30Mhz). Reducing the SDHC clock frequency is a good troubleshooting step when debugging communication issues. |
---