From 846224f0214f8b9d49909a8645d7ea8ac645bcb5 Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Mon, 2 Oct 2023 15:07:53 +0300 Subject: [PATCH 1/7] 24LC256 EEPROM driver added. --- .../EEPROM/eeprom_24lc256_driver.c | 244 ++++++++++++++++++ .../EEPROM/eeprom_24lc256_driver.h | 83 ++++++ 2 files changed, 327 insertions(+) create mode 100644 Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c create mode 100644 Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c new file mode 100644 index 00000000000..9499aec6f2e --- /dev/null +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c @@ -0,0 +1,244 @@ +/****************************************************************************** + * 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. + * + ******************************************************************************/ + +#include "eeprom_24lc256_driver.h" + +/******************************* Globals *******************************/ +static mxc_i2c_req_t req; ///< I2C request + +/******************************* Functions *******************************/ +static int i2c_transfer(mxc_i2c_req_t *req, uint8_t *txData, int txSize, uint8_t *rxData, + int rxSize) +{ + req->tx_buf = txData; // Write data buffer + req->tx_len = txSize; // Number of bytes to write + req->rx_buf = rxData; // Read data buffer + req->rx_len = rxSize; // Number of bytes to read + return MXC_I2C_MasterTransaction(req); +} + +static int i2c_write(mxc_i2c_req_t *req, uint8_t *txData, int txSize) +{ + return i2c_transfer(req, txData, txSize, NULL, 0); // Create I2C write request +} + +static int i2c_read(mxc_i2c_req_t *req, uint8_t *txData, uint8_t *rxData, int rxSize) +{ + return i2c_transfer(req, txData, 2, rxData, rxSize); // Create I2C read request +} + +/** + * @brief Initializes I2C registers EEPROM + * @param i2c I2C registers + * @param addr Slave I2C address of EEPROM. + * @returns #E_NO_ERROR if init succeeded. + * + */ +static int eeprom_24LC256_init(mxc_i2c_regs_t *i2c, uint8_t addr) +{ + req.i2c = i2c; + req.addr = addr; + req.tx_buf = NULL; + req.tx_len = 0; + req.rx_buf = NULL; + req.rx_len = 0; + req.restart = 0; + req.callback = NULL; + + return E_NO_ERROR; +} + +/** + * @brief Writes data from EEPROM + * @param addr Start address we want to read. + * @param data_buffer Data buffer to read. + * @param length Number of bytes to read. + * @returns #E_NO_ERROR if read succeeded. non-zero if an error occurred. + * + */ +static int eeprom_24LC256_read(uint16_t addr, uint8_t* data_buffer, uint16_t length) +{ + int err = E_NO_ERROR; + uint16_t remaining = length; + uint8_t* current_data_buffer = data_buffer; + uint16_t eeprom_addr_to_read = addr; + uint8_t send_buffer[2] = { 0x00, 0x00}; + + if(addr + length > _24LC256_EEPROM_SIZE) + { + return E_BAD_PARAM; + } + + while(remaining) + { + if(remaining <= I2C_MAX_READ_SIZE) + { + send_buffer[0] = eeprom_addr_to_read >> 8; + send_buffer[1] = (eeprom_addr_to_read & 0x00FF); + + // Read + err = i2c_read(&req, send_buffer, current_data_buffer, remaining); + if (err != E_NO_ERROR) { + return err; + }else{ + remaining = 0; + } + }else + { + send_buffer[0] = eeprom_addr_to_read >> 8; + send_buffer[1] = (eeprom_addr_to_read & 0x00FF); + + // Read + err = i2c_read(&req, send_buffer, current_data_buffer, I2C_MAX_READ_SIZE); + if (err != E_NO_ERROR) { + return err; + } + remaining -= I2C_MAX_READ_SIZE; + current_data_buffer += I2C_MAX_READ_SIZE; + eeprom_addr_to_read += I2C_MAX_READ_SIZE; + } + } + return E_NO_ERROR; +} + +/** + * @brief Writes a small chunk of data directly to the EEPROM. The written memory should be in the same page of EEPROM (1 page = 64 bytes) + * @param addr Address we want to write to. + * @param data_buffer Data buffer to write. + * @param length Number of bytes to write. + * @returns #E_NO_ERROR if write succeeded. non-zero if an error occurred. + * + */ +static int eeprom_24LC256_write_chunk(uint16_t addr, uint8_t* data_buffer, uint16_t length) +{ + int err = E_NO_ERROR; + int i = 0; + uint8_t send_buffer[66]; // Max write length is equal to page size (64 bytes). So, max buffer size 64 + 2 bytes + send_buffer[0] = addr >> 8; + send_buffer[1] = (addr & 0x00FF); + for(i = 0; i < length; i++) + { + send_buffer[i+2] = data_buffer[i]; + } + + // Write + err = i2c_write(&req, send_buffer, (length + 2)); + if (err != E_NO_ERROR) { + return err; + } + return E_NO_ERROR; +} + +/** + * @brief Writes data to the EEPROM + * @param addr Address we want to write to. + * @param data_buffer Data buffer to write. + * @param length Number of bytes to write. + * @returns #E_NO_ERROR if write succeeded. non-zero if an error occurred. + * + */ +static int eeprom_24LC256_write(uint16_t addr, uint8_t* data_buffer, uint32_t length) +{ + int err = E_NO_ERROR; + uint16_t remaining_data_length_to_write = length; + uint16_t remaining_size_until_page_end = 0; + uint8_t* current_data_buffer = data_buffer; + uint16_t eeprom_addr_to_write = addr; + if(addr + length > _24LC256_EEPROM_SIZE) + { + return E_BAD_PARAM; + } + + // EEPROM does not support writing to multiple pages simultaneously + // In fist operation, if we are not writing to start of a page, we should write until the end of that page. + if((addr % _24LC256_EEPROM_PAGE_SIZE) != 0) // If starting address is not multiple of 64 bytes (not start of a page) + { + remaining_size_until_page_end = _24LC256_EEPROM_PAGE_SIZE - (eeprom_addr_to_write & 0x3F); + if(remaining_data_length_to_write <= remaining_size_until_page_end) // if remaining data size is smaller than remaining page size + { + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, remaining_data_length_to_write); + if (err != E_NO_ERROR) { + return err; + }else{ + remaining_data_length_to_write = 0; + } + }else + { + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, remaining_size_until_page_end); // Write until the end of the page + if (err != E_NO_ERROR) { + return err; + }else{ + remaining_data_length_to_write -= remaining_size_until_page_end; + current_data_buffer += remaining_size_until_page_end; + eeprom_addr_to_write += remaining_size_until_page_end; + MXC_Delay(MXC_DELAY_MSEC(10)); // Wait for 10ms + } + } + } + + while(remaining_data_length_to_write) + { + if(remaining_data_length_to_write <= _24LC256_EEPROM_PAGE_SIZE) + { + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, remaining_data_length_to_write); + if (err != E_NO_ERROR) { + return err; + } + return E_NO_ERROR; + } + else + { + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, _24LC256_EEPROM_PAGE_SIZE); + if (err != E_NO_ERROR) { + return err; + }else{ + remaining_data_length_to_write -= _24LC256_EEPROM_PAGE_SIZE; + current_data_buffer += _24LC256_EEPROM_PAGE_SIZE; + eeprom_addr_to_write += _24LC256_EEPROM_PAGE_SIZE; + MXC_Delay(MXC_DELAY_MSEC(10)); // Wait for 10ms + } + } + } + return E_NO_ERROR; +} + +eeprom_24LC256_driver_t eeprom_24LC256_Open(void) +{ + eeprom_24LC256_driver_t SD; + SD.init = eeprom_24LC256_init; + SD.read = eeprom_24LC256_read; + SD.write_chunk = eeprom_24LC256_write_chunk; + SD.write = eeprom_24LC256_write; + + return SD; +} diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h new file mode 100644 index 00000000000..687a9f8970b --- /dev/null +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h @@ -0,0 +1,83 @@ +/** + * @file eeprom_24lc256_driver.h + * @brief 24LC256 EEPROM driver header + * @details Defines 24LC256 EEPROM + * Implements helper macros + **/ + +/****************************************************************************** + * 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 EEPROM_24LC256_DRIVER_H_ +#define EEPROM_24LC256_DRIVER_H_ + +#include +#include +#include +#include "mxc_delay.h" +#include "i2c.h" + +/**@def _24LC256_EEPROM_PAGE_SIZE + * @brief Page size of 24LC256 EEPROM + **/ +#define _24LC256_EEPROM_PAGE_SIZE 64 + +/**@def _24LC256_EEPROM_SIZE + * @brief Total size of 24LC256 EEPROM = 256 Kbit + **/ +#define _24LC256_EEPROM_SIZE 0x8000 // 32 KByte = 256 Kbit + +/**@def I2C + * @brief I2C Max read size for single transaction + **/ +#define I2C_MAX_READ_SIZE 256 + +/** + * @brief Structure with sensor function pointers + */ +typedef struct { + int (*init)(mxc_i2c_regs_t *i2c, uint8_t addr); ///< Pointer to + int (*read)(uint16_t addr, uint8_t* data_buffer, uint16_t length); + int (*write_chunk)(uint16_t addr, uint8_t* data_buffer, uint16_t length); + int (*write)(uint16_t addr, uint8_t* data_buffer, uint32_t length); +} eeprom_24LC256_driver_t; + +/** + * @brief Prepare EEPROM_24LC256_DRIVER function pointers + * + * @return eeprom_24LC256_driver_t instance + */ +eeprom_24LC256_driver_t eeprom_24LC256_Open(); + + +#endif /* EEPROM_24LC256_DRIVER_H_ */ From 4e9a4b57350eb894087a6756b80763334f8dd5b8 Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Tue, 3 Oct 2023 10:04:50 +0300 Subject: [PATCH 2/7] 24LC256 EEPROM example for Max32655 EVKIT added. --- Examples/MAX32655/I2C_EEPROM/.cproject | 81 ++++ Examples/MAX32655/I2C_EEPROM/.project | 33 ++ .../.settings/language.settings.xml | 15 + .../org.eclipse.cdt.codan.core.prefs | 93 ++++ .../.settings/org.eclipse.cdt.core.prefs | 20 + .../org.eclipse.core.resources.prefs | 2 + .../MAX32655/I2C_EEPROM/.vscode/README.md | 422 ++++++++++++++++++ .../I2C_EEPROM/.vscode/c_cpp_properties.json | 53 +++ .../MAX32655/I2C_EEPROM/.vscode/flash.gdb | 15 + .../MAX32655/I2C_EEPROM/.vscode/launch.json | 133 ++++++ .../MAX32655/I2C_EEPROM/.vscode/settings.json | 76 ++++ .../MAX32655/I2C_EEPROM/.vscode/tasks.json | 115 +++++ .../MAX32655/I2C_EEPROM/I2C_EEPROM.launch | 62 +++ Examples/MAX32655/I2C_EEPROM/Makefile | 395 ++++++++++++++++ Examples/MAX32655/I2C_EEPROM/README.md | 75 ++++ Examples/MAX32655/I2C_EEPROM/main.c | 192 ++++++++ Examples/MAX32655/I2C_EEPROM/project.mk | 16 + 17 files changed, 1798 insertions(+) create mode 100644 Examples/MAX32655/I2C_EEPROM/.cproject create mode 100644 Examples/MAX32655/I2C_EEPROM/.project create mode 100644 Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml create mode 100644 Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.codan.core.prefs create mode 100644 Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.core.prefs create mode 100644 Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.core.resources.prefs create mode 100644 Examples/MAX32655/I2C_EEPROM/.vscode/README.md create mode 100644 Examples/MAX32655/I2C_EEPROM/.vscode/c_cpp_properties.json create mode 100644 Examples/MAX32655/I2C_EEPROM/.vscode/flash.gdb create mode 100644 Examples/MAX32655/I2C_EEPROM/.vscode/launch.json create mode 100644 Examples/MAX32655/I2C_EEPROM/.vscode/settings.json create mode 100644 Examples/MAX32655/I2C_EEPROM/.vscode/tasks.json create mode 100644 Examples/MAX32655/I2C_EEPROM/I2C_EEPROM.launch create mode 100644 Examples/MAX32655/I2C_EEPROM/Makefile create mode 100644 Examples/MAX32655/I2C_EEPROM/README.md create mode 100644 Examples/MAX32655/I2C_EEPROM/main.c create mode 100644 Examples/MAX32655/I2C_EEPROM/project.mk diff --git a/Examples/MAX32655/I2C_EEPROM/.cproject b/Examples/MAX32655/I2C_EEPROM/.cproject new file mode 100644 index 00000000000..d9298b4c9ed --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.cproject @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/.project b/Examples/MAX32655/I2C_EEPROM/.project new file mode 100644 index 00000000000..561065f9745 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.project @@ -0,0 +1,33 @@ + + + I2C_EEPROM + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + MiscDrivers + 2 + C:/MaximSDK/Libraries/MiscDrivers + + + diff --git a/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml b/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml new file mode 100644 index 00000000000..5f595b9fc20 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.codan.core.prefs b/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.codan.core.prefs new file mode 100644 index 00000000000..59c0b37ba75 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.codan.core.prefs @@ -0,0 +1,93 @@ +eclipse.preferences.version=1 +org.eclipse.cdt.codan.checkers.errnoreturn=Warning +org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return\\")",implicit\=>false} +org.eclipse.cdt.codan.checkers.errreturnvalue=Error +org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused return value\\")"} +org.eclipse.cdt.codan.checkers.nocommentinside=-Error +org.eclipse.cdt.codan.checkers.nocommentinside.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Nesting comments\\")"} +org.eclipse.cdt.codan.checkers.nolinecomment=-Error +org.eclipse.cdt.codan.checkers.nolinecomment.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Line comments\\")"} +org.eclipse.cdt.codan.checkers.noreturn=Error +org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return value\\")",implicit\=>false} +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error +org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Abstract class cannot be instantiated\\")"} +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error +org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Ambiguous problem\\")"} +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment in condition\\")"} +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error +org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment to itself\\")"} +org.eclipse.cdt.codan.internal.checkers.CStyleCastProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.CStyleCastProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"C-Style cast instead of C++ cast\\")"} +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning +org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No break at end of case\\")",no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false,enable_fallthrough_quickfix_param\=>false} +org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning +org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Catching by reference is recommended\\")",unknown\=>false,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error +org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Circular inheritance\\")"} +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class members should be properly initialized\\")",skip\=>true} +org.eclipse.cdt.codan.internal.checkers.CopyrightProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.CopyrightProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Lack of copyright information\\")",regex\=>".*Copyright.*"} +org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem=Error +org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid 'decltype(auto)' specifier\\")"} +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Field cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Function cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.GotoStatementProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.GotoStatementProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Goto statement used\\")"} +org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error +org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid arguments\\")"} +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error +org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid template argument\\")"} +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Label statement not found\\")"} +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error +org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Member declaration not found\\")"} +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Method cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.MissCaseProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.MissCaseProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Missing cases in switch\\")"} +org.eclipse.cdt.codan.internal.checkers.MissDefaultProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.MissDefaultProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Missing default in switch\\")",defaultWithAllEnums\=>false} +org.eclipse.cdt.codan.internal.checkers.MissReferenceProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.MissReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Missing reference return value in assignment operator\\")"} +org.eclipse.cdt.codan.internal.checkers.MissSelfCheckProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.MissSelfCheckProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Missing self check in assignment operator\\")"} +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info +org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Name convention for function\\")",pattern\=>"^[a-z]",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning +org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class has a virtual method and non-virtual destructor\\")"} +org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error +org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid overload\\")"} +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redeclaration\\")"} +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error +org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redefinition\\")"} +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Return with parenthesis\\")"} +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Format String Vulnerability\\")"} +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning +org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Statement has no effect\\")",macro\=>true,exceptions\=>()} +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suggested parenthesis around expression\\")",paramNot\=>false} +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning +org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suspicious semicolon\\")",else\=>false,afterelse\=>false} +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Type cannot be resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused function declaration\\")",macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused static function\\")",macro\=>true} +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>true,exceptions\=>("@(\#)","$Id")} +org.eclipse.cdt.codan.internal.checkers.UsingInHeaderProblem=-Warning +org.eclipse.cdt.codan.internal.checkers.UsingInHeaderProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Using directive in header\\")"} +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error +org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Symbol is not resolved\\")"} +org.eclipse.cdt.codan.internal.checkers.VirtualMethodCallProblem=-Error +org.eclipse.cdt.codan.internal.checkers.VirtualMethodCallProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Virtual method call in constructor/destructor\\")"} +org.eclipse.cdt.qt.core.qtproblem=Warning +org.eclipse.cdt.qt.core.qtproblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>true,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>null} diff --git a/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.core.prefs b/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 00000000000..552530382e6 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,20 @@ +doxygen/doxygen_new_line_after_brief=true +doxygen/doxygen_use_brief_tag=false +doxygen/doxygen_use_javadoc_tags=true +doxygen/doxygen_use_pre_tag=false +doxygen/doxygen_use_structural_commands=false +eclipse.preferences.version=1 +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/BOARD/delimiter=; +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/BOARD/operation=append +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/BOARD/value=EvKit_V1 +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/GCC_PREFIX/delimiter=; +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/GCC_PREFIX/operation=replace +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/GCC_PREFIX/value=arm-none-eabi- +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/PROJECT/delimiter=; +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/PROJECT/operation=append +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/PROJECT/value=I2C_EEPROM +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/TARGET/delimiter=; +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/TARGET/operation=append +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/TARGET/value=MAX32655 +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/append=true +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1028364529/appendContributed=true diff --git a/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.core.resources.prefs b/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Examples/MAX32655/I2C_EEPROM/.vscode/README.md b/Examples/MAX32655/I2C_EEPROM/.vscode/README.md new file mode 100644 index 00000000000..8b58b503892 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.vscode/README.md @@ -0,0 +1,422 @@ +# VSCode-Maxim + +_(If you're viewing this document from within Visual Studio Code you can press `CTRL+SHIFT+V` to open a Markdown preview window.)_ + +## Quick Links + +* [MSDK User Guide](https://analog-devices-msdk.github.io/msdk/USERGUIDE/) + * If it's not in the README, check the UG. + * If it's not in the UG, open a ticket! +* [VSCode-Maxim Github](https://github.com/Analog-Devices-MSDK/VSCode-Maxim) + +## Introduction + +VSCode-Maxim is a set of [Visual Studio Code](https://code.visualstudio.com/) project configurations and utilities for enabling embedded development for [Analog Device's MSDK](https://github.com/Analog-Devices-MSDK/msdk) and the [MAX32xxx/MAX78xxx microcontrollers](https://www.analog.com/en/product-category/microcontrollers.html). + +The following features are supported: + +* Code editing with intellisense down to the register level +* Code compilation with the ability to easily re-target a project for different microcontrollers and boards +* Flashing programs +* GUI and command-line debugging + +## Dependencies + +* [Visual Studio Code](https://code.visualstudio.com/) + * [C/C++ VSCode Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) + * [Cortex-Debug Extension](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) +* [Analog Devices MSDK](https://www.analog.com/en/design-center/evaluation-hardware-and-software/software/software-download?swpart=SFW0010820A) + +## Installation + +The steps below are also available in video form in "Understanding Artificial Intelligence Episode 8.5 - Visual Studio Code" [here](https://www.analog.com/en/education/education-library/videos/6313212752112.html). + +1. Download and install the Analog Devices MSDK for your OS from the links below. For more detailed instructions on installing the MSDK, see the [MSDK User Guide](https://analog-devices-msdk.github.io/msdk/USERGUIDE/) + * [Windows](https://www.analog.com/en/design-center/evaluation-hardware-and-software/software/software-download?swpart=SFW0010820A) + * [Linux (Ubuntu)](https://www.analog.com/en/design-center/evaluation-hardware-and-software/software/software-download?swpart=SFW0018720A) + * [MacOS](https://www.analog.com/en/design-center/evaluation-hardware-and-software/software/software-download?swpart=SFW0018610A) + +2. Run the installer executable, and ensure that "Visual Studio Code Support" is enabled for your installation. + + ![Selected Components](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/installer_components.JPG) + +3. Finish the MSDK installation, taking note of where the MSDK was installed. + +4. Download & install Visual Studio Code for your OS [here](https://code.visualstudio.com/Download). + +5. Launch Visual Studio Code. + +6. Install the Microsoft [C/C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools). + +7. Install the [Cortex-Debug Extension](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) + +8. Use `CTRL + SHIFT + P` (or `COMMAND + SHIFT + P` on MacOS) to open the developer prompt. + +9. Type "open settings json" and select the "Preferences: Open Settings (JSON)" option (_not_ the "Preferences: Open _Default_ Settings (JSON)"). This will open your user settings.json file in VS Code's editor. + + ![Open Settings JSON Command](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/open_settings_json.jpg) + +10. Add the entries below into your user settings.json file. + + ```json + { + // There may be other settings up here... + + "MAXIM_PATH":"C:/MaximSDK", // Set this to the installed location of the Analog Devices MSDK. Only use forward slashes '/' when setting this path! + "update.mode": "manual", + "extensions.autoUpdate": false, + + // There may be other settings down here... + } + ``` + +11. Save your changes to the file with `CTRL + S` and restart VS Code. + +12. That's it! You're ready to start using Visual Studio Code to develop with Analog Devices MAX-series Microcontrollers. The MSDK examples come pre-populated with .vscode project folders, and the `Tools/VSCode-Maxim` folder of the MSDK contains documentation and templates. See [Usage](#usage) below for more details. + +## Usage + +This section covers basic usage of the VSCode-Maxim project files. For documentation on Visual Studio Code itself, please refer to the official docs [here](https://code.visualstudio.com/Docs). + +### Opening Projects + +Visual Studio Code is built around a "working directory" paradigm. The editor is always rooted in a working directory, and the main mechanism for changing that directory is `File -> Open Folder...`. + +![File -> Open Folder](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/file_openfolder.JPG) + +As a result, you'll notice that there is no "New Project" mechanism. A "project" in VS Code is simply a folder. It will look inside of the opened folder for a `.vscode` _sub_-folder to load project-specific settings from. + +A project that is configured for VS Code will have, at minimum, a .vscode sub-folder and a Makefile in its directory _(Note: You may need to enable viewing of hidden items in your file explorer to see the .vscode sub-folder)_. + +Ex: + +![Example Directory Contents](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/opening_projects_2.jpg) + +### Where to Find Projects + +The [Examples](https://github.com/Analog-Devices-MSDK/msdk/tree/main/Examples) in the MSDK come with with pre-configured .vscode project folders. These projects can be opened "out of the box", but it's good practice to copy example folders _outside_ of the MSDK so that the original copies are kept as clean references. The examples can be freely moved to any location _without a space in its path_. + +Additionally, empty project templates and a drag-and-drop folder for "injecting" a VSCode-Maxim project can be found under `Tools/VSCode-Maxim` in the MSDK installation. + +### Build Tasks + +Once a project is opened 4 available build tasks will become available via `Terminal > Run Build task...` or the shortcut `Ctrl+Shift+B`. These tasks are configured by the `.vscode/task.json` file. + +![Build Tasks Image](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/buildtasks.JPG) + +#### Build + +* Compiles the code with a `make all` command. +* Additional options are passed into Make on the command-line based on the project's settings.json file. +* The `./build` directory will be created and will contain the output binary, as well as all intermediary object files. + +#### Clean + +* Cleans the build output, removing the `./build` directory and all of its contents. + +#### Clean-Periph + +* This task is the same as 'clean', but it also removes the build output for the MSDK's peripheral drivers. +* Use this if you would like to recompile the peripheral drivers from source on the next build. + +#### Flash + +* Launching this task automatically runs the `Build` task first. Then, it flashes the output binary to the microcontroller. +* It uses the GDB `load` and `compare-sections` commands, and handles launching an OpenOCD internally via a pipe connection. +* The flashed program will be halted until the microcontroller is reset, power cycled, or a debugger is connected. +* A debugger must be connected correctly to use this task. Refer to the datasheet of your microcontroller's evaluation board for instructions. + +#### Flash & Run + +* This is the same as the `Flash` task, but it also will launch execution of the program once flashing is complete. + +#### Erase Flash + +* Completely erases all of the application code in the flash memory bank. +* Once complete, the target microcontroller will be effectively "blank". +* This can be useful for recovering from Low-Power (LP) lockouts, bad firmware, etc. + +### Debugging + +![Debug Window](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/debugger.JPG) + +Debugging is enabled by Visual Studio Code's integrated debugger. Launch configurations can be found in the `.vscode/launch.json` file. + +* Note: **Flashing does not happen automatically when launching the debugger.** Run the "Flash" [build task](#build-tasks) for your program _before_ debugging. + +#### Debugger Limitations + +In general, the MAX-series microcontrollers have the following debugger limitations at the hardware level: + +* The debugger can not be connected _while_ the device is in reset. + +* The device can not be debugged while the device is in Sleep, Low Power Mode, Micro Power Mode, Standby, Backup, or Shutdown mode. These modes shut down the SWD clock. + +* These limitations can sometimes make the device difficult or impossible to connect to if firmware has locked out the debugger. In such cases, the ["Erase Flash"](#erase-flash) task can be used to recover the part. + +#### Launching the Debugger + +1. Attach your debugger to the SWD port on the target microcontroller. (Refer to the datasheet of your evaluation board for instructions on connecting a debugger) + +2. Flash the program to the microcontroller with the "Flash" [Build Task](#build-tasks). **Flashing does not happen automatically when launching the debugger.** + +3. Launch the debugger with `Run > Start Debugging`, with the shortcut `F5`, or via the `Run and Debug` window (Ctrl + Shift + D) and the green "launch" arrow. + + ![Debug Tab](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/debugger_window.JPG) + +4. The debugger will launch a GDB client & OpenOCD server, reset the microcontroller, and should break on entry into `main`. + + ![Debugger Break on Main](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/debugger_breakmain.JPG) + +#### Using the Debugger + +* For full usage details, please refer to the [official VS Code debugger documentation](https://code.visualstudio.com/docs/editor/debugging). + +The main interface for the debugger is the debugger control bar: + +![Debugger Control Bar Image](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/debugger_bar.JPG) + +`Continue | Step Over | Step Into | Step Out | Restart | Stop` + +Breakpoints can be set by clicking in the space next to the line number in a source code file. A red dot indicates a line to break on. Breakpoints can be removed by clicking on them again. Ex: + +![Breakpoint](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/breakpoint.JPG) + +## Project Configuration + +### Project Settings + +`.vscode/settings.json` is the main project configuration file. Values set here are parsed into the other .json config files. + +**When a change is made to this file, VS Code should be reloaded with CTRL+SHIFT+P -> Reload Window (or alternatively restarted completely) to force a re-parse.** + +![Reload Window](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/reload_window.JPG) + +The default project configuration should work for most use cases as long as `"target"` and `"board"` are set correctly. + +Any field from `settings.json` can be referenced from any other config file (including itself) with `"${config:[fieldname]}"` + +The following configuration options are available: + +### Basic Config Options + +#### `"target"` + +* This sets the target microcontroller for the project. +* It sets the `TARGET` [Build Configuration](#build-configuration) variable. +* Supported values: + * `"MAX32520"` + * `"MAX32570"` + * `"MAX32650"` + * `"MAX32655"` + * `"MAX32660"` + * `"MAX32662"` + * `"MAX32665"` (for MAX32665-MAX32668) + * `"MAX32670"` + * `"MAX32672"` + * `"MAX32675"` + * `"MAX32680"` + * `"MAX32690"` + * `"MAX78000"` + * `"MAX78002"` + +#### `"board"` + +* This sets the target board for the project (ie. Evaluation Kit, Feather board, etc.) +* Supported values: + * ... can be found in the `Libraries/Boards` folder of the MSDK + * For example, the supported options for the MAX78000 are `"EvKit_V1"`, `"FTHR_RevA"`, and `"MAXREFDES178"`. + + ![MAX78000 Boards](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/main/img/78000_boards.JPG) + +### Advanced Config Options + +#### `"MAXIM_PATH"` + +* This option must point to the root installation directory of the MSDK. +* It should be placed in the _global_ user settings.json file during first-time VSCode-Maxim setup. See [Installation](#installation). + +#### `"terminal.integrated.env.[platform]:Path"` + +* This prepends the location of the MSDK toolchain binaries to the system `Path` used by VSCode's integrated terminal. +* The Path is not sanitized by default, which means that the terminal inherits the system path. +* Don't touch unless you know what you're doing :) + +#### `"project_name"` + +* Sets the name of project. This is used in other config options such as `program_file`. +* Default value: `"${workspaceFolderBasename}"` + +#### `"program_file"` + +* Sets the name of the file to flash and debug. This is provided in case it's needed, but for most use cases should be left at its default. +* File extension must be included. +* Default value: `"${config:project_name}.elf"` + +#### `"symbol_file"` + +* Sets the name of the file that GDB will load debug symbols from. +* File extension must be included. +* Default value: `"${config:program_file}"` + +#### `"M4_OCD_interface_file"` + +* Sets the OpenOCD interface file to use to connect to the Arm M4 core. This should match the debugger being used for the M4 core. +* The `MaximSDK/Tools/OpenOCD/scripts/interface` folder is searched for the file specified by this setting. +* `.cfg` file extension must be included. +* Default value: `"cmsis-dap.cfg"` + +#### `"M4_OCD_target_file"` + +* Sets the OpenOCD target file to use for the Arm M4 core. This should match the target microcontroller. +* `.cfg` file extension must be included. +* The `MaximSDK/Tools/OpenOCD/scripts/target` folder is searched for the file specified by this setting. +* Default value: `"${config:target}.cfg"` + +#### `"RV_OCD_interface_file"` + +* Sets the OpenOCD interface file to use to connect to the RISC-V core. This should match the debugger being used for the RISC-V core. +* The `MaximSDK/Tools/OpenOCD/scripts/interface` folder is searched for the file specified by this setting. +* `.cfg` file extension must be included. +* Default value: `"ftdi/olimex-arm-usb-ocd-h.cfg"` + +#### `"RV_OCD_target_file"` + +* Sets the OpenOCD target file to use for the RISC-V core. +* The `MaximSDK/Tools/OpenOCD/scripts/target` folder is searched for the file specified by this setting. +* `.cfg` file extension must be included. +* Default value: `"${config:target}_riscv.cfg"` + +#### `"v_Arm_GCC"` + +* Sets the version of the Arm Embedded GCC to use, including toolchain binaries and the standard library version. +* This gets parsed into `ARM_GCC_path`. +* Default value: `"10.3"` + +#### `"v_xPack_GCC"` + +* Sets the version of the xPack RISC-V GCC to use. +* This gets parsed into `xPack_GCC_path`. +* Default value: `"10.2.0-1.2"` + +#### `"OCD_path"` + +* Where to find the OpenOCD. +* Default value: `"${config:MAXIM_PATH}/Tools/OpenOCD"` + +#### `"ARM_GCC_path"` + +* Where to find the Arm Embedded GCC Toolchain. +* Default value: `"${config:MAXIM_PATH}/Tools/GNUTools/${config:v_Arm_GCC}"` + +#### `"xPack_GCC_path"` + +* Where to find the RISC-V GCC Toolchain. +* Default value: `"${config:MAXIM_PATH}/Tools/xPack/riscv-none-embed-gcc/${config:v_xPack_GCC}"` + +#### `"Make_path"` + +* Where to find Make binaries (only used on Windows) +* Default value: `"${config:MAXIM_PATH}/Tools/MSYS2/usr/bin"` + +#### `"C_Cpp.default.includePath"` + +* Which paths to search to find header (.h) files. +* Does not recursively search by default. To recursively search, use `/**`. + +#### `"C_Cpp.default.browse.path"` + +* Which paths to search to find source (.c) files. +* Does not recursively search by default. To recursively search, use `/**`. + +#### `"C_Cpp.default.defines"` + +* Sets the compiler definitions to use for the intellisense engine. +* Most definitions should be defined in header files, but if a definition is missing it can be entered here to get the intellisense engine to recognize it. + +### Setting Search Paths for Intellisense + +VS Code's intellisense engine must be told where to find the header files for your source code. By default, the MSDK's peripheral drivers, the C standard libraries, and all of the sub-directories of the workspace will be searched for header files to use with Intellisense. If VS Code throws an error on an `#include` statement (and the file exists), then a search path is most likely missing. + +To add additional search paths : + +1. Open the `.vscode/settings.json` file. + +2. Add the include path(s) to the `C_Cpp.default.includePath` list. The paths set here should contain header files, and will be searched by the Intellisense engine and when using "Go to Declaration" in the editor. + +3. Add the path(s) to any relevant implementation files to the `C_Cpp.default.browse.path` list. This list contains the paths that will be searched when using "Go to Definition". + +## Build Configuration + +A project's build system is managed by two files found in the project's root directory. These files are used alongside the [GNU Make](https://www.gnu.org/software/make/) program (which is a part of the MSDK toolchain) to locate and build a project's source code for the correct microcontroller. + +* `Makefile` +* `project.mk` + +![Files are located in the root directory](https://raw.githubusercontent.com/Analog-Devices-MSDK/VSCode-Maxim/65af7c61800c7039956f3c1971ffd7915008668d/img/projectmk.JPG) + +When the command... + +```shell +make +``` + +... is run, the program `make` will load settings from these two files. Then, it will use them to build the project's source code. VSCode-Maxim is a "wrapper" around this Makefile system. + +**See the [MSDK User Guide](https://analog-devices-msdk.github.io/msdk/USERGUIDE/#build-system) for full documentation on how to configure the build system.** + +## Project Creation + +### Option 1. Copying a Pre-Made Project + +Copying a pre-made example project is a great way to get rolling quickly, and is currently the recommended method for creating new projects. + +The release package for this project (Located at Tools/VSCode-Maxim in the Analog Devices MSDK) contains a `New_Project` folder designed for such purposes. Additionally, any of the VS Code-enabled Example projects can be copied from the MSDK. + +1. Copy the existing project folder to an accessible location. This will be the location of your new project. + +2. (Optional) Rename the folder. For example, I might rename the folder to `MyProject`. + +3. Open the project in VS Code (`File -> Open Folder...`) + +4. Set your target microcontroller and board correctly. See [Basic Config Options](#basic-config-options) + +5. `CTRL+SHIFT+P -> Reload Window` to re-parse the project settings. + +6. That's it! The existing project is ready to build, debug, and modify. + +### Option 2 - Injecting + +VSCode-Maxim releases provide the `Inject` folder for "injecting" into an existing folder. If you want to start from scratch or use the project files with existing source code, take this option. + +1. Create your project folder if necessary. For example, I might create a new project in a workspace folder with the path: `C:\Users\Jake.Carter\workspace\MyNewProject`. + +2. Copy the **contents** of the `Inject` folder into the project folder from step 1. The contents to copy include a `.vscode` folder, a `Makefile`, and a `project.mk` file. For this example, the contents of the 'MyProject' folder would be the following: + + ```shell + C:\Users\Jake.Carter\workspace\MyNewProject + |- .vscode + |- Makefile + |- project.mk + ``` + +3. Open the project in VS Code (`File -> Open Folder...`) + +4. Set your target microcontroller correctly. See [Basic Config Options](#basic-config-options). + +5. `CTRL+SHIFT+P -> Reload Window` to re-parse the project settings. + +6. Configure the [build system](https://analog-devices-msdk.github.io/msdk/USERGUIDE/#build-system) for use with any pre-existing source code. + +7. That's it! Your new empty project can now be opened with `File > Open Folder` from within VS Code. + +## Issue Tracker + +Bug reports, feature requests, and contributions are welcome via the [issues](https://github.com/Analog-Devices-MSDK/VSCode-Maxim/issues) tracker on Github. + +New issues should contain _at minimum_ the following information: + +* Visual Studio Code version #s (see `Help -> About`) +* C/C++ Extension version # +* Target microcontroller and evaluation platform +* The projects `.vscode` folder and `Makefile` (where applicable). Standard compression formats such as `.zip`, `.rar`, `.tar.gz`, etc. are all acceptable. diff --git a/Examples/MAX32655/I2C_EEPROM/.vscode/c_cpp_properties.json b/Examples/MAX32655/I2C_EEPROM/.vscode/c_cpp_properties.json new file mode 100644 index 00000000000..dfbed47b581 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.vscode/c_cpp_properties.json @@ -0,0 +1,53 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${default}" + ], + "defines": [ + "${default}" + ], + "intelliSenseMode": "gcc-arm", + "compilerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gcc.exe", + "browse": { + "path": [ + "${default}" + ] + } + }, + { + "name": "Linux", + "includePath": [ + "${default}" + ], + "defines": [ + "${default}" + ], + "intelliSenseMode": "gcc-arm", + "compilerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gcc", + "browse": { + "path": [ + "${default}" + ] + } + }, + { + "name": "Mac", + "includePath": [ + "${default}" + ], + "defines": [ + "${default}" + ], + "intelliSenseMode": "gcc-arm", + "compilerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gcc", + "browse": { + "path": [ + "${default}" + ] + } + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/.vscode/flash.gdb b/Examples/MAX32655/I2C_EEPROM/.vscode/flash.gdb new file mode 100644 index 00000000000..fc627ae86a3 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.vscode/flash.gdb @@ -0,0 +1,15 @@ +define flash_m4 + set architecture armv7e-m + target remote | openocd -c "gdb_port pipe;log_output flash.log" -s $arg0/scripts -f interface/$arg1 -f target/$arg2 -c "init; reset halt" + load + compare-sections + monitor reset halt +end + +define flash_m4_run + set architecture armv7e-m + target remote | openocd -c "gdb_port pipe;log_output flash.log" -s $arg0/scripts -f interface/$arg1 -f target/$arg2 -c "init; reset halt" + load + compare-sections + monitor resume +end \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/.vscode/launch.json b/Examples/MAX32655/I2C_EEPROM/.vscode/launch.json new file mode 100644 index 00000000000..af0d6f650c7 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.vscode/launch.json @@ -0,0 +1,133 @@ +{ + "configurations": [ + { + "name": "Debug Arm (Cortex-debug)", + "cwd":"${workspaceRoot}", + "executable": "${workspaceFolder}/build/${config:program_file}", + "loadFiles": ["${workspaceFolder}/build/${config:program_file}"], + "symbolFiles": [{ + "file": "${workspaceFolder}/build/${config:symbol_file}" + }], + "request": "launch", + "type": "cortex-debug", + "servertype": "openocd", + "linux": { + "gdbPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gdb", + "serverpath": "${config:OCD_path}/openocd", + }, + "windows": { + "gdbPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gdb.exe", + "serverpath": "${config:OCD_path}/openocd.exe", + }, + "osx": { + "gdbPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gdb", + "serverpath": "${config:OCD_path}/openocd", + }, + "searchDir": ["${config:OCD_path}/scripts"], + "configFiles": ["interface/${config:M4_OCD_interface_file}", "target/${config:M4_OCD_target_file}"], + "interface": "swd", + "runToEntryPoint": "main", + "svdFile": "${config:MAXIM_PATH}/Libraries/CMSIS/Device/Maxim/${config:target}/Include/${config:target}.svd" + }, + { + "name": "GDB (Arm M4)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/${config:program_file}", + "args": [], + "stopAtEntry": true, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "linux": { + "miDebuggerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gdb", + "debugServerPath": "${config:OCD_path}/openocd", + }, + "windows": { + "miDebuggerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gdb.exe", + "debugServerPath": "${config:OCD_path}/openocd.exe", + }, + "osx": { + "miDebuggerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gdb", + "debugServerPath": "${config:OCD_path}/bin/openocd", + }, + "logging": { + "exceptions": true, + "trace": false, + "traceResponse": false, + "engineLogging": false + }, + "miDebuggerServerAddress": "localhost:3333", + "debugServerArgs": "-s ${config:OCD_path}/scripts -f interface/${config:M4_OCD_interface_file} -f target/${config:M4_OCD_target_file} -c \"init; reset halt\"", + "serverStarted": "Info : Listening on port 3333 for gdb connections", + "filterStderr": true, + "targetArchitecture": "arm", + "customLaunchSetupCommands": [ + {"text":"-list-features"} + ], + "setupCommands": [ + { "text":"set logging overwrite on"}, + { "text":"set logging file debug-arm.log"}, + { "text":"set logging on"}, + { "text":"cd ${workspaceFolder}" }, + { "text":"exec-file build/${config:program_file}" }, + { "text":"symbol-file build/${config:symbol_file}" }, + { "text":"target remote localhost:3333" }, + { "text":"monitor reset halt" }, + { "text":"set $pc=Reset_Handler"}, + { "text":"b main" } + ] + }, + { + "name": "GDB (RISC-V)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/buildrv/${config:program_file}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "linux": { + "miDebuggerPath": "${config:xPack_GCC_path}/bin/riscv-none-embed-gdb", + "debugServerPath": "${config:OCD_path}/openocd", + }, + "windows": { + "miDebuggerPath": "${config:xPack_GCC_path}/bin/riscv-none-embed-gdb.exe", + "debugServerPath": "${config:OCD_path}/openocd.exe", + }, + "osx": { + "miDebuggerPath": "${config:xPack_GCC_path}/bin/riscv-none-embed-gdb", + "debugServerPath": "${config:OCD_path}/bin/openocd", + }, + "logging": { + "exceptions": true, + "trace": false, + "traceResponse": false, + "engineLogging": false + }, + "miDebuggerServerAddress": "localhost:3334", + "debugServerArgs": "-c \"gdb_port 3334\" -s ${config:OCD_path}/scripts -f interface/${config:RV_OCD_interface_file} -f target/${config:RV_OCD_target_file}", + "serverStarted": "Info : Listening on port 3334 for gdb connections", + "filterStderr": true, + "customLaunchSetupCommands": [ + {"text":"-list-features"} + ], + "targetArchitecture": "arm", + "setupCommands": [ + { "text":"set logging overwrite on"}, + { "text":"set logging file debug-riscv.log"}, + { "text":"set logging on"}, + { "text":"cd ${workspaceFolder}" }, + { "text": "set architecture riscv:rv32", "ignoreFailures": false }, + { "text":"exec-file build/${config:program_file}", "ignoreFailures": false }, + { "text":"symbol-file buildrv/${config:symbol_file}", "ignoreFailures": false }, + { "text":"target remote localhost:3334" }, + { "text":"b main" }, + { "text": "set $pc=Reset_Handler","ignoreFailures": false } + ] + } + ] +} \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/.vscode/settings.json b/Examples/MAX32655/I2C_EEPROM/.vscode/settings.json new file mode 100644 index 00000000000..5b2da1da924 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.vscode/settings.json @@ -0,0 +1,76 @@ +{ + "terminal.integrated.env.windows": { + "Path":"${config:OCD_path};${config:ARM_GCC_path}/bin;${config:xPack_GCC_path}/bin;${config:Make_path};${env:PATH}", + "MAXIM_PATH":"${config:MAXIM_PATH}" + }, + "terminal.integrated.defaultProfile.windows": "Command Prompt", + + "terminal.integrated.env.linux": { + "PATH":"${config:OCD_path}:${config:ARM_GCC_path}/bin:${config:xPack_GCC_path}/bin:${env:PATH}", + "MAXIM_PATH":"${config:MAXIM_PATH}" + }, + "terminal.integrated.env.osx": { + "PATH":"${config:OCD_path}/bin:${config:ARM_GCC_path}/bin:${config:xPack_GCC_path}/bin:${env:PATH}", + "MAXIM_PATH":"${config:MAXIM_PATH}" + }, + + "target":"MAX32655", + "board":"EvKit_V1", + + "project_name":"${workspaceFolderBasename}", + + "program_file":"${config:project_name}.elf", + "symbol_file":"${config:program_file}", + + "M4_OCD_interface_file":"cmsis-dap.cfg", + "M4_OCD_target_file":"max32655.cfg", + "RV_OCD_interface_file":"ftdi/olimex-arm-usb-ocd-h.cfg", + "RV_OCD_target_file":"${config:target}_riscv.cfg", + + "v_Arm_GCC":"10.3", + "v_xPack_GCC":"12.2.0-3.1", + + "OCD_path":"${config:MAXIM_PATH}/Tools/OpenOCD", + "ARM_GCC_path":"${config:MAXIM_PATH}/Tools/GNUTools/${config:v_Arm_GCC}", + "xPack_GCC_path":"${config:MAXIM_PATH}/Tools/xPack/riscv-none-elf-gcc/${config:v_xPack_GCC}", + "Make_path":"${config:MAXIM_PATH}/Tools/MSYS2/usr/bin", + + "C_Cpp.default.includePath": [ + "${workspaceFolder}", + "${workspaceFolder}/**", + "${config:MAXIM_PATH}/Libraries/Boards/${config:target}/Include", + "${config:MAXIM_PATH}/Libraries/Boards/${config:target}/${config:board}/Include", + "${config:MAXIM_PATH}/Libraries/CMSIS/Device/Maxim/${config:target}/Include", + "${config:MAXIM_PATH}/Libraries/CMSIS/Include", + "${config:ARM_GCC_path}/arm-none-eabi/include", + "${config:ARM_GCC_path}/lib/gcc/arm-none-eabi/${config:v_Arm_GCC}/include", + "${config:MAXIM_PATH}/Libraries/PeriphDrivers/Include/${config:target}", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/Camera", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/Display", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/ExtMemory", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/LED", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/PMIC", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen" + ], + "C_Cpp.default.browse.path": [ + "${workspaceFolder}", + "${config:MAXIM_PATH}/Libraries/Boards/${config:target}/Source", + "${config:MAXIM_PATH}/Libraries/Boards/${config:target}/${config:board}/Source", + "${config:MAXIM_PATH}/Libraries/PeriphDrivers/Source", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/Camera", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/Display", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/LED", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/PMIC", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton", + "${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen", + "${config:MAXIM_PATH}/Libraries/MiscDrivers" + ], + "C_Cpp.default.defines": [ + + ], + "C_Cpp.default.forcedInclude": [ + "${workspaceFolder}/build/project_defines.h" + ] +} + diff --git a/Examples/MAX32655/I2C_EEPROM/.vscode/tasks.json b/Examples/MAX32655/I2C_EEPROM/.vscode/tasks.json new file mode 100644 index 00000000000..e95445e2b3e --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/.vscode/tasks.json @@ -0,0 +1,115 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "make -r -j 8 --output-sync=target --no-print-directory TARGET=${config:target} BOARD=${config:board} MAXIM_PATH=${config:MAXIM_PATH} MAKE=make PROJECT=${config:project_name}", + "osx":{ + "command": "source ~/.zshrc && make -r -j 8 --output-sync=target --no-print-directory TARGET=${config:target} BOARD=${config:board} MAXIM_PATH=${config:MAXIM_PATH} MAKE=make PROJECT=${config:project_name}" + }, + "group": "build", + "problemMatcher": [] + }, + { + "label": "clean", + "type": "shell", + "command": "make -j 8 clean --output-sync=target --no-print-directory TARGET=${config:target} BOARD=${config:board} MAXIM_PATH=${config:MAXIM_PATH} MAKE=make PROJECT=${config:project_name}", + "osx":{ + "command": "source ~/.zshrc && make -j 8 clean --output-sync=target --no-print-directory TARGET=${config:target} BOARD=${config:board} MAXIM_PATH=${config:MAXIM_PATH} MAKE=make PROJECT=${config:project_name}" + }, + "group": "build", + "problemMatcher": [] + }, + { + "label": "clean-periph", + "type": "shell", + "command": "make -j 8 distclean --output-sync=target --no-print-directory TARGET=${config:target} BOARD=${config:board} MAXIM_PATH=${config:MAXIM_PATH} MAKE=make PROJECT=${config:project_name}", + "osx":{ + "command": "source ~/.zshrc && make -j 8 distclean --output-sync=target --no-print-directory TARGET=${config:target} BOARD=${config:board} MAXIM_PATH=${config:MAXIM_PATH} MAKE=make PROJECT=${config:project_name}" + }, + "group": "build", + "problemMatcher": [] + }, + { + "label": "flash", + "type": "shell", + "command": "arm-none-eabi-gdb", + "args": [ + "--cd=\"${workspaceFolder}\"", + "--se=\"build/${config:program_file}\"", + "--symbols=build/${config:symbol_file}", + "-x=\"${workspaceFolder}/.vscode/flash.gdb\"", + "--ex=\"flash_m4 ${config:OCD_path} ${config:M4_OCD_interface_file} ${config:M4_OCD_target_file}\"", + "--batch" + ], + "group": "build", + "problemMatcher": [], + "dependsOn":["build"] + }, + { + "label": "flash & run", + "type": "shell", + "command": "arm-none-eabi-gdb", + "args": [ + "--cd=\"${workspaceFolder}\"", + "--se=\"build/${config:program_file}\"", + "--symbols=build/${config:symbol_file}", + "-x=\"${workspaceFolder}/.vscode/flash.gdb\"", + "--ex=\"flash_m4_run ${config:OCD_path} ${config:M4_OCD_interface_file} ${config:M4_OCD_target_file}\"", + "--batch" + ], + "group": "build", + "problemMatcher": [], + "dependsOn":["build"] + }, + { + "label": "erase flash", + "type": "shell", + "command": "openocd", + "args": [ + "-s", "${config:OCD_path}/scripts", + "-f", "interface/${config:M4_OCD_interface_file}", + "-f", "target/${config:M4_OCD_target_file}", + "-c", "\"init; reset halt; max32xxx mass_erase 0;\"", + "-c", "exit" + ], + "group":"build", + "problemMatcher": [], + "dependsOn":[] + }, + { + "label": "openocd (m4)", + "type": "shell", + "command": "openocd", + "args": [ + "-s", + "${config:OCD_path}/scripts", + "-f", + "interface/${config:M4_OCD_interface_file}", + "-f", + "target/${config:M4_OCD_target_file}", + "-c", + "\"init; reset halt\"" + ], + "problemMatcher": [], + "dependsOn":[] + }, + { + "label": "gdb (m4)", + "type": "shell", + "command": "arm-none-eabi-gdb", + "args": [ + "--ex=\"cd ${workspaceFolder}\"", + "--se=\"build/${config:program_file}\"", + "--symbols=build/${config:symbol_file}", + "--ex=\"target remote localhost:3333\"", + "--ex=\"monitor reset halt\"", + "--ex=\"b main\"", + "--ex=\"c\"" + ], + "problemMatcher": [], + "dependsOn":[] + }, + ] +} \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/I2C_EEPROM.launch b/Examples/MAX32655/I2C_EEPROM/I2C_EEPROM.launch new file mode 100644 index 00000000000..7673785b830 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/I2C_EEPROM.launch @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/MAX32655/I2C_EEPROM/Makefile b/Examples/MAX32655/I2C_EEPROM/Makefile new file mode 100644 index 00000000000..a780185d5f8 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/Makefile @@ -0,0 +1,395 @@ +################################################################################ + # 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. + # +############################################################################### + +# ** Readme! ** +# Don't edit this file! This is the core Makefile for a MaximSDK +# project. The available configuration options can be overridden +# in "project.mk", on the command-line, or with system environment +# variables. + +# See https://analog-devices-msdk.github.io/msdk/USERGUIDE/#build-system +# for more detailed instructions on how to use this system. + +# The detailed instructions mentioned above are easier to read than +# this file, but the comments found in this file also outline the +# available configuration variables. This file is organized into +# sub-sections, some of which expose config variables. + + +# ******************************************************************************* +# Set the target microcontroller and board to compile for. + +# Every TARGET microcontroller has some Board Support Packages (BSPs) that are +# available for it under the MaximSDK/Libraries/Boards/TARGET folder. The BSP +# that gets selected is MaximSDK/Libraries/Boards/TARGET/BOARD. + +# Configuration Variables: +# - TARGET : Override the default target microcontroller. Ex: TARGET=MAX78000 +# - BOARD : Override the default BSP (case sensitive). Ex: BOARD=EvKit_V1, BOARD=FTHR_RevA + + +ifeq "$(TARGET)" "" +# Default target microcontroller +TARGET := MAX32655 +TARGET_UC := MAX32655 +TARGET_LC := max32655 +else +# "TARGET" has been overridden in the environment or on the command-line. +# We need to calculate an upper and lowercase version of the part number, +# because paths on Linux and MacOS are case-sensitive. +TARGET_UC := $(subst m,M,$(subst a,A,$(subst x,X,$(TARGET)))) +TARGET_LC := $(subst M,m,$(subst A,a,$(subst X,x,$(TARGET)))) +endif + +# Default board. +BOARD ?= EvKit_V1 + +# ******************************************************************************* +# Locate the MaximSDK + +# This Makefile needs to know where to find the MaximSDK, and the MAXIM_PATH variable +# should point to the root directory of the MaximSDK installation. Setting this manually +# is usually only required if you're working on the command-line. + +# If MAXIM_PATH is not specified, we assume the project still lives inside of the MaximSDK +# and move up from this project's original location. + +# Configuration Variables: +# - MAXIM_PATH : Tell this Makefile where to find the MaximSDK. Ex: MAXIM_PATH=C:/MaximSDK + + +ifneq "$(MAXIM_PATH)" "" +# Sanitize MAXIM_PATH for backslashes +MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) +# Locate some other useful paths... +LIBS_DIR := $(abspath $(MAXIM_PATH)/Libraries) +CMSIS_ROOT := $(LIBS_DIR)/CMSIS +endif + +# ******************************************************************************* +# Include project Makefile. We do this after formulating TARGET, BOARD, and MAXIM_PATH +# in case project.mk needs to reference those values. However, we also include +# this as early as possible in the Makefile so that it can append to or override +# the variables below. + + +PROJECTMK ?= $(abspath ./project.mk) +include $(PROJECTMK) +$(info Loaded project.mk) +# PROJECTMK is also used by implicit rules and other libraries to add project.mk as a watch file + +# ******************************************************************************* +# Final path sanitization and re-calculation. No options here. + +ifeq "$(MAXIM_PATH)" "" +# MAXIM_PATH is still not defined... +DEPTH := ../../../ +MAXIM_PATH := $(abspath $(DEPTH)) +$(warning Warning: MAXIM_PATH is not set! Set MAXIM_PATH in your environment or in project.mk to clear this warning.) +$(warning Warning: Attempting to use $(MAXIM_PATH) calculated from relative path) +else +# Sanitize MAXIM_PATH for backslashes +MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) +endif + +# Final recalculation of LIBS_DIR/CMSIS_ROOT +LIBS_DIR := $(abspath $(MAXIM_PATH)/Libraries) +CMSIS_ROOT := $(LIBS_DIR)/CMSIS + +# One final UC/LC check in case user set TARGET in project.mk +TARGET_UC := $(subst m,M,$(subst a,A,$(subst x,X,$(TARGET)))) +TARGET_LC := $(subst M,m,$(subst A,a,$(subst X,x,$(TARGET)))) + +export TARGET +export TARGET_UC +export TARGET_LC +export CMSIS_ROOT +# TODO: Remove dependency on exports for these variables. + +# ******************************************************************************* +# Set up search paths, and auto-detect all source code on those paths. + +# The following paths are searched by default, where "./" is the project directory. +# ./ +# |- *.h +# |- *.c +# |-include (optional) +# |- *.h +# |-src (optional) +# |- *.c + +# Configuration Variables: +# - VPATH : Tell this Makefile to search additional locations for source (.c) files. +# You should use the "+=" operator with this option. +# Ex: VPATH += your/new/path +# - IPATH : Tell this Makefile to search additional locations for header (.h) files. +# You should use the "+=" operator with this option. +# Ex: VPATH += your/new/path +# - SRCS : Tell this Makefile to explicitly add a source (.c) file to the build. +# This is really only useful if you want to add a source file that isn't +# on any VPATH, in which case you can add the full path to the file here. +# You should use the "+=" operator with this option. +# Ex: SRCS += your/specific/source/file.c +# - AUTOSEARCH : Set whether this Makefile should automatically detect .c files on +# VPATH and add them to the build. This is enabled by default. Set +# to 0 to disable. If autosearch is disabled, source files must be +# manually added to SRCS. +# Ex: AUTOSEARCH = 0 + + +# Where to find source files for this project. +VPATH += . +VPATH += src +VPATH := $(VPATH) + +# Where to find header files for this project +IPATH += . +IPATH += include +IPATH := $(IPATH) + +AUTOSEARCH ?= 1 +ifeq ($(AUTOSEARCH), 1) +# Auto-detect all C/C++ source files on VPATH +SRCS += $(wildcard $(addsuffix /*.c, $(VPATH))) +SRCS += $(wildcard $(addsuffix /*.cpp, $(VPATH))) +endif + +# Collapse SRCS before passing them on to the next stage +SRCS := $(SRCS) + +# ******************************************************************************* +# Set the output filename + +# Configuration Variables: +# - PROJECT : Override the default output filename. Ex: PROJECT=MyProject + + +# The default value creates a file named after the target micro. Ex: MAX78000.elf +PROJECT ?= $(TARGET_LC) + +# ******************************************************************************* +# Compiler options + +# Configuration Variables: +# - DEBUG : Set DEBUG=1 to build explicitly for debugging. This adds some additional +# symbols and sets -Og as the default optimization level. +# - MXC_OPTIMIZE_CFLAGS : Override the default compiler optimization level. +# Ex: MXC_OPTIMIZE_CFLAGS = -O2 +# - PROJ_CFLAGS : Add additional compiler flags to the build. +# You should use the "+=" operator with this option. +# Ex: PROJ_CFLAGS += -Wextra +# - MFLOAT_ABI : Set the floating point acceleration level. +# The only options are "hard", "soft", or "softfp". +# Ex: MFLOAT_ABI = hard +# - LINKERFILE : Override the default linkerfile. +# Ex: LINKERFILE = customlinkerfile.ld +# - LINKERPATH : Override the default search location for $(LINKERFILE) +# The default search location is $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC +# If $(LINKERFILE) cannot be found at this path, then the root project +# directory will be used as a fallback. + +# Select 'GCC' or 'IAR' compiler +ifeq "$(COMPILER)" "" +COMPILER := GCC +endif + +# Set default compiler optimization levels +ifeq "$(MAKECMDGOALS)" "release" +# Default optimization level for "release" builds (make release) +MXC_OPTIMIZE_CFLAGS ?= -O2 +DEBUG = 0 +endif + +ifeq ($(DEBUG),1) +# Optimizes for debugging as recommended +# by GNU for code-edit-debug cycles +# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options +MXC_OPTIMIZE_CFLAGS := -Og +endif + +# Default level if not building for release or explicitly for debug +MXC_OPTIMIZE_CFLAGS ?= -Og + +# Set compiler flags +PROJ_CFLAGS += -Wall # Enable warnings +PROJ_CFLAGS += -DMXC_ASSERT_ENABLE + +# Set hardware floating point acceleration. +# Options are: +# - hard +# - soft +# - softfp (default if MFLOAT_ABI is not set) +MFLOAT_ABI ?= softfp +# MFLOAT_ABI must be exported to other Makefiles +export MFLOAT_ABI + +# This path contains system-level intialization files for the target micro. Add to the build. +VPATH += $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source + +# ******************************************************************************* +# Secure Boot Tools (SBT) + +# This section integrates the Secure Boot Tools. It's intended for use with +# microcontrollers that have a secure bootloader. + +# Enabling SBT integration will add some special rules, such as "make sla", "make scpa", etc. + +# Configuration variables: +# SBT : Toggle SBT integration. Set to 1 to enable, or 0 +# to disable +# MAXIM_SBT_DIR : Specify the location of the SBT tool binaries. This defaults to +# Tools/SBT in the MaximSDK. The standalone SBT installer will override +# this via an environment variable. +# TARGET_SEC : Specify the part number to be passed into the SBT. This should match +# the secure variant part #. The default value will depend on TARGET. +# For example, TARGET=MAX32650 will result in TARGET_SEC=MAX32651, and +# the default selection happens in Tools/SBT/SBT-config. +# However, if there are multiple secure part #s for the target +# microcontroller this variable may need to be changed. + +SBT ?= 0 +ifeq ($(SBT), 1) +MAXIM_SBT_DIR ?= $(MAXIM_PATH)/Tools/SBT +MAXIM_SBT_DIR := $(subst \,/,$(MAXIM_SBT_DIR)) +# ^ Must sanitize path for \ on Windows, since this may come from an environment +# variable. + +export MAXIM_SBT_DIR # SBTs must have this environment variable defined to work + +# SBT-config.mk and SBT-rules.mk are included further down this Makefile. + +endif # SBT + +# ******************************************************************************* +# Default goal selection. This section allows you to override the default goal +# that will run if no targets are specified on the command-line. +# (ie. just running 'make' instead of 'make all') + +# Configuration variables: +# .DEFAULT_GOAL : Set the default goal if no targets were specified on the +# command-line +# ** "override" must be used with this variable. ** +# Ex: "override .DEFAULT_GOAL = mygoal" + +ifeq "$(.DEFAULT_GOAL)" "" +ifeq ($(SBT),1) +override .DEFAULT_GOAL := sla +else +override .DEFAULT_GOAL := all +endif +endif + +# Developer note: 'override' is used above for legacy Makefile compatibility. +# gcc.mk/gcc_riscv.mk need to hard-set 'all' internally, so this new system +# uses 'override' to come in over the top without breaking old projects. + +# It's also necessary to explicitly set MAKECMDGOALS... +ifeq "$(MAKECMDGOALS)" "" +MAKECMDGOALS:=$(.DEFAULT_GOAL) +endif + +# Enable colors when --sync-output is used. +# See https://www.gnu.org/software/make/manual/make.html#Terminal-Output (section 13.2) +ifneq ($(MAKE_TERMOUT),) +PROJ_CFLAGS += -fdiagnostics-color=always +endif + +ifneq ($(FORCE_COLOR),) +PROJ_CFLAGS += -fdiagnostics-color=always +endif + +# ******************************************************************************* +# Include SBT config. We need to do this here because it needs to know +# the current MAKECMDGOAL. +ifeq ($(SBT),1) +include $(MAXIM_PATH)/Tools/SBT/SBT-config.mk +endif + +# ******************************************************************************* +# Libraries + +# This section offers "toggle switches" to include or exclude the libraries that +# are available in the MaximSDK. Set a configuration variable to 1 to include the +# library in the build, or 0 to exclude. + +# Each library may also have its own library specific configuration variables. See +# Libraries/libs.mk for more details. + +# Configuration variables: +# - LIB_BOARD : Include the Board-Support Package (BSP) library. (Enabled by default) +# - LIB_PERIPHDRIVERS : Include the peripheral driver library. (Enabled by default) +# - LIB_CMSIS_DSP : Include the CMSIS-DSP library. +# - LIB_CORDIO : Include the Cordio BLE library +# - LIB_FCL : Include the Free Cryptographic Library (FCL) +# - LIB_FREERTOS : Include the FreeRTOS and FreeRTOS-Plus-CLI libraries +# - LIB_LC3 : Include the Low Complexity Communication Codec (LC3) library +# - LIB_LITTLEFS : Include the "little file system" (littleFS) library +# - LIB_LWIP : Include the lwIP library +# - LIB_MAXUSB : Include the MAXUSB library +# - LIB_SDHC : Include the SDHC library + +include $(LIBS_DIR)/libs.mk + + +# ******************************************************************************* +# Rules + +# Include the rules for building for this target. All other makefiles should be +# included before this one. +include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk + +# Include the rules that integrate the SBTs. SBTs are a special case that must be +# include after the core gcc rules to extend them. +ifeq ($(SBT), 1) +include $(MAXIM_PATH)/Tools/SBT/SBT-rules.mk +endif + + +# Get .DEFAULT_GOAL working. +ifeq "$(MAKECMDGOALS)" "" +MAKECMDGOALS:=$(.DEFAULT_GOAL) +endif + + +all: +# Extend the functionality of the "all" recipe here + arm-none-eabi-size --format=berkeley $(BUILD_DIR)/$(PROJECT).elf + +libclean: + $(MAKE) -f ${PERIPH_DRIVER_DIR}/periphdriver.mk clean.periph + +clean: +# Extend the functionality of the "clean" recipe here + +# The rule to clean out all the build products. +distclean: clean libclean diff --git a/Examples/MAX32655/I2C_EEPROM/README.md b/Examples/MAX32655/I2C_EEPROM/README.md new file mode 100644 index 00000000000..d05629cbd94 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/README.md @@ -0,0 +1,75 @@ +## Description + +This example communicates with an external 24LC256 EEPROM using the I2C. +One 24LC256 EEPROM is required to implement this example. + + +## Software + +### Project Usage + +Universal instructions on building, flashing, and debugging this project can be found in the **[MSDK User Guide](https://analog-devices-msdk.github.io/msdk/USERGUIDE/)**. + +### Project-Specific Build Notes + +* This project comes pre-configured for the MAX32655EVKIT. See [Board Support Packages](https://analog-devices-msdk.github.io/msdk/USERGUIDE/#board-support-packages) in the MSDK User Guide for instructions on changing the target board. + +## Required Connections + +- Connect a USB cable between the PC and the CN1 (USB/PWR) connector. +- Select RX0 and TX0 on Headers JP4 and JP5 (UART 0). +- Open an terminal application on the PC and connect to the EV kit's console UART at 115200, 8-N-1. +- Connect JP9 (VDDIOH_EN) btw 2-3(3.3V) and JP10 (VDDIOH) jumpers for powering VDDIOH with 3.3V +- Connect the pull-up jumper (JP22) to VDDIOH +- Connect 24LC256 pin 4(VSS) to GND of EVKIT +- Connect 24LC256 pin 8(VDD) to VDDIOH of EVKIT +- Connect 24LC256 pin 6(SCL) to P0.16 (SCL) of EVKIT +- Connect 24LC256 pin 5(SDA) to P0.17 (SDA) of EVKIT +- Connect 24LC256 pin 7(WP) to GND of EVKIT. This enables write operation. +- Connect 24LC256 pin 1(A0), pin 2(A1), ,pin 3(A2) to GND of EVKIT. This makes the I2C Slave address 0x50. Slave address calculated as: 1010(A2)(A1)(A0) + +## Expected Output + +``` + +****************** 24LC256 EEPROM DEMO ******************* + +This example communicates with an external 24LC256 EEPROM using the I2C. +One 24LC256 EEPROM is required to implement this example. +Press ENTER key to Continue + +EEPROM DEMO - Test 1: Writing and reading 1 byte: + +The value: 0x00 is written to the address: 0x0000 +The value: 0x00 is read from the address: 0x0000 +The value: 0x01 is written to the address: 0x0001 +The value: 0x01 is read from the address: 0x0001 +The value: 0x02 is written to the address: 0x0002 +The value: 0x02 is read from the address: 0x0002 +The value: 0x03 is written to the address: 0x0003 +The value: 0x03 is read from the address: 0x0003 +The value: 0x04 is written to the address: 0x0004 +The value: 0x04 is read from the address: 0x0004 + +EEPROM DEMO - Test2: Writing and Reading 256 Bytes: + +256 Bytes written to the EEPROM starting from the address: 0x0000. Each page (64 byte) filled with its own page number. + +256 bytes bytes read from the memory. The start address: 0x0000. The values read: +Page 0: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +Page 1: 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +Page 2: 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, +Page 3: 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + +EEPROM DEMO - Test 3: Write and read test for writing multiple pages starting from random adress(not page start): + +Test size : 80 Bytes +Test value : 0xA5 +Test start address : 0x003A +The value: 0xA5 is written to EEPROM for 80 Bytes starting from the address: 0x003A + +80 bytes read from the memory. The start address: 0x003A. The values read: +0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, + +... +``` \ No newline at end of file diff --git a/Examples/MAX32655/I2C_EEPROM/main.c b/Examples/MAX32655/I2C_EEPROM/main.c new file mode 100644 index 00000000000..dde948cf555 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/main.c @@ -0,0 +1,192 @@ +/** + * @file main.c + * @brief 24LC256 EEPROM I2C Communication Example + * @details This example uses the I2C Master to read/write from/to the EEPROM. + */ + +/****************************************************************************** + * 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. + * + ******************************************************************************/ + +/***** Includes *****/ +#include +#include +#include + +#include "i2c.h" +#include "mxc_device.h" + +#include "eeprom_24lc256_driver.h" + +/***** Definitions *****/ +#define I2C_MASTER MXC_I2C1 ///< I2C instance +#define I2C_FREQ 100000 ///< I2C clock frequency + +#define EEPROM_24LC256_I2C_SLAVE_ADDR0 0x50//(0xA0 >> 1) + +#define EEPROM_DEMO_BUFFER_PAGE_COUNT 4 +#define EEPROM_DEMO_BUFFER_SIZE _24LC256_EEPROM_PAGE_SIZE * EEPROM_DEMO_BUFFER_PAGE_COUNT // Bytes +// ***************************************************************************** + +int main(void) +{ + int err = E_NO_ERROR; + int i = 0, j = 0; + uint16_t eeprom_memory_addr = 0x0000; + uint8_t written_val = 0; + uint8_t readed_val = 0; + uint8_t eeprom_demo_buffer[EEPROM_DEMO_BUFFER_SIZE]; + uint32_t page_offset = 0; + + printf("\n****************** 24LC256 EEPROM DEMO *******************\n\n"); + printf("This example communicates with an external 24LC256 EEPROM using the I2C.\n"); + printf("One 24LC256 EEPROM is required to implement this example.\n"); + printf("Press ENTER key to Continue\n\n"); + getchar(); + + err = MXC_I2C_Init(I2C_MASTER, 1, 0); + if (err != E_NO_ERROR) { + printf("EEPROM configure failed with error %i\n", err); + return err; + } + + MXC_I2C_SetFrequency(I2C_MASTER, I2C_FREQ); + + eeprom_24LC256_driver_t eeprom_24LC256 = eeprom_24LC256_Open(); + + eeprom_24LC256.init(I2C_MASTER, EEPROM_24LC256_I2C_SLAVE_ADDR0); // init the EEPROM + + printf("EEPROM DEMO - Test 1: Writing and reading 1 byte:\n\n"); + for(i = 0; i < 5; i++) + { + err = eeprom_24LC256.write(eeprom_memory_addr, &written_val, 1); + if (err != E_NO_ERROR) { + printf("EEPROM write error, error code = %d\n", err); + }else{ + printf("The value: 0x%02X is written to the address: 0x%04X\n", written_val, eeprom_memory_addr); + } + err = eeprom_24LC256.read(eeprom_memory_addr, &readed_val, 1); + if (err != E_NO_ERROR) { + printf("EEPROM read error, error code = %d\n", err); + }else{ + printf("The value: 0x%02X is read from the address: 0x%04X\n", readed_val, eeprom_memory_addr); + } + if(readed_val != written_val){ + printf("EEPROM error; written and read values are different\n", readed_val, eeprom_memory_addr); + } + + written_val++; + eeprom_memory_addr++; + } + + printf("\nEEPROM DEMO - Test2: Writing and Reading %d Bytes:\n\n", EEPROM_DEMO_BUFFER_SIZE); + eeprom_memory_addr = 0x0000; + page_offset = eeprom_memory_addr / _24LC256_EEPROM_PAGE_SIZE; + + for(i = 0; i < EEPROM_DEMO_BUFFER_PAGE_COUNT; i++) + { + for(j = 0; j < _24LC256_EEPROM_PAGE_SIZE; j++) + { + eeprom_demo_buffer[i*_24LC256_EEPROM_PAGE_SIZE + j] = i; + } + } + + err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); + if (err != E_NO_ERROR) { + printf("EEPROM write error, error code = %d\n", err); + }else{ + printf("%d Bytes written to the EEPROM starting from the address: 0x%04X. Each page (64 byte) filled with its own page number.\n", EEPROM_DEMO_BUFFER_SIZE, eeprom_memory_addr); + } + + for(i = 0; i < EEPROM_DEMO_BUFFER_SIZE; i++) + { + eeprom_demo_buffer[i] = 0; + } + + err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); + if (err != E_NO_ERROR) { + printf("EEPROM read %d bytes error, error code = %d\n", EEPROM_DEMO_BUFFER_SIZE, err); + }else{ + printf("\n%d bytes bytes read from the memory. The start address: 0x%04X. The values read: ", EEPROM_DEMO_BUFFER_SIZE, eeprom_memory_addr); + for(i = 0; i < EEPROM_DEMO_BUFFER_SIZE; i++) + { + if(i % _24LC256_EEPROM_PAGE_SIZE == 0) + { + printf("\nPage %4d: ", (i/_24LC256_EEPROM_PAGE_SIZE + page_offset)); + } + printf("0x%02X, ", eeprom_demo_buffer[i]); + + } + printf("\n"); + } + + printf("\nEEPROM DEMO - Test 3: Write and read test for writing multiple pages starting from random adress(not page start):\n\n"); + + uint32_t test_size = 80; + uint16_t test_val = 0xA5; + eeprom_memory_addr = 0x003A; + + printf("Test size : %d Bytes \n", test_size); + printf("Test value : 0x%02X \n", test_val); + printf("Test start address : 0x%04X \n", eeprom_memory_addr); + + for(i = 0; i < test_size; i++) + { + eeprom_demo_buffer[i] = test_val; + } + + err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); + if (err != E_NO_ERROR) { + printf("EEPROM write error, error code = %d\n", err); + }else{ + printf("The value: 0x%02X is written to EEPROM for %d Bytes starting from the address: 0x%04X\n", test_val, test_size, eeprom_memory_addr); + } + + for(i = 0; i < test_size; i++) + { + eeprom_demo_buffer[i] = 0; + } + + err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); + if (err != E_NO_ERROR) { + printf("EEPROM read error, error code = %d\n", err); + }else{ + printf("\n%d bytes read from the memory. The start address: 0x%04X. The values read: \n", test_size, eeprom_memory_addr); + for(i = 0; i < test_size; i++) + { + printf("0x%02X, ", eeprom_demo_buffer[i]); + } + printf("\n"); + } + + return E_NO_ERROR; +} diff --git a/Examples/MAX32655/I2C_EEPROM/project.mk b/Examples/MAX32655/I2C_EEPROM/project.mk new file mode 100644 index 00000000000..334e3cd8217 --- /dev/null +++ b/Examples/MAX32655/I2C_EEPROM/project.mk @@ -0,0 +1,16 @@ +# This file can be used to set build configuration +# variables. These variables are defined in a file called +# "Makefile" that is located next to this one. + +# For instructions on how to use this system, see +# https://analog-devices-msdk.github.io/msdk/USERGUIDE/#build-system + +# ********************************************************** + +# Add your config here! + + +SRCS+=eeprom_24lc256_driver.c + +VPATH+=$(LIBS_DIR)/MiscDrivers/EEPROM +IPATH+=$(LIBS_DIR)/MiscDrivers/EEPROM From cc82860ea7bd575cc974ed1645660e4bffc75d32 Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Wed, 4 Oct 2023 09:45:43 +0300 Subject: [PATCH 3/7] 24LC256 EEPROM driver added. 24LC256 EEPROM example for Max32655 EVKIT added. clang format fixes implemented. --- Examples/MAX32655/I2C_EEPROM/main.c | 179 ++++++++--------- .../EEPROM/eeprom_24lc256_driver.c | 183 +++++++++--------- .../EEPROM/eeprom_24lc256_driver.h | 9 +- 3 files changed, 183 insertions(+), 188 deletions(-) diff --git a/Examples/MAX32655/I2C_EEPROM/main.c b/Examples/MAX32655/I2C_EEPROM/main.c index dde948cf555..308c7ea5d2a 100644 --- a/Examples/MAX32655/I2C_EEPROM/main.c +++ b/Examples/MAX32655/I2C_EEPROM/main.c @@ -51,21 +51,21 @@ #define I2C_MASTER MXC_I2C1 ///< I2C instance #define I2C_FREQ 100000 ///< I2C clock frequency -#define EEPROM_24LC256_I2C_SLAVE_ADDR0 0x50//(0xA0 >> 1) +#define EEPROM_24LC256_I2C_SLAVE_ADDR0 0x50 //(0xA0 >> 1) -#define EEPROM_DEMO_BUFFER_PAGE_COUNT 4 -#define EEPROM_DEMO_BUFFER_SIZE _24LC256_EEPROM_PAGE_SIZE * EEPROM_DEMO_BUFFER_PAGE_COUNT // Bytes +#define EEPROM_DEMO_BUFFER_PAGE_COUNT 4 +#define EEPROM_DEMO_BUFFER_SIZE _24LC256_EEPROM_PAGE_SIZE *EEPROM_DEMO_BUFFER_PAGE_COUNT // Bytes // ***************************************************************************** int main(void) { int err = E_NO_ERROR; int i = 0, j = 0; - uint16_t eeprom_memory_addr = 0x0000; - uint8_t written_val = 0; - uint8_t readed_val = 0; - uint8_t eeprom_demo_buffer[EEPROM_DEMO_BUFFER_SIZE]; - uint32_t page_offset = 0; + uint16_t eeprom_memory_addr = 0x0000; + uint8_t written_val = 0; + uint8_t readed_val = 0; + uint8_t eeprom_demo_buffer[EEPROM_DEMO_BUFFER_SIZE]; + uint32_t page_offset = 0; printf("\n****************** 24LC256 EEPROM DEMO *******************\n\n"); printf("This example communicates with an external 24LC256 EEPROM using the I2C.\n"); @@ -86,107 +86,108 @@ int main(void) eeprom_24LC256.init(I2C_MASTER, EEPROM_24LC256_I2C_SLAVE_ADDR0); // init the EEPROM printf("EEPROM DEMO - Test 1: Writing and reading 1 byte:\n\n"); - for(i = 0; i < 5; i++) - { - err = eeprom_24LC256.write(eeprom_memory_addr, &written_val, 1); - if (err != E_NO_ERROR) { - printf("EEPROM write error, error code = %d\n", err); - }else{ - printf("The value: 0x%02X is written to the address: 0x%04X\n", written_val, eeprom_memory_addr); - } - err = eeprom_24LC256.read(eeprom_memory_addr, &readed_val, 1); - if (err != E_NO_ERROR) { - printf("EEPROM read error, error code = %d\n", err); - }else{ - printf("The value: 0x%02X is read from the address: 0x%04X\n", readed_val, eeprom_memory_addr); - } - if(readed_val != written_val){ - printf("EEPROM error; written and read values are different\n", readed_val, eeprom_memory_addr); - } - - written_val++; - eeprom_memory_addr++; - } + for (i = 0; i < 5; i++) { + err = eeprom_24LC256.write(eeprom_memory_addr, &written_val, 1); + if (err != E_NO_ERROR) { + printf("EEPROM write error, error code = %d\n", err); + } else { + printf("The value: 0x%02X is written to the address: 0x%04X\n", written_val, + eeprom_memory_addr); + } + err = eeprom_24LC256.read(eeprom_memory_addr, &readed_val, 1); + if (err != E_NO_ERROR) { + printf("EEPROM read error, error code = %d\n", err); + } else { + printf("The value: 0x%02X is read from the address: 0x%04X\n", readed_val, + eeprom_memory_addr); + } + if (readed_val != written_val) { + printf("EEPROM error; written and read values are different\n", readed_val, + eeprom_memory_addr); + } + + written_val++; + eeprom_memory_addr++; + } printf("\nEEPROM DEMO - Test2: Writing and Reading %d Bytes:\n\n", EEPROM_DEMO_BUFFER_SIZE); eeprom_memory_addr = 0x0000; page_offset = eeprom_memory_addr / _24LC256_EEPROM_PAGE_SIZE; - for(i = 0; i < EEPROM_DEMO_BUFFER_PAGE_COUNT; i++) - { - for(j = 0; j < _24LC256_EEPROM_PAGE_SIZE; j++) - { - eeprom_demo_buffer[i*_24LC256_EEPROM_PAGE_SIZE + j] = i; + for (i = 0; i < EEPROM_DEMO_BUFFER_PAGE_COUNT; i++) { + for (j = 0; j < _24LC256_EEPROM_PAGE_SIZE; j++) { + eeprom_demo_buffer[i * _24LC256_EEPROM_PAGE_SIZE + j] = i; } } - err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); - if (err != E_NO_ERROR) { - printf("EEPROM write error, error code = %d\n", err); - }else{ - printf("%d Bytes written to the EEPROM starting from the address: 0x%04X. Each page (64 byte) filled with its own page number.\n", EEPROM_DEMO_BUFFER_SIZE, eeprom_memory_addr); - } + err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); + if (err != E_NO_ERROR) { + printf("EEPROM write error, error code = %d\n", err); + } else { + printf( + "%d Bytes written to the EEPROM starting from the address: 0x%04X. Each page (64 byte) filled with its own page number.\n", + EEPROM_DEMO_BUFFER_SIZE, eeprom_memory_addr); + } - for(i = 0; i < EEPROM_DEMO_BUFFER_SIZE; i++) - { - eeprom_demo_buffer[i] = 0; + for (i = 0; i < EEPROM_DEMO_BUFFER_SIZE; i++) { + eeprom_demo_buffer[i] = 0; } err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); - if (err != E_NO_ERROR) { - printf("EEPROM read %d bytes error, error code = %d\n", EEPROM_DEMO_BUFFER_SIZE, err); - }else{ - printf("\n%d bytes bytes read from the memory. The start address: 0x%04X. The values read: ", EEPROM_DEMO_BUFFER_SIZE, eeprom_memory_addr); - for(i = 0; i < EEPROM_DEMO_BUFFER_SIZE; i++) - { - if(i % _24LC256_EEPROM_PAGE_SIZE == 0) - { - printf("\nPage %4d: ", (i/_24LC256_EEPROM_PAGE_SIZE + page_offset)); - } - printf("0x%02X, ", eeprom_demo_buffer[i]); - - } - printf("\n"); - } - - printf("\nEEPROM DEMO - Test 3: Write and read test for writing multiple pages starting from random adress(not page start):\n\n"); - - uint32_t test_size = 80; - uint16_t test_val = 0xA5; + if (err != E_NO_ERROR) { + printf("EEPROM read %d bytes error, error code = %d\n", EEPROM_DEMO_BUFFER_SIZE, err); + } else { + printf( + "\n%d bytes bytes read from the memory. The start address: 0x%04X. The values read: ", + EEPROM_DEMO_BUFFER_SIZE, eeprom_memory_addr); + for (i = 0; i < EEPROM_DEMO_BUFFER_SIZE; i++) { + if (i % _24LC256_EEPROM_PAGE_SIZE == 0) { + printf("\nPage %4d: ", (i / _24LC256_EEPROM_PAGE_SIZE + page_offset)); + } + printf("0x%02X, ", eeprom_demo_buffer[i]); + } + printf("\n"); + } + + printf( + "\nEEPROM DEMO - Test 3: Write and read test for writing multiple pages starting from random adress(not page start):\n\n"); + + uint32_t test_size = 80; + uint16_t test_val = 0xA5; eeprom_memory_addr = 0x003A; - printf("Test size : %d Bytes \n", test_size); - printf("Test value : 0x%02X \n", test_val); - printf("Test start address : 0x%04X \n", eeprom_memory_addr); + printf("Test size : %d Bytes \n", test_size); + printf("Test value : 0x%02X \n", test_val); + printf("Test start address : 0x%04X \n", eeprom_memory_addr); - for(i = 0; i < test_size; i++) - { - eeprom_demo_buffer[i] = test_val; + for (i = 0; i < test_size; i++) { + eeprom_demo_buffer[i] = test_val; } - err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); - if (err != E_NO_ERROR) { - printf("EEPROM write error, error code = %d\n", err); - }else{ - printf("The value: 0x%02X is written to EEPROM for %d Bytes starting from the address: 0x%04X\n", test_val, test_size, eeprom_memory_addr); - } + err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); + if (err != E_NO_ERROR) { + printf("EEPROM write error, error code = %d\n", err); + } else { + printf( + "The value: 0x%02X is written to EEPROM for %d Bytes starting from the address: 0x%04X\n", + test_val, test_size, eeprom_memory_addr); + } - for(i = 0; i < test_size; i++) - { - eeprom_demo_buffer[i] = 0; + for (i = 0; i < test_size; i++) { + eeprom_demo_buffer[i] = 0; } - err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); - if (err != E_NO_ERROR) { - printf("EEPROM read error, error code = %d\n", err); - }else{ - printf("\n%d bytes read from the memory. The start address: 0x%04X. The values read: \n", test_size, eeprom_memory_addr); - for(i = 0; i < test_size; i++) - { - printf("0x%02X, ", eeprom_demo_buffer[i]); - } - printf("\n"); - } + err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); + if (err != E_NO_ERROR) { + printf("EEPROM read error, error code = %d\n", err); + } else { + printf("\n%d bytes read from the memory. The start address: 0x%04X. The values read: \n", + test_size, eeprom_memory_addr); + for (i = 0; i < test_size; i++) { + printf("0x%02X, ", eeprom_demo_buffer[i]); + } + printf("\n"); + } return E_NO_ERROR; } diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c index 9499aec6f2e..d488e2f0c34 100644 --- a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c @@ -86,47 +86,43 @@ static int eeprom_24LC256_init(mxc_i2c_regs_t *i2c, uint8_t addr) * @returns #E_NO_ERROR if read succeeded. non-zero if an error occurred. * */ -static int eeprom_24LC256_read(uint16_t addr, uint8_t* data_buffer, uint16_t length) +static int eeprom_24LC256_read(uint16_t addr, uint8_t *data_buffer, uint16_t length) { int err = E_NO_ERROR; uint16_t remaining = length; - uint8_t* current_data_buffer = data_buffer; + uint8_t *current_data_buffer = data_buffer; uint16_t eeprom_addr_to_read = addr; - uint8_t send_buffer[2] = { 0x00, 0x00}; + uint8_t send_buffer[2] = { 0x00, 0x00 }; - if(addr + length > _24LC256_EEPROM_SIZE) - { - return E_BAD_PARAM; + if (addr + length > _24LC256_EEPROM_SIZE) { + return E_BAD_PARAM; } - while(remaining) - { - if(remaining <= I2C_MAX_READ_SIZE) - { - send_buffer[0] = eeprom_addr_to_read >> 8; - send_buffer[1] = (eeprom_addr_to_read & 0x00FF); - - // Read - err = i2c_read(&req, send_buffer, current_data_buffer, remaining); - if (err != E_NO_ERROR) { - return err; - }else{ - remaining = 0; - } - }else - { - send_buffer[0] = eeprom_addr_to_read >> 8; - send_buffer[1] = (eeprom_addr_to_read & 0x00FF); - - // Read - err = i2c_read(&req, send_buffer, current_data_buffer, I2C_MAX_READ_SIZE); - if (err != E_NO_ERROR) { - return err; - } - remaining -= I2C_MAX_READ_SIZE; - current_data_buffer += I2C_MAX_READ_SIZE; - eeprom_addr_to_read += I2C_MAX_READ_SIZE; - } + while (remaining) { + if (remaining <= I2C_MAX_READ_SIZE) { + send_buffer[0] = eeprom_addr_to_read >> 8; + send_buffer[1] = (eeprom_addr_to_read & 0x00FF); + + // Read + err = i2c_read(&req, send_buffer, current_data_buffer, remaining); + if (err != E_NO_ERROR) { + return err; + } else { + remaining = 0; + } + } else { + send_buffer[0] = eeprom_addr_to_read >> 8; + send_buffer[1] = (eeprom_addr_to_read & 0x00FF); + + // Read + err = i2c_read(&req, send_buffer, current_data_buffer, I2C_MAX_READ_SIZE); + if (err != E_NO_ERROR) { + return err; + } + remaining -= I2C_MAX_READ_SIZE; + current_data_buffer += I2C_MAX_READ_SIZE; + eeprom_addr_to_read += I2C_MAX_READ_SIZE; + } } return E_NO_ERROR; } @@ -139,24 +135,23 @@ static int eeprom_24LC256_read(uint16_t addr, uint8_t* data_buffer, uint16_t len * @returns #E_NO_ERROR if write succeeded. non-zero if an error occurred. * */ -static int eeprom_24LC256_write_chunk(uint16_t addr, uint8_t* data_buffer, uint16_t length) +static int eeprom_24LC256_write_chunk(uint16_t addr, uint8_t *data_buffer, uint16_t length) { int err = E_NO_ERROR; int i = 0; - uint8_t send_buffer[66]; // Max write length is equal to page size (64 bytes). So, max buffer size 64 + 2 bytes + uint8_t send_buffer[66]; // Page size (64) + 2 bytes send_buffer[0] = addr >> 8; send_buffer[1] = (addr & 0x00FF); - for(i = 0; i < length; i++) - { - send_buffer[i+2] = data_buffer[i]; + for (i = 0; i < length; i++) { + send_buffer[i + 2] = data_buffer[i]; } - // Write - err = i2c_write(&req, send_buffer, (length + 2)); - if (err != E_NO_ERROR) { - return err; - } - return E_NO_ERROR; + // Write + err = i2c_write(&req, send_buffer, (length + 2)); + if (err != E_NO_ERROR) { + return err; + } + return E_NO_ERROR; } /** @@ -167,74 +162,74 @@ static int eeprom_24LC256_write_chunk(uint16_t addr, uint8_t* data_buffer, uint1 * @returns #E_NO_ERROR if write succeeded. non-zero if an error occurred. * */ -static int eeprom_24LC256_write(uint16_t addr, uint8_t* data_buffer, uint32_t length) +static int eeprom_24LC256_write(uint16_t addr, uint8_t *data_buffer, uint32_t length) { int err = E_NO_ERROR; uint16_t remaining_data_length_to_write = length; uint16_t remaining_size_until_page_end = 0; - uint8_t* current_data_buffer = data_buffer; + uint8_t *current_data_buffer = data_buffer; uint16_t eeprom_addr_to_write = addr; - if(addr + length > _24LC256_EEPROM_SIZE) - { - return E_BAD_PARAM; + if (addr + length > _24LC256_EEPROM_SIZE) { + return E_BAD_PARAM; } // EEPROM does not support writing to multiple pages simultaneously // In fist operation, if we are not writing to start of a page, we should write until the end of that page. - if((addr % _24LC256_EEPROM_PAGE_SIZE) != 0) // If starting address is not multiple of 64 bytes (not start of a page) + if ((addr % _24LC256_EEPROM_PAGE_SIZE) != 0) // If not start of a page) { - remaining_size_until_page_end = _24LC256_EEPROM_PAGE_SIZE - (eeprom_addr_to_write & 0x3F); - if(remaining_data_length_to_write <= remaining_size_until_page_end) // if remaining data size is smaller than remaining page size - { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, remaining_data_length_to_write); - if (err != E_NO_ERROR) { - return err; - }else{ - remaining_data_length_to_write = 0; - } - }else + remaining_size_until_page_end = _24LC256_EEPROM_PAGE_SIZE - (eeprom_addr_to_write & 0x3F); + if (remaining_data_length_to_write <= + remaining_size_until_page_end) // if remaining data size is smaller than remaining page size { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, remaining_size_until_page_end); // Write until the end of the page - if (err != E_NO_ERROR) { - return err; - }else{ - remaining_data_length_to_write -= remaining_size_until_page_end; - current_data_buffer += remaining_size_until_page_end; - eeprom_addr_to_write += remaining_size_until_page_end; - MXC_Delay(MXC_DELAY_MSEC(10)); // Wait for 10ms - } + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, + remaining_data_length_to_write); + if (err != E_NO_ERROR) { + return err; + } else { + remaining_data_length_to_write = 0; + } + } else { + err = eeprom_24LC256_write_chunk( + eeprom_addr_to_write, current_data_buffer, + remaining_size_until_page_end); // Write until the end of the page + if (err != E_NO_ERROR) { + return err; + } else { + remaining_data_length_to_write -= remaining_size_until_page_end; + current_data_buffer += remaining_size_until_page_end; + eeprom_addr_to_write += remaining_size_until_page_end; + MXC_Delay(MXC_DELAY_MSEC(10)); // Wait for 10ms + } } } - while(remaining_data_length_to_write) - { - if(remaining_data_length_to_write <= _24LC256_EEPROM_PAGE_SIZE) - { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, remaining_data_length_to_write); - if (err != E_NO_ERROR) { - return err; - } - return E_NO_ERROR; - } - else - { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, _24LC256_EEPROM_PAGE_SIZE); - if (err != E_NO_ERROR) { - return err; - }else{ - remaining_data_length_to_write -= _24LC256_EEPROM_PAGE_SIZE; - current_data_buffer += _24LC256_EEPROM_PAGE_SIZE; - eeprom_addr_to_write += _24LC256_EEPROM_PAGE_SIZE; - MXC_Delay(MXC_DELAY_MSEC(10)); // Wait for 10ms - } - } + while (remaining_data_length_to_write) { + if (remaining_data_length_to_write <= _24LC256_EEPROM_PAGE_SIZE) { + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, + remaining_data_length_to_write); + if (err != E_NO_ERROR) { + return err; + } + return E_NO_ERROR; + } else { + err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, + _24LC256_EEPROM_PAGE_SIZE); + if (err != E_NO_ERROR) { + return err; + } else { + remaining_data_length_to_write -= _24LC256_EEPROM_PAGE_SIZE; + current_data_buffer += _24LC256_EEPROM_PAGE_SIZE; + eeprom_addr_to_write += _24LC256_EEPROM_PAGE_SIZE; + MXC_Delay(MXC_DELAY_MSEC(10)); // Wait for 10ms + } + } } - return E_NO_ERROR; + return E_NO_ERROR; } eeprom_24LC256_driver_t eeprom_24LC256_Open(void) { - eeprom_24LC256_driver_t SD; + eeprom_24LC256_driver_t SD; SD.init = eeprom_24LC256_init; SD.read = eeprom_24LC256_read; SD.write_chunk = eeprom_24LC256_write_chunk; diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h index 687a9f8970b..57f6dc2de91 100644 --- a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h @@ -55,7 +55,7 @@ /**@def _24LC256_EEPROM_SIZE * @brief Total size of 24LC256 EEPROM = 256 Kbit **/ -#define _24LC256_EEPROM_SIZE 0x8000 // 32 KByte = 256 Kbit +#define _24LC256_EEPROM_SIZE 0x8000 // 32 KByte = 256 Kbit /**@def I2C * @brief I2C Max read size for single transaction @@ -67,9 +67,9 @@ */ typedef struct { int (*init)(mxc_i2c_regs_t *i2c, uint8_t addr); ///< Pointer to - int (*read)(uint16_t addr, uint8_t* data_buffer, uint16_t length); - int (*write_chunk)(uint16_t addr, uint8_t* data_buffer, uint16_t length); - int (*write)(uint16_t addr, uint8_t* data_buffer, uint32_t length); + int (*read)(uint16_t addr, uint8_t *data_buffer, uint16_t length); + int (*write_chunk)(uint16_t addr, uint8_t *data_buffer, uint16_t length); + int (*write)(uint16_t addr, uint8_t *data_buffer, uint32_t length); } eeprom_24LC256_driver_t; /** @@ -79,5 +79,4 @@ typedef struct { */ eeprom_24LC256_driver_t eeprom_24LC256_Open(); - #endif /* EEPROM_24LC256_DRIVER_H_ */ From 4c6672aa2821deaf1f33175599b5dc02fada4a31 Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Wed, 4 Oct 2023 10:29:24 +0300 Subject: [PATCH 4/7] Header guard is fixed. --- Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h index 57f6dc2de91..adfa26dfd52 100644 --- a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h @@ -38,8 +38,8 @@ * ******************************************************************************/ -#ifndef EEPROM_24LC256_DRIVER_H_ -#define EEPROM_24LC256_DRIVER_H_ +#ifndef LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ +#define LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ #include #include @@ -79,4 +79,4 @@ typedef struct { */ eeprom_24LC256_driver_t eeprom_24LC256_Open(); -#endif /* EEPROM_24LC256_DRIVER_H_ */ +#endif // LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ From c18768364ee1d31907627a695cced5408a3fd8b6 Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Wed, 4 Oct 2023 10:44:03 +0300 Subject: [PATCH 5/7] clang error fixed. --- Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h index adfa26dfd52..9c5060a7588 100644 --- a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h @@ -79,4 +79,4 @@ typedef struct { */ eeprom_24LC256_driver_t eeprom_24LC256_Open(); -#endif // LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ +#endif // LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ From fbc230d8c49a5a769fb1a024dfcc4304a60ce0ab Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Wed, 25 Oct 2023 14:38:39 +0300 Subject: [PATCH 6/7] Updated according to fix request. --- .../.settings/language.settings.xml | 2 +- Examples/MAX32655/I2C_EEPROM/README.md | 19 ++- Examples/MAX32655/I2C_EEPROM/main.c | 30 ++--- .../EEPROM/eeprom_24lc256_driver.c | 110 +++++++----------- .../EEPROM/eeprom_24lc256_driver.h | 66 +++++++++-- Libraries/MiscDrivers/libinfo.json | 5 + 6 files changed, 138 insertions(+), 94 deletions(-) diff --git a/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml b/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml index 5f595b9fc20..9d535fdfef9 100644 --- a/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml +++ b/Examples/MAX32655/I2C_EEPROM/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/Examples/MAX32655/I2C_EEPROM/README.md b/Examples/MAX32655/I2C_EEPROM/README.md index d05629cbd94..3a96099d4b9 100644 --- a/Examples/MAX32655/I2C_EEPROM/README.md +++ b/Examples/MAX32655/I2C_EEPROM/README.md @@ -32,6 +32,7 @@ Universal instructions on building, flashing, and debugging this project can be ``` + ****************** 24LC256 EEPROM DEMO ******************* This example communicates with an external 24LC256 EEPROM using the I2C. @@ -51,15 +52,27 @@ The value: 0x03 is read from the address: 0x0003 The value: 0x04 is written to the address: 0x0004 The value: 0x04 is read from the address: 0x0004 -EEPROM DEMO - Test2: Writing and Reading 256 Bytes: +EEPROM DEMO - Test2: Writing and Reading 1024 Bytes: -256 Bytes written to the EEPROM starting from the address: 0x0000. Each page (64 byte) filled with its own page number. +1024 Bytes written to the EEPROM starting from the address: 0x0000. Each page (64 byte) filled with its own page number. -256 bytes bytes read from the memory. The start address: 0x0000. The values read: +1024 bytes bytes read from the memory. The start address: 0x0000. The values read: Page 0: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, Page 1: 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, Page 2: 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, Page 3: 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, +Page 4: 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, +Page 5: 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, +Page 6: 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, +Page 7: 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, +Page 8: 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, +Page 9: 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, +Page 10: 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, +Page 11: 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, +Page 12: 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, +Page 13: 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, +Page 14: 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, +Page 15: 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, EEPROM DEMO - Test 3: Write and read test for writing multiple pages starting from random adress(not page start): diff --git a/Examples/MAX32655/I2C_EEPROM/main.c b/Examples/MAX32655/I2C_EEPROM/main.c index 308c7ea5d2a..f4f95e8b605 100644 --- a/Examples/MAX32655/I2C_EEPROM/main.c +++ b/Examples/MAX32655/I2C_EEPROM/main.c @@ -53,10 +53,13 @@ #define EEPROM_24LC256_I2C_SLAVE_ADDR0 0x50 //(0xA0 >> 1) -#define EEPROM_DEMO_BUFFER_PAGE_COUNT 4 +#define EEPROM_DEMO_BUFFER_PAGE_COUNT 16 #define EEPROM_DEMO_BUFFER_SIZE _24LC256_EEPROM_PAGE_SIZE *EEPROM_DEMO_BUFFER_PAGE_COUNT // Bytes -// ***************************************************************************** +/******************************* Globals *******************************/ +static eeprom_24lc256_req_t eeprom1_req; ///< EEPROM request + +/***** Functions *****/ int main(void) { int err = E_NO_ERROR; @@ -73,28 +76,23 @@ int main(void) printf("Press ENTER key to Continue\n\n"); getchar(); - err = MXC_I2C_Init(I2C_MASTER, 1, 0); + err = Eeprom_24LC256_Init(&eeprom1_req, I2C_MASTER, EEPROM_24LC256_I2C_SLAVE_ADDR0, + I2C_FREQ); // init the EEPROM if (err != E_NO_ERROR) { printf("EEPROM configure failed with error %i\n", err); return err; } - MXC_I2C_SetFrequency(I2C_MASTER, I2C_FREQ); - - eeprom_24LC256_driver_t eeprom_24LC256 = eeprom_24LC256_Open(); - - eeprom_24LC256.init(I2C_MASTER, EEPROM_24LC256_I2C_SLAVE_ADDR0); // init the EEPROM - printf("EEPROM DEMO - Test 1: Writing and reading 1 byte:\n\n"); for (i = 0; i < 5; i++) { - err = eeprom_24LC256.write(eeprom_memory_addr, &written_val, 1); + err = Eeprom_24LC256_Write(&eeprom1_req, eeprom_memory_addr, &written_val, 1); if (err != E_NO_ERROR) { printf("EEPROM write error, error code = %d\n", err); } else { printf("The value: 0x%02X is written to the address: 0x%04X\n", written_val, eeprom_memory_addr); } - err = eeprom_24LC256.read(eeprom_memory_addr, &readed_val, 1); + err = Eeprom_24LC256_Read(&eeprom1_req, eeprom_memory_addr, &readed_val, 1); if (err != E_NO_ERROR) { printf("EEPROM read error, error code = %d\n", err); } else { @@ -120,7 +118,8 @@ int main(void) } } - err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); + err = Eeprom_24LC256_Write(&eeprom1_req, eeprom_memory_addr, &eeprom_demo_buffer[0], + EEPROM_DEMO_BUFFER_SIZE); if (err != E_NO_ERROR) { printf("EEPROM write error, error code = %d\n", err); } else { @@ -133,7 +132,8 @@ int main(void) eeprom_demo_buffer[i] = 0; } - err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], EEPROM_DEMO_BUFFER_SIZE); + err = Eeprom_24LC256_Read(&eeprom1_req, eeprom_memory_addr, &eeprom_demo_buffer[0], + EEPROM_DEMO_BUFFER_SIZE); if (err != E_NO_ERROR) { printf("EEPROM read %d bytes error, error code = %d\n", EEPROM_DEMO_BUFFER_SIZE, err); } else { @@ -164,7 +164,7 @@ int main(void) eeprom_demo_buffer[i] = test_val; } - err = eeprom_24LC256.write(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); + err = Eeprom_24LC256_Write(&eeprom1_req, eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); if (err != E_NO_ERROR) { printf("EEPROM write error, error code = %d\n", err); } else { @@ -177,7 +177,7 @@ int main(void) eeprom_demo_buffer[i] = 0; } - err = eeprom_24LC256.read(eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); + err = Eeprom_24LC256_Read(&eeprom1_req, eeprom_memory_addr, &eeprom_demo_buffer[0], test_size); if (err != E_NO_ERROR) { printf("EEPROM read error, error code = %d\n", err); } else { diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c index d488e2f0c34..1612341c5b4 100644 --- a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.c @@ -31,11 +31,9 @@ * ******************************************************************************/ +/***** Includes *****/ #include "eeprom_24lc256_driver.h" -/******************************* Globals *******************************/ -static mxc_i2c_req_t req; ///< I2C request - /******************************* Functions *******************************/ static int i2c_transfer(mxc_i2c_req_t *req, uint8_t *txData, int txSize, uint8_t *rxData, int rxSize) @@ -57,36 +55,37 @@ static int i2c_read(mxc_i2c_req_t *req, uint8_t *txData, uint8_t *rxData, int rx return i2c_transfer(req, txData, 2, rxData, rxSize); // Create I2C read request } -/** - * @brief Initializes I2C registers EEPROM - * @param i2c I2C registers - * @param addr Slave I2C address of EEPROM. - * @returns #E_NO_ERROR if init succeeded. - * - */ -static int eeprom_24LC256_init(mxc_i2c_regs_t *i2c, uint8_t addr) +int Eeprom_24LC256_Init(eeprom_24lc256_req_t *req, mxc_i2c_regs_t *i2c, uint8_t addr, + unsigned int i2c_freq) { - req.i2c = i2c; - req.addr = addr; - req.tx_buf = NULL; - req.tx_len = 0; - req.rx_buf = NULL; - req.rx_len = 0; - req.restart = 0; - req.callback = NULL; + int err = E_NO_ERROR; + int return_val = 0; + + err = MXC_I2C_Init(i2c, 1, 0); + if (err != E_NO_ERROR) { + return err; + } + + return_val = MXC_I2C_SetFrequency(i2c, i2c_freq); + if (return_val <= 0) { + err = return_val; + return err; + } + + req->i2c_req.i2c = i2c; + req->i2c_req.addr = addr; + req->i2c_req.tx_buf = NULL; + req->i2c_req.tx_len = 0; + req->i2c_req.rx_buf = NULL; + req->i2c_req.rx_len = 0; + req->i2c_req.restart = 0; + req->i2c_req.callback = NULL; return E_NO_ERROR; } -/** - * @brief Writes data from EEPROM - * @param addr Start address we want to read. - * @param data_buffer Data buffer to read. - * @param length Number of bytes to read. - * @returns #E_NO_ERROR if read succeeded. non-zero if an error occurred. - * - */ -static int eeprom_24LC256_read(uint16_t addr, uint8_t *data_buffer, uint16_t length) +int Eeprom_24LC256_Read(eeprom_24lc256_req_t *req, uint16_t addr, uint8_t *data_buffer, + uint16_t length) { int err = E_NO_ERROR; uint16_t remaining = length; @@ -104,7 +103,7 @@ static int eeprom_24LC256_read(uint16_t addr, uint8_t *data_buffer, uint16_t len send_buffer[1] = (eeprom_addr_to_read & 0x00FF); // Read - err = i2c_read(&req, send_buffer, current_data_buffer, remaining); + err = i2c_read(&req->i2c_req, send_buffer, current_data_buffer, remaining); if (err != E_NO_ERROR) { return err; } else { @@ -115,7 +114,7 @@ static int eeprom_24LC256_read(uint16_t addr, uint8_t *data_buffer, uint16_t len send_buffer[1] = (eeprom_addr_to_read & 0x00FF); // Read - err = i2c_read(&req, send_buffer, current_data_buffer, I2C_MAX_READ_SIZE); + err = i2c_read(&req->i2c_req, send_buffer, current_data_buffer, I2C_MAX_READ_SIZE); if (err != E_NO_ERROR) { return err; } @@ -127,19 +126,18 @@ static int eeprom_24LC256_read(uint16_t addr, uint8_t *data_buffer, uint16_t len return E_NO_ERROR; } -/** - * @brief Writes a small chunk of data directly to the EEPROM. The written memory should be in the same page of EEPROM (1 page = 64 bytes) - * @param addr Address we want to write to. - * @param data_buffer Data buffer to write. - * @param length Number of bytes to write. - * @returns #E_NO_ERROR if write succeeded. non-zero if an error occurred. - * - */ -static int eeprom_24LC256_write_chunk(uint16_t addr, uint8_t *data_buffer, uint16_t length) +int Eeprom_24LC256_Write_Chunk(eeprom_24lc256_req_t *req, uint16_t addr, uint8_t *data_buffer, + uint16_t length) { int err = E_NO_ERROR; int i = 0; uint8_t send_buffer[66]; // Page size (64) + 2 bytes + + uint16_t remaining_size_until_page_end = _24LC256_EEPROM_PAGE_SIZE - (addr & 0x3F); + if (length > remaining_size_until_page_end) { + return E_BAD_PARAM; + } + send_buffer[0] = addr >> 8; send_buffer[1] = (addr & 0x00FF); for (i = 0; i < length; i++) { @@ -147,22 +145,15 @@ static int eeprom_24LC256_write_chunk(uint16_t addr, uint8_t *data_buffer, uint1 } // Write - err = i2c_write(&req, send_buffer, (length + 2)); + err = i2c_write(&req->i2c_req, send_buffer, (length + 2)); if (err != E_NO_ERROR) { return err; } return E_NO_ERROR; } -/** - * @brief Writes data to the EEPROM - * @param addr Address we want to write to. - * @param data_buffer Data buffer to write. - * @param length Number of bytes to write. - * @returns #E_NO_ERROR if write succeeded. non-zero if an error occurred. - * - */ -static int eeprom_24LC256_write(uint16_t addr, uint8_t *data_buffer, uint32_t length) +int Eeprom_24LC256_Write(eeprom_24lc256_req_t *req, uint16_t addr, uint8_t *data_buffer, + uint32_t length) { int err = E_NO_ERROR; uint16_t remaining_data_length_to_write = length; @@ -181,7 +172,7 @@ static int eeprom_24LC256_write(uint16_t addr, uint8_t *data_buffer, uint32_t le if (remaining_data_length_to_write <= remaining_size_until_page_end) // if remaining data size is smaller than remaining page size { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, + err = Eeprom_24LC256_Write_Chunk(req, eeprom_addr_to_write, current_data_buffer, remaining_data_length_to_write); if (err != E_NO_ERROR) { return err; @@ -189,8 +180,8 @@ static int eeprom_24LC256_write(uint16_t addr, uint8_t *data_buffer, uint32_t le remaining_data_length_to_write = 0; } } else { - err = eeprom_24LC256_write_chunk( - eeprom_addr_to_write, current_data_buffer, + err = Eeprom_24LC256_Write_Chunk( + req, eeprom_addr_to_write, current_data_buffer, remaining_size_until_page_end); // Write until the end of the page if (err != E_NO_ERROR) { return err; @@ -205,14 +196,14 @@ static int eeprom_24LC256_write(uint16_t addr, uint8_t *data_buffer, uint32_t le while (remaining_data_length_to_write) { if (remaining_data_length_to_write <= _24LC256_EEPROM_PAGE_SIZE) { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, + err = Eeprom_24LC256_Write_Chunk(req, eeprom_addr_to_write, current_data_buffer, remaining_data_length_to_write); if (err != E_NO_ERROR) { return err; } return E_NO_ERROR; } else { - err = eeprom_24LC256_write_chunk(eeprom_addr_to_write, current_data_buffer, + err = Eeprom_24LC256_Write_Chunk(req, eeprom_addr_to_write, current_data_buffer, _24LC256_EEPROM_PAGE_SIZE); if (err != E_NO_ERROR) { return err; @@ -226,14 +217,3 @@ static int eeprom_24LC256_write(uint16_t addr, uint8_t *data_buffer, uint32_t le } return E_NO_ERROR; } - -eeprom_24LC256_driver_t eeprom_24LC256_Open(void) -{ - eeprom_24LC256_driver_t SD; - SD.init = eeprom_24LC256_init; - SD.read = eeprom_24LC256_read; - SD.write_chunk = eeprom_24LC256_write_chunk; - SD.write = eeprom_24LC256_write; - - return SD; -} diff --git a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h index 9c5060a7588..23d3b0e781c 100644 --- a/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h +++ b/Libraries/MiscDrivers/EEPROM/eeprom_24lc256_driver.h @@ -41,12 +41,14 @@ #ifndef LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ #define LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ +/***** Includes *****/ #include #include #include #include "mxc_delay.h" #include "i2c.h" +/***** Definitions *****/ /**@def _24LC256_EEPROM_PAGE_SIZE * @brief Page size of 24LC256 EEPROM **/ @@ -62,21 +64,65 @@ **/ #define I2C_MAX_READ_SIZE 256 +typedef struct _eeprom_24lc256_req_t eeprom_24lc256_req_t; + +/** + * @brief The information required to communicate with eeprom over the I2C channel. + * + * This structure is used to communicate eeprom over I2C channel. + */ +struct _eeprom_24lc256_req_t { + mxc_i2c_req_t i2c_req; ///< I2C request +}; + +/***** Function Prototypes *****/ + /** - * @brief Structure with sensor function pointers + * @brief Initializes I2C registers EEPROM + * @param req Pointer to details of communication with eeprom + * @param i2c I2C registers + * @param addr Slave I2C address of EEPROM. + * @param i2c_freq The desired i2c frequency in Hertz + * @return #E_NO_ERROR if read succeeded, see \ref MXC_Error_Codes for a list of return codes. + * + */ +int Eeprom_24LC256_Init(eeprom_24lc256_req_t *req, mxc_i2c_regs_t *i2c, uint8_t addr, + unsigned int i2c_freq); + +/** + * @brief Reads data from EEPROM + * @param req Pointer to details of communication with eeprom + * @param addr Start address we want to read. + * @param data_buffer Data buffer to read. + * @param length Number of bytes to read. + * @return #E_NO_ERROR if read succeeded. see \ref MXC_Error_Codes for a list of return codes. + * + */ +int Eeprom_24LC256_Read(eeprom_24lc256_req_t *req, uint16_t addr, uint8_t *data_buffer, + uint16_t length); + +/** + * @brief Writes a small chunk of data directly to the EEPROM. The written memory should be in the same page of EEPROM (1 page = 64 bytes) + * @param req Pointer to details of communication with eeprom + * @param addr Address we want to write to. + * @param data_buffer Data buffer to write. + * @param length Number of bytes to write. + * @returns #E_NO_ERROR if write succeeded. see \ref MXC_Error_Codes for a list of return codes. + * */ -typedef struct { - int (*init)(mxc_i2c_regs_t *i2c, uint8_t addr); ///< Pointer to - int (*read)(uint16_t addr, uint8_t *data_buffer, uint16_t length); - int (*write_chunk)(uint16_t addr, uint8_t *data_buffer, uint16_t length); - int (*write)(uint16_t addr, uint8_t *data_buffer, uint32_t length); -} eeprom_24LC256_driver_t; +int Eeprom_24LC256_Write_Chunk(eeprom_24lc256_req_t *req, uint16_t addr, uint8_t *data_buffer, + uint16_t length); /** - * @brief Prepare EEPROM_24LC256_DRIVER function pointers + * @brief Writes data to the EEPROM + * @param req Pointer to details of communication with eeprom + * @param addr Address we want to write to. + * @param data_buffer Data buffer to write. + * @param length Number of bytes to write. + * @returns #E_NO_ERROR if write succeeded. see \ref MXC_Error_Codes for a list of return codes. * - * @return eeprom_24LC256_driver_t instance */ -eeprom_24LC256_driver_t eeprom_24LC256_Open(); +int Eeprom_24LC256_Write(eeprom_24lc256_req_t *req, uint16_t addr, uint8_t *data_buffer, + uint32_t length); #endif // LIBRARIES_MISCDRIVERS_EEPROM_EEPROM_24LC256_DRIVER_H_ diff --git a/Libraries/MiscDrivers/libinfo.json b/Libraries/MiscDrivers/libinfo.json index 7a990cf737c..6d237387769 100644 --- a/Libraries/MiscDrivers/libinfo.json +++ b/Libraries/MiscDrivers/libinfo.json @@ -3,6 +3,7 @@ "ipaths":[ "Camera", "Display", + "EEPROM", "ExtMemory", "LED", "PMIC", @@ -14,6 +15,7 @@ "ADC", "Camera", "Display", + "EEPROM", "LED", "PMIC", "PushButton", @@ -22,6 +24,9 @@ "./"], "whitelist":"True", "targets":[ + { + "name":"MAX32655" + }, { "name":"MAX32665" }, From 395f360ef746d0429cfcf00ac34e1b584ba51d43 Mon Sep 17 00:00:00 2001 From: Kenan Balci Date: Thu, 26 Oct 2023 08:52:15 +0300 Subject: [PATCH 7/7] variable name change --- Examples/MAX32655/I2C_EEPROM/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/MAX32655/I2C_EEPROM/main.c b/Examples/MAX32655/I2C_EEPROM/main.c index f4f95e8b605..d437ac42ff9 100644 --- a/Examples/MAX32655/I2C_EEPROM/main.c +++ b/Examples/MAX32655/I2C_EEPROM/main.c @@ -66,7 +66,7 @@ int main(void) int i = 0, j = 0; uint16_t eeprom_memory_addr = 0x0000; uint8_t written_val = 0; - uint8_t readed_val = 0; + uint8_t read_val = 0; uint8_t eeprom_demo_buffer[EEPROM_DEMO_BUFFER_SIZE]; uint32_t page_offset = 0; @@ -92,15 +92,15 @@ int main(void) printf("The value: 0x%02X is written to the address: 0x%04X\n", written_val, eeprom_memory_addr); } - err = Eeprom_24LC256_Read(&eeprom1_req, eeprom_memory_addr, &readed_val, 1); + err = Eeprom_24LC256_Read(&eeprom1_req, eeprom_memory_addr, &read_val, 1); if (err != E_NO_ERROR) { printf("EEPROM read error, error code = %d\n", err); } else { - printf("The value: 0x%02X is read from the address: 0x%04X\n", readed_val, + printf("The value: 0x%02X is read from the address: 0x%04X\n", read_val, eeprom_memory_addr); } - if (readed_val != written_val) { - printf("EEPROM error; written and read values are different\n", readed_val, + if (read_val != written_val) { + printf("EEPROM error; written and read values are different\n", read_val, eeprom_memory_addr); }