Skip to content

Commit

Permalink
add FRAM read tool
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Nov 22, 2024
1 parent 09a2635 commit 9a49a9d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tools/fram_read/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
53 changes: 53 additions & 0 deletions tools/fram_read/fram_read.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstdio>

#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;
}

0 comments on commit 9a49a9d

Please sign in to comment.