Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Fujitsu MB85RS4MT FRAM; added sleep mode #31

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ name: Arduino Library CI
on: [pull_request, push, repository_dispatch]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run pre-commit
uses: pre-commit/[email protected]

build:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: actions/checkout@v3
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: adafruit/ci-arduino
path: ci
Expand All @@ -22,9 +27,6 @@ jobs:
- name: test platforms
run: python3 ci/build_platform.py main_platforms

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
#
# SPDX-License-Identifier: Unlicense

repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.7
hooks:
- id: clang-format
types_or: [c++, c, header]
34 changes: 34 additions & 0 deletions Adafruit_FRAM_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const struct {
{0x04, 0x2503, 32 * 1024UL}, // MB85RS256TY
{0x04, 0x2703, 128 * 1024UL}, // MB85RS1MT
{0x04, 0x4803, 256 * 1024UL}, // MB85RS2MTA
{0x04, 0x2803, 256 * 1024UL}, // MB85RS2MT
{0x04, 0x4903, 512 * 1024UL}, // MB85RS4MT

// Cypress
Expand Down Expand Up @@ -343,3 +344,36 @@ bool Adafruit_FRAM_SPI::setStatusRegister(uint8_t value) {
void Adafruit_FRAM_SPI::setAddressSize(uint8_t nAddressSize) {
_nAddressSizeBytes = nAddressSize;
}

/*!
* @brief Enters the FRAM's low power sleep mode
* @return true if successful
*/
// WARNING: this method has not yet been validated
bool Adafruit_FRAM_SPI::enter_low_power_mode(void) {
uint8_t cmd;

cmd = OPCODE_SLEEP;

return spi_dev->write(&cmd, 1);
}

/*!
* @brief exits the FRAM's low power sleep mode
* @return true if successful
*/
// WARNING: this method has not yet been validated
bool Adafruit_FRAM_SPI::exit_low_power_mode(void) {
uint8_t cmd;

// Returning to an normal operation from the SLEEP mode is carried out after
// tREC (Max 400 μs) time from the falling edge of CS
spi_dev->beginTransactionWithAssertingCS();
delayMicroseconds(300);
// It is possible to return CS to H level before tREC time. However, it
// is prohibited to bring down CS to L level again during tREC period.
spi_dev->endTransactionWithDeassertingCS();
delayMicroseconds(100);

return spi_dev->write(&cmd, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need to do spi write() here, cs along should be able to put chip out of sleep

}
18 changes: 11 additions & 7 deletions Adafruit_FRAM_SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* BSD license, all text above must be included in any redistribution
*/

#ifndef _ADAFRUIT_FRAM_SPI_H_
#define _ADAFRUIT_FRAM_SPI_H_

Expand All @@ -27,13 +28,14 @@

/** Operation Codes **/
typedef enum opcodes_e {
OPCODE_WREN = 0b0110, /* Write Enable Latch */
OPCODE_WRDI = 0b0100, /* Reset Write Enable Latch */
OPCODE_RDSR = 0b0101, /* Read Status Register */
OPCODE_WRSR = 0b0001, /* Write Status Register */
OPCODE_READ = 0b0011, /* Read Memory */
OPCODE_WRITE = 0b0010, /* Write Memory */
OPCODE_RDID = 0b10011111 /* Read Device ID */
OPCODE_WREN = 0b0110, /* Write Enable Latch */
OPCODE_WRDI = 0b0100, /* Reset Write Enable Latch */
OPCODE_RDSR = 0b0101, /* Read Status Register */
OPCODE_WRSR = 0b0001, /* Write Status Register */
OPCODE_READ = 0b0011, /* Read Memory */
OPCODE_WRITE = 0b0010, /* Write Memory */
OPCODE_RDID = 0b10011111, /* Read Device ID */
OPCODE_SLEEP = 0b10111001 /* Sleep Mode by FUEL4EP */
} opcodes_t;

/*!
Expand All @@ -56,6 +58,8 @@ class Adafruit_FRAM_SPI {
uint8_t getStatusRegister(void);
bool setStatusRegister(uint8_t value);
void setAddressSize(uint8_t nAddressSize);
bool enter_low_power_mode(void); // added by FUEL4EP
bool exit_low_power_mode(void); // added by FUEL4EP

private:
Adafruit_SPIDevice *spi_dev = NULL;
Expand Down
67 changes: 37 additions & 30 deletions examples/FRAMInfo/FRAMInfo.ino
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"
#include <SPI.h>

/* Example code to interrogate Adafruit SPI FRAM breakout for address size and storage capacity */
/* Example code to interrogate Adafruit SPI FRAM breakout for address size and
* storage capacity */

/* NOTE: This sketch will overwrite data already on the FRAM breakout */

uint8_t FRAM_CS = 10;
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI

uint8_t FRAM_SCK = 13;
uint8_t FRAM_MISO = 12;
uint8_t FRAM_MOSI = 11;
//Or use software SPI, any pins!
//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);
// Or use software SPI, any pins!
// Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI,
// FRAM_CS);

uint8_t addrSizeInBytes = 2; //Default to address size of two bytes
uint32_t memSize;
uint8_t addrSizeInBytes = 2; // Default to address size of two bytes
uint32_t memSize;

int32_t readBack(uint32_t addr, int32_t data) {
int32_t check = !data;
int32_t wrapCheck, backup;
fram.read(addr, (uint8_t*)&backup, sizeof(int32_t));
fram.read(addr, (uint8_t *)&backup, sizeof(int32_t));
fram.writeEnable(true);
fram.write(addr, (uint8_t*)&data, sizeof(int32_t));
fram.write(addr, (uint8_t *)&data, sizeof(int32_t));
fram.writeEnable(false);
fram.read(addr, (uint8_t*)&check, sizeof(int32_t));
fram.read(0, (uint8_t*)&wrapCheck, sizeof(int32_t));
fram.read(addr, (uint8_t *)&check, sizeof(int32_t));
fram.read(0, (uint8_t *)&wrapCheck, sizeof(int32_t));
fram.writeEnable(true);
fram.write(addr, (uint8_t*)&backup, sizeof(int32_t));
fram.write(addr, (uint8_t *)&backup, sizeof(int32_t));
fram.writeEnable(false);
// Check for warparound, address 0 will work anyway
if (wrapCheck==check)
if (wrapCheck == check)
check = 0;
return check;
}
Expand All @@ -42,17 +44,18 @@ bool testAddrSize(uint8_t addrSize) {
return false;
}


void setup(void) {
Serial.begin(9600);

while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens

while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens

if (fram.begin(addrSizeInBytes)) {
Serial.println("Found SPI FRAM");
} else {
Serial.println("No SPI FRAM found ... check your connections\r\n");
while (1);
while (1)
;
}

if (testAddrSize(2))
Expand All @@ -62,28 +65,32 @@ void setup(void) {
else if (testAddrSize(4))
addrSizeInBytes = 4;
else {
Serial.println("SPI FRAM can not be read/written with any address size\r\n");
while (1);
Serial.println(
"SPI FRAM can not be read/written with any address size\r\n");
while (1)
;
}

memSize = 0;
while (readBack(memSize, memSize) == memSize) {
memSize += 256;
//Serial.print("Block: #"); Serial.println(memSize/256);
// Serial.print("Block: #"); Serial.println(memSize/256);
}

Serial.print("SPI FRAM address size is ");
Serial.print(addrSizeInBytes);
Serial.println(" bytes.");
Serial.println("SPI FRAM capacity appears to be..");
Serial.print(memSize); Serial.println(" bytes");
Serial.print(memSize/0x400); Serial.println(" kilobytes");
Serial.print((memSize*8)/0x400); Serial.println(" kilobits");
if (memSize >= (0x100000/8)) {
Serial.print((memSize*8)/0x100000); Serial.println(" megabits");
Serial.print(memSize);
Serial.println(" bytes");
Serial.print(memSize / 0x400);
Serial.println(" kilobytes");
Serial.print((memSize * 8) / 0x400);
Serial.println(" kilobits");
if (memSize >= (0x100000 / 8)) {
Serial.print((memSize * 8) / 0x100000);
Serial.println(" megabits");
}
}

void loop(void) {

}
void loop(void) {}
44 changes: 25 additions & 19 deletions examples/MB85RS64V/MB85RS64V.ino
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"
#include <SPI.h>

/* Example code for the Adafruit SPI FRAM breakout */
uint8_t FRAM_CS = 10;

//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI
// Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); // use hardware SPI

uint8_t FRAM_SCK= 13;
uint8_t FRAM_SCK = 13;
uint8_t FRAM_MISO = 12;
uint8_t FRAM_MOSI = 11;
//Or use software SPI, any pins!
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);
// Or use software SPI, any pins!
Adafruit_FRAM_SPI fram =
Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);

uint16_t addr = 0;
uint16_t addr = 0;

void setup(void) {
Serial.begin(9600);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens

while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens

if (fram.begin()) {
Serial.println("Found SPI FRAM");
} else {
Serial.println("No SPI FRAM found ... check your connections\r\n");
while (1);
while (1)
;
}

// Read the first byte
uint8_t test = fram.read8(0x0);
Serial.print("Restarted "); Serial.print(test); Serial.println(" times");
Serial.print("Restarted ");
Serial.print(test);
Serial.println(" times");

// Test write ++
fram.writeEnable(true);
fram.write8(0x0, test+1);
fram.write8(0x0, test + 1);
fram.writeEnable(false);

fram.writeEnable(true);
Expand All @@ -43,15 +48,16 @@ void setup(void) {
for (uint16_t a = 0; a < 8192; a++) {
value = fram.read8(a);
if ((a % 32) == 0) {
Serial.print("\n 0x"); Serial.print(a, HEX); Serial.print(": ");
Serial.print("\n 0x");
Serial.print(a, HEX);
Serial.print(": ");
}
Serial.print("0x");
if (value < 0x1)
Serial.print("0x");
if (value < 0x1)
Serial.print('0');
Serial.print(value, HEX); Serial.print(" ");
Serial.print(value, HEX);
Serial.print(" ");
}
}

void loop(void) {

}
void loop(void) {}