diff --git a/Examples/MAX32650/SDHC_FAT/main.c b/Examples/MAX32650/SDHC_FAT/main.c index 249cd81b610..d9673114fb6 100644 --- a/Examples/MAX32650/SDHC_FAT/main.c +++ b/Examples/MAX32650/SDHC_FAT/main.c @@ -60,15 +60,15 @@ /***** Functions *****/ int main(void) { - int err; + int err; printf("\n\n***** " TOSTRING(TARGET) " SDHC FAT Filesystem Example *****\n"); MXC_ICC_Disable(); if (sdhc_init() != E_NO_ERROR) { - printf("Unable to initialize the SDHC card.\n"); - return E_BAD_STATE; + printf("Unable to initialize the SDHC card.\n"); + return E_BAD_STATE; } printf("SDHC Ready!\n"); diff --git a/Examples/MAX32650/SDHC_FAT/src/sdhc_example.c b/Examples/MAX32650/SDHC_FAT/src/sdhc_example.c index f2bb8cc6de6..86fb7ad91e0 100644 --- a/Examples/MAX32650/SDHC_FAT/src/sdhc_example.c +++ b/Examples/MAX32650/SDHC_FAT/src/sdhc_example.c @@ -65,63 +65,62 @@ mxc_gpio_cfg_t SDPowerEnablePin = { MXC_GPIO3, MXC_GPIO_PIN_5, MXC_GPIO_FUNC_OUT // ****************************************************************************** int sdhc_init(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"; - - // Enable Power To Card - MXC_GPIO_Config(&SDPowerEnablePin); - MXC_GPIO_OutClr(MXC_GPIO1, SDPowerEnablePin.mask); - - // Initialize SDHC peripheral - cfg.bus_voltage = MXC_SDHC_Bus_Voltage_3_3; - cfg.block_gap = 0; - cfg.clk_div = - 0x0b0; // Maximum divide ratio, frequency must be >= 400 kHz during Card Identification phase - if (MXC_SDHC_Init(&cfg) != E_NO_ERROR) { - printf("Unable to initialize SDHC driver.\n"); - return 1; - } - - // wait for card to be inserted - 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("Card Initialized.\n"); - } else { - printf("No card response! Remove card, reset EvKit, and try again.\n"); - - return -1; - } - - if (MXC_SDHC_Lib_Get_Card_Type() == CARD_SDHC) { - printf("Card type: SDHC\n"); - } else { - printf("Card type: MMC/eMMC\n"); - } - - return E_NO_ERROR; + 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"; + + // Enable Power To Card + MXC_GPIO_Config(&SDPowerEnablePin); + MXC_GPIO_OutClr(MXC_GPIO1, SDPowerEnablePin.mask); + + // Initialize SDHC peripheral + cfg.bus_voltage = MXC_SDHC_Bus_Voltage_3_3; + cfg.block_gap = 0; + cfg.clk_div = + 0x0b0; // Maximum divide ratio, frequency must be >= 400 kHz during Card Identification phase + if (MXC_SDHC_Init(&cfg) != E_NO_ERROR) { + printf("Unable to initialize SDHC driver.\n"); + return 1; + } + + // wait for card to be inserted + 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("Card Initialized.\n"); + } else { + printf("No card response! Remove card, reset EvKit, and try again.\n"); + return -1; + } + + if (MXC_SDHC_Lib_Get_Card_Type() == CARD_SDHC) { + printf("Card type: SDHC\n"); + } else { + printf("Card type: MMC/eMMC\n"); + } + + return E_NO_ERROR; } // ****************************************************************************** diff --git a/Examples/MAX32670/Flash_CLI/definitions.h b/Examples/MAX32670/Flash_CLI/definitions.h index fd8252caacb..26064ef4a46 100644 --- a/Examples/MAX32670/Flash_CLI/definitions.h +++ b/Examples/MAX32670/Flash_CLI/definitions.h @@ -44,26 +44,28 @@ #define POLY 0xEDB88320 // CRC Polynomial // CLI command table -#define CMD_TABLE { { "write", \ - "write ", \ - "Writes text string to flash starting at the 32-bit word in the\n flash " \ - "page specified by \"word offset\" (e.g. word offset=3 -> address\n " \ - "offset=0xC, word offset=4 -> address offset=0x10)", \ - handle_write }, \ - { "erase", \ - "erase", \ - "Erases page in flash being operated on", \ - handle_erase }, \ - { "read", \ - "read ", \ - "Reads text from flash starting at the 32-bit word in the flash\n page " \ - "specified by \"word offset\" (e.g. word offset=3 -> address offset=0xC,\n" \ - " word offset=4 -> address offset=0x10)", \ - handle_read }, \ - { "crc", \ - "crc", \ - "Calculates CRC of entire flash page", \ +// clang-format off +#define CMD_TABLE { { "write", \ + "write ", \ + "Writes text string to flash starting at the 32-bit word in the\n" \ + " flash page specified by \"word offset\" (e.g. word offset=3 -> address\n" \ + " offset=0xC, word offset=4 -> address offset=0x10)", \ + handle_write }, \ + { "erase", \ + "erase", \ + "Erases page in flash being operated on", \ + handle_erase }, \ + { "read", \ + "read ", \ + "Reads text from flash starting at the 32-bit word in the flash\n" \ + " page specified by \"word offset\" (e.g. word offset=3 -> address offset=0xC,\n" \ + " word offset=4 -> address offset=0x10)", \ + handle_read }, \ + { "crc", \ + "crc", \ + "Calculates CRC of entire flash page", \ handle_crc } } +// clang-format on #define WORD_OFFSET_POS 1 #define DATA_POS 2 diff --git a/Examples/MAX32670/Flash_CLI/main.c b/Examples/MAX32670/Flash_CLI/main.c index 02810375f65..de22aedbbcb 100644 --- a/Examples/MAX32670/Flash_CLI/main.c +++ b/Examples/MAX32670/Flash_CLI/main.c @@ -70,9 +70,9 @@ int main(void) const unsigned int cmd_table_sz = sizeof(cmd_table) / sizeof(command_t); // Initialize CLI - if(MXC_CLI_Init(MXC_UART_GET_UART(CONSOLE_UART), cmd_table, cmd_table_sz) != E_NO_ERROR) { - printf("Failed to initialize command-line interface.\n"); - return E_BAD_STATE; + if (MXC_CLI_Init(MXC_UART_GET_UART(CONSOLE_UART), cmd_table, cmd_table_sz) != E_NO_ERROR) { + printf("Failed to initialize command-line interface.\n"); + return E_BAD_STATE; } // Run CLI @@ -84,23 +84,23 @@ int main(void) // ***************************************************************************** int handle_write(int argc, char *argv[]) { - int err, i = 0; - uint32_t data[MXC_FLASH_PAGE_SIZE/4]; + int err, i = 0; + uint32_t data[MXC_FLASH_PAGE_SIZE/4]; - // Check for an invalid command - if (argc != 3 || argv == NULL) { - printf("Invalid command format. Aborting flash write.\n"); - return E_BAD_PARAM; - } + // Check for an invalid command + if (argc != 3 || argv == NULL) { + printf("Invalid command format. Aborting flash write.\n"); + return E_BAD_PARAM; + } - // Get command-line arguments - int startaddr = FLASH_STORAGE_START_ADDR + atoi(argv[WORD_OFFSET_POS]) * 4; - char *text = argv[DATA_POS]; + // Get command-line arguments + int startaddr = FLASH_STORAGE_START_ADDR + atoi(argv[WORD_OFFSET_POS]) * 4; + char *text = argv[DATA_POS]; - // Convert character string to uint32_t since we must write flash in 32-bit words - for (int i = 0; i < strlen(text); i++) { - data[i] = (uint32_t)text[i]; - } + // Convert character string to uint32_t since we must write flash in 32-bit words + for (int i = 0; i < strlen(text); i++) { + data[i] = (uint32_t)text[i]; + } // Check if flash controller is busy if (MXC_FLC0->ctrl & MXC_F_FLC_CTRL_PEND) { @@ -130,28 +130,28 @@ int handle_write(int argc, char *argv[]) // Verify the flash write was successful err = flash_verify(startaddr, strlen(text), data); - if (err != E_NO_ERROR) { - printf("Write failed with error %i\n", err); - } else { - printf("Success\n"); - } + if (err != E_NO_ERROR) { + printf("Write failed with error %i\n", err); + } else { + printf("Success\n"); + } - return E_NO_ERROR; + return E_NO_ERROR; } // ***************************************************************************** int handle_read(int argc, char *argv[]) { - uint32_t addr; - uint8_t data[MXC_FLASH_PAGE_SIZE/4]; + uint32_t addr; + uint8_t data[MXC_FLASH_PAGE_SIZE/4]; - // Check for an invalid command - if (argc != 3 || argv == NULL) { - printf("Invalid command format. Aborting flash read.\n"); - return E_BAD_PARAM; - } + // Check for an invalid command + if (argc != 3 || argv == NULL) { + printf("Invalid command format. Aborting flash read.\n"); + return E_BAD_PARAM; + } - // Get command-line arguments + // Get command-line arguments int startaddr = FLASH_STORAGE_START_ADDR + atoi(argv[WORD_OFFSET_POS]) * 4; int length = atoi(argv[LENGTH_POS]); @@ -164,14 +164,14 @@ int handle_read(int argc, char *argv[]) data[i] = *(uint32_t *)addr; if (data[i] == 0xFF) { - printf("Read addr 0x%08X: %s\n", addr, "empty"); - } else { - printf("Read addr 0x%08X: %c\n", addr, data[i]); - } + printf("Read addr 0x%08X: %s\n", addr, "empty"); + } else { + printf("Read addr 0x%08X: %c\n", addr, data[i]); + } } - printf("Success:\n"); - printf("%s\n", (char *)data); + printf("Success:\n"); + printf("%s\n", (char *)data); return E_NO_ERROR; } @@ -179,7 +179,7 @@ int handle_read(int argc, char *argv[]) // ***************************************************************************** int handle_erase(int argc, char *argv[]) { - int err = E_NO_ERROR; + int err = E_NO_ERROR; // Check for an invalid command if (argc != 1 || argv == NULL) { @@ -187,12 +187,12 @@ int handle_erase(int argc, char *argv[]) return E_BAD_PARAM; } - // Check whether the flash page is already erased + // Check whether the flash page is already erased if (!check_erased(FLASH_STORAGE_START_ADDR, MXC_FLASH_PAGE_SIZE)) { - // Erase flash page if it's not already erased + // Erase flash page if it's not already erased if ((err = MXC_FLC_PageErase(FLASH_STORAGE_START_ADDR)) != E_NO_ERROR) { - printf("Failed to erase flash page.\n"); - return err; + printf("Failed to erase flash page.\n"); + return err; } } @@ -204,7 +204,7 @@ int handle_erase(int argc, char *argv[]) // ***************************************************************************** int handle_crc(int argc, char *argv[]) { - int err; + int err; mxc_crc_req_t req; // Check for an invalid command @@ -267,6 +267,6 @@ int check_mem(uint32_t startaddr, uint32_t length, uint32_t data) //****************************************************************************** int check_erased(uint32_t startaddr, uint32_t length) { - // Check whether flash memory is set to all 1's (erased state) + // Check whether flash memory is set to all 1's (erased state) return check_mem(startaddr, length, 0xFFFFFFFF); } diff --git a/Libraries/CLI/src/cli.c b/Libraries/CLI/src/cli.c index d5344a9dbd4..0e0069b5648 100644 --- a/Libraries/CLI/src/cli.c +++ b/Libraries/CLI/src/cli.c @@ -63,7 +63,7 @@ // Macro to call MXC_UART_Init function with appropriate parameters #if (TARGET_NUM == 32520 || TARGET_NUM == 32570 || TARGET_NUM == 32650) #define UART_INIT(uart) MXC_UART_Init(uart, UART_BAUD) -#elif TARGET_NUM == 32660 +#elif TARGET_NUM == 32660 #define UART_INIT(uart) MXC_UART_Init(uart, UART_BAUD, MAP_A) #elif TARGET_NUM == 32662 #define UART_INIT(uart) MXC_UART_Init(uart, UART_BAUD, MXC_UART_APB_CLK, MAP_A)