From 9a49a9d8ce034c2fb9b422a430d450009b4bd7ab Mon Sep 17 00:00:00 2001 From: Cameron Goddard Date: Fri, 22 Nov 2024 17:05:34 -0500 Subject: [PATCH] add FRAM read tool --- tools/fram_read/CMakeLists.txt | 41 ++++++++++++++++++++++++++ tools/fram_read/fram_read.cpp | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tools/fram_read/CMakeLists.txt create mode 100644 tools/fram_read/fram_read.cpp diff --git a/tools/fram_read/CMakeLists.txt b/tools/fram_read/CMakeLists.txt new file mode 100644 index 0000000..f2bf04c --- /dev/null +++ b/tools/fram_read/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.22) + +# Pull in SDK (must be before project) +include(../../lib/pico-sdk/pico_sdk_init.cmake) + +project(fram_read C CXX ASM) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +# Initialize the SDK +pico_sdk_init() + +add_compile_options( + -Wall + -Wno-format + -Wno-unused-function +) + +add_executable(${PROJECT_NAME} + ${PROJECT_NAME}.cpp +) + +add_subdirectory(${PROJECT_SOURCE_DIR}/../../lib/MB85RS-Pico ${CMAKE_BINARY_DIR}/MB85RS-Pico) + +# Include project and library headers +target_include_directories(${PROJECT_NAME} + PRIVATE + ${PROJECT_SOURCE_DIR}/../../lib/MB85RS-Pico +) + +# Pull in common dependencies +target_link_libraries(${PROJECT_NAME} + pico_stdlib + MB85RS-Pico +) + +pico_enable_stdio_usb(${PROJECT_NAME} 1) +pico_enable_stdio_uart(${PROJECT_NAME} 0) + +# Create uf2 file +pico_add_uf2_output(${PROJECT_NAME}) \ No newline at end of file diff --git a/tools/fram_read/fram_read.cpp b/tools/fram_read/fram_read.cpp new file mode 100644 index 0000000..0e39150 --- /dev/null +++ b/tools/fram_read/fram_read.cpp @@ -0,0 +1,53 @@ +/** + * @file fram_read.cpp + * @author csg83 + * + * @brief Reads out the contents of FRAM + */ + +#include "pico/stdlib.h" +#include "mb85rs.hpp" +#include "../../src/pins.hpp" +#include "tusb.h" +#include + +#define BYTES_TO_READ 20 + +MB85RS fram(SPI_PORT, FRAM_CS); + +int main() { + stdio_init_all(); + + gpio_init(FRAM_CS); + gpio_set_dir(FRAM_CS, GPIO_OUT); + + spi_init(SPI_PORT, 125 * 1000000 / 6); + gpio_set_function(SPI_MISO, GPIO_FUNC_SPI); + gpio_set_function(SPI_MOSI, GPIO_FUNC_SPI); + gpio_set_function(SPI_SCK, GPIO_FUNC_SPI); + gpio_put(FRAM_CS, 1); + + while (!tud_cdc_connected()) { + sleep_ms(500); + } + printf("Connected\n"); + + if (!fram.begin()) { + printf("Error: FRAM begin unsuccessful\n"); + } + + uint8_t data[BYTES_TO_READ] = {0}; + uint8_t temp = 42; + + fram.write_bytes(0, &temp, 1); + + if (fram.read_bytes(0, data, BYTES_TO_READ)) { + for (int i = 0; i < BYTES_TO_READ; i++) { + printf("(%d): %d\n", i, data[i]); + } + } else { + printf("Error: FRAM read unsuccessful\n"); + } + + return 0; +} \ No newline at end of file