|
F439_CPP_SPI_RA8875_TFT_LCD_04 1.0
STM32F439 SPI RA8875 7-inch TFT display with FRAM-backed touch calibration, built on the STM32_GFX, STM32_RA8875 and STM32_MB85RS64V libraries
|
Driver for one MB85RS64V SPI FRAM (8192 bytes) on an STM32 HAL SPI bus. More...
#include <MB85RS64V.hpp>
Public Types | |
| enum class | BlockProtect : uint8_t { None = 0 , UpperQuarter = STATUS_BP0 , UpperHalf = STATUS_BP1 , All = STATUS_BP1 | STATUS_BP0 } |
| Areas of the array that the block-protect bits can lock against writes. More... | |
Public Member Functions | |
| MB85RS64V (SPI_HandleTypeDef *hspi, GPIO_TypeDef *csPort, uint16_t csPin, uint32_t timeoutMs=100, uint8_t maxAttempts=3) | |
| Creates the driver object; does not touch the hardware (call begin() for that). | |
| bool | begin () |
| Checks the SPI setup and the chip's identity, and leaves writes disabled. | |
| bool | readId (uint8_t *id) |
| Reads the four-byte device ID (RDID, 9Fh). | |
| bool | read (uint16_t address, uint8_t *buffer, size_t length) |
| Reads bytes from the FRAM array (READ, 03h). | |
| bool | write (uint16_t address, const uint8_t *data, size_t length) |
| Writes bytes to the FRAM array (WREN, then WRITE, 02h); a retry repeats both steps. | |
| bool | writeEnable () |
| Sets the write enable latch (WREN, 06h). Normally not needed; write() does it. | |
| bool | writeDisable () |
| Clears the write enable latch (WRDI, 04h). | |
| bool | readStatus (uint8_t *status) |
| Reads the status register (RDSR, 05h). | |
| bool | writeStatus (uint8_t status) |
| Writes the status register (WREN, then WRSR, 01h); a retry repeats both steps. | |
| bool | setBlockProtect (BlockProtect area) |
| Sets which part of the array the block-protect bits lock against writes, keeping the other writable status bits as they are. | |
| HAL_StatusTypeDef | lastStatus () const |
| HAL status of the most recent failed SPI call (HAL_OK if none has failed). Because a failed command is retried and then ends in Error_Handler(), this is mainly useful from a custom Error_Handler() or a debugger. | |
Static Public Attributes | |
| static constexpr uint16_t | SIZE_BYTES = 8192 |
| Capacity in bytes (8192; addresses 0x0000 to 0x1FFF). | |
| static constexpr size_t | ID_LENGTH = 4 |
| Number of bytes returned by readId(). | |
Status register bits | |
| static constexpr uint8_t | STATUS_WEL = 0x02 |
| Write enable latch (read-only through WRSR). | |
| static constexpr uint8_t | STATUS_BP0 = 0x04 |
| Block protect bit 0. | |
| static constexpr uint8_t | STATUS_BP1 = 0x08 |
| Block protect bit 1. | |
| static constexpr uint8_t | STATUS_WPEN = 0x80 |
| Status register write protect enable. | |
Driver for one MB85RS64V SPI FRAM (8192 bytes) on an STM32 HAL SPI bus.
FRAM writes at bus speed: there is no page buffer, no erase and no write delay, so every call below completes when its SPI transfer completes. Write endurance is 10^12 cycles per byte.
maxAttempts times in all. Any other failure, such as HAL_ERROR from a bad parameter or a peripheral in the wrong state, cannot be fixed by trying again and is not retried. Once the attempts are used up, or at once for a failure that is not retried, the driver calls Error_Handler() from main.h, which does not return. lastStatus() holds the HAL status of the most recent failed attempt. The methods still return false for a bad argument, and begin() returns false when the chip answers with the wrong ID or the SPI handle is configured wrongly; the caller decides what to do about those (a bridge function normally reports the reason and calls Error_Handler()).Definition at line 78 of file MB85RS64V.hpp.
|
strong |
Areas of the array that the block-protect bits can lock against writes.
| Enumerator | |
|---|---|
| None | No protection. |
| UpperQuarter | 0x1800 to 0x1FFF protected. |
| UpperHalf | 0x1000 to 0x1FFF protected. |
| All | 0x0000 to 0x1FFF protected. |
Definition at line 95 of file MB85RS64V.hpp.
| MB85RS64V::MB85RS64V | ( | SPI_HandleTypeDef * | hspi, |
| GPIO_TypeDef * | csPort, | ||
| uint16_t | csPin, | ||
| uint32_t | timeoutMs = 100, | ||
| uint8_t | maxAttempts = 3 ) |
Creates the driver object; does not touch the hardware (call begin() for that).
| hspi | SPI handle already initialised by CubeMX. |
| csPort | GPIO port of the chip-select pin. |
| csPin | GPIO pin of the chip-select pin. |
| timeoutMs | Timeout of each HAL SPI call, in milliseconds. |
| maxAttempts | Tries per command when it fails with a transient communication error, before Error_Handler() is called; 0 is treated as 1. |
Construct the object after MX_SPIx_Init() has run (for example with new inside an init function), not as a global, which would be constructed before the peripheral is configured.
Definition at line 25 of file MB85RS64V.cpp.
| bool MB85RS64V::begin | ( | ) |
Checks the SPI setup and the chip's identity, and leaves writes disabled.
Definition at line 145 of file MB85RS64V.cpp.
References ID_LENGTH, readId(), and writeDisable().
Referenced by initFRAM().
|
inline |
HAL status of the most recent failed SPI call (HAL_OK if none has failed). Because a failed command is retried and then ends in Error_Handler(), this is mainly useful from a custom Error_Handler() or a debugger.
Definition at line 129 of file MB85RS64V.hpp.
Referenced by initFRAM(), and testFRAM().
| bool MB85RS64V::read | ( | uint16_t | address, |
| uint8_t * | buffer, | ||
| size_t | length ) |
Reads bytes from the FRAM array (READ, 03h).
| address | First address, 0x0000 to 0x1FFF. |
| buffer | Destination buffer of at least length bytes. |
| length | Number of bytes; address + length must not exceed SIZE_BYTES. |
Definition at line 186 of file MB85RS64V.cpp.
References SIZE_BYTES.
Referenced by testFRAM(), touchCalibrationLoad(), and touchCalibrationSave().
| bool MB85RS64V::readId | ( | uint8_t * | id | ) |
Reads the four-byte device ID (RDID, 9Fh).
| id | Buffer of at least ID_LENGTH bytes. Expected: 04h (Fujitsu manufacturer), 7Fh (continuation code), 03h (64 Kbit density), 02h. |
id is null. Definition at line 166 of file MB85RS64V.cpp.
References ID_LENGTH.
Referenced by begin(), and initFRAM().
| bool MB85RS64V::readStatus | ( | uint8_t * | status | ) |
Reads the status register (RDSR, 05h).
| status | Receives the register value (see the STATUS_* constants). |
status is null. Definition at line 252 of file MB85RS64V.cpp.
Referenced by initFRAM(), and setBlockProtect().
| bool MB85RS64V::setBlockProtect | ( | BlockProtect | area | ) |
Sets which part of the array the block-protect bits lock against writes, keeping the other writable status bits as they are.
| area | Which part of the array to lock. |
Definition at line 294 of file MB85RS64V.cpp.
References readStatus(), STATUS_BP0, STATUS_BP1, and writeStatus().
| bool MB85RS64V::write | ( | uint16_t | address, |
| const uint8_t * | data, | ||
| size_t | length ) |
Writes bytes to the FRAM array (WREN, then WRITE, 02h); a retry repeats both steps.
| address | First address, 0x0000 to 0x1FFF. |
| data | Source buffer of at least length bytes. |
| length | Number of bytes; address + length must not exceed SIZE_BYTES. |
The write enable latch is set before each write and clears automatically afterwards, so every call is independent. Writing into a block that setBlockProtect() has locked is silently ignored by the chip; read the data back if you need to be sure.
Definition at line 210 of file MB85RS64V.cpp.
References SIZE_BYTES.
Referenced by testFRAM(), and touchCalibrationSave().
| bool MB85RS64V::writeDisable | ( | ) |
Clears the write enable latch (WRDI, 04h).
Definition at line 243 of file MB85RS64V.cpp.
Referenced by begin().
| bool MB85RS64V::writeEnable | ( | ) |
Sets the write enable latch (WREN, 06h). Normally not needed; write() does it.
Definition at line 235 of file MB85RS64V.cpp.
| bool MB85RS64V::writeStatus | ( | uint8_t | status | ) |
Writes the status register (WREN, then WRSR, 01h); a retry repeats both steps.
| status | New value; the chip stores only WPEN, BP1 and BP0. |
Definition at line 271 of file MB85RS64V.cpp.
Referenced by setBlockProtect().
|
staticconstexpr |
Number of bytes returned by readId().
Definition at line 84 of file MB85RS64V.hpp.
Referenced by begin(), initFRAM(), and readId().
|
staticconstexpr |
Capacity in bytes (8192; addresses 0x0000 to 0x1FFF).
Definition at line 81 of file MB85RS64V.hpp.
Referenced by read(), touchCalibrationAttachStorage(), and write().
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
Write enable latch (read-only through WRSR).
Definition at line 88 of file MB85RS64V.hpp.
|
staticconstexpr |
Status register write protect enable.
Definition at line 91 of file MB85RS64V.hpp.