CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
flash_driver.h File Reference
#include <stdint.h>
#include "main.h"
#include "littlefs/lfs.h"
Include dependency graph for flash_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FLASH_NUMBER_OF_FLASH_DEVICES   8
 
#define FLASH_CHIP_SIZE_BYTES   134217728
 
#define FLASH_CHIP_PAGES_PER_BLOCK   64
 
#define FLASH_MAX_BYTES_PER_PAGE   2048
 

Enumerations

enum  FLASH_error_enum_t {
  FLASH_ERR_OK = 0 , FLASH_ERR_SPI_TRANSMIT_FAILED = -3 , FLASH_ERR_SPI_RECEIVE_FAILED = -4 , FLASH_ERR_DEVICE_BUSY_TIMEOUT = -6 ,
  FLASH_ERR_UNKNOWN = -7 , FLASH_ERR_STATUS_REG_ERROR = -8 , FLASH_ERR_SPI_TRANSMIT_TIMEOUT = -10 , FLASH_ERR_SPI_RECEIVE_TIMEOUT = -11
}
 

Functions

void FLASH_activate_chip_select (uint8_t chip_number)
 Activates the chip select for the given flash module number.
 
void FLASH_deactivate_chip_select ()
 Deactivates the chip select for all lines.
 
FLASH_error_enum_t FLASH_unblock_block_lock (SPI_HandleTypeDef *hspi, uint8_t chip_number, uint8_t *buf)
 Unblocks all blocked blocks of memory on the NAND flash memory module.
 
FLASH_error_enum_t FLASH_read_status_register (SPI_HandleTypeDef *hspi, uint8_t chip_number, uint8_t *buf)
 Read Status Register and store the values in given buffer.
 
FLASH_error_enum_t FLASH_read_block_lock_register (SPI_HandleTypeDef *hspi, uint8_t chip_number, uint8_t *buf)
 Read Block Lock Register and store the values in given buffer.
 
FLASH_error_enum_t FLASH_write_enable (SPI_HandleTypeDef *hspi, uint8_t chip_number)
 Sends Write Enable Command.
 
FLASH_error_enum_t FLASH_write_disable (SPI_HandleTypeDef *hspi, uint8_t chip_number)
 Sends Write Disable Command.
 
FLASH_error_enum_t FLASH_erase (SPI_HandleTypeDef *hspi, uint8_t chip_number, lfs_block_t page)
 Sends Block Erase Command.
 
FLASH_error_enum_t FLASH_write_data (SPI_HandleTypeDef *hspi, uint8_t chip_number, lfs_block_t page, uint8_t *packet_buffer, lfs_size_t packet_buffer_len)
 Sends Page Program Command.
 
FLASH_error_enum_t FLASH_read_data (SPI_HandleTypeDef *hspi, uint8_t chip_number, lfs_block_t page, uint8_t *rx_buffer, lfs_size_t rx_buffer_len)
 Sends Page Read Command.
 
FLASH_error_enum_t FLASH_is_reachable (SPI_HandleTypeDef *hspi, uint8_t chip_number)
 Checks if the FLASH chip is reachable by checking it's ID.
 
FLASH_error_enum_t FLASH_reset (SPI_HandleTypeDef *hspi, uint8_t chip_number)
 Resets the NAND flash memory module.
 

Variables

static const uint8_t FLASH_FEAT_BLOCK_LOCK = 0xA0
 
static const uint8_t FLASH_FEAT_CONFIG = 0xB0
 
static const uint8_t FLASH_FEAT_STATUS = 0xC0
 
static const uint8_t FLASH_FEAT_DIE_SELECT = 0xD0
 
static const uint8_t FLASH_CMD_PAGE_READ = 0x13
 
static const uint8_t FLASH_CMD_READ_FROM_CACHE = 0x03
 
static const uint8_t FLASH_CMD_PROGRAM_LOAD = 0x02
 
static const uint8_t FLASH_CMD_PROGRAM_EXEC = 0x10
 
static const uint8_t FLASH_CMD_BLOCK_ERASE = 0xD8
 
static const uint8_t FLASH_CMD_WRITE_ENABLE = 0x06
 
static const uint8_t FLASH_CMD_WRITE_DISABLE = 0x04
 
static const uint8_t FLASH_CMD_GET_FEATURES = 0x0F
 
static const uint8_t FLASH_CMD_SET_FEATURES = 0x1F
 
static const uint8_t FLASH_CMD_READ_ID = 0x9F
 
static const uint8_t FLASH_CMD_RESET = 0xFF
 
static const uint8_t FLASH_SR1_WRITE_IN_PROGRESS_MASK = (1 << 0)
 
static const uint8_t FLASH_SR1_WRITE_ENABLE_LATCH_MASK = (1 << 1)
 
static const uint8_t FLASH_SR1_PROGRAMMING_ERROR_MASK = (1 << 3)
 
static const uint8_t FLASH_SR1_ERASE_ERROR_MASK = (1 << 2)
 

Macro Definition Documentation

◆ FLASH_CHIP_PAGES_PER_BLOCK

#define FLASH_CHIP_PAGES_PER_BLOCK   64

◆ FLASH_CHIP_SIZE_BYTES

#define FLASH_CHIP_SIZE_BYTES   134217728

◆ FLASH_MAX_BYTES_PER_PAGE

#define FLASH_MAX_BYTES_PER_PAGE   2048

◆ FLASH_NUMBER_OF_FLASH_DEVICES

#define FLASH_NUMBER_OF_FLASH_DEVICES   8

Enumeration Type Documentation

◆ FLASH_error_enum_t

Enumerator
FLASH_ERR_OK 
FLASH_ERR_SPI_TRANSMIT_FAILED 
FLASH_ERR_SPI_RECEIVE_FAILED 
FLASH_ERR_DEVICE_BUSY_TIMEOUT 
FLASH_ERR_UNKNOWN 
FLASH_ERR_STATUS_REG_ERROR 
FLASH_ERR_SPI_TRANSMIT_TIMEOUT 
FLASH_ERR_SPI_RECEIVE_TIMEOUT 

Function Documentation

◆ FLASH_activate_chip_select()

void FLASH_activate_chip_select ( uint8_t chip_number)

Activates the chip select for the given flash module number.

Parameters
chip_number- Index of the chip select line to activate

Activates the chip select for the given chip number by setting the corresponding GPIO pins LOW. Deactivates all other chip selects by setting their corresponding GPIO pins HIGH.

Returns
None - GPIO writes can't fail
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_deactivate_chip_select()

void FLASH_deactivate_chip_select ( )

Deactivates the chip select for all lines.

Returns
None - GPIO writes can't fail
Here is the caller graph for this function:

◆ FLASH_erase()

FLASH_error_enum_t FLASH_erase ( SPI_HandleTypeDef * hspi,
uint8_t chip_number,
lfs_block_t page )

Sends Block Erase Command.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
page- page number to erase the block the page is contained in
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_is_reachable()

FLASH_error_enum_t FLASH_is_reachable ( SPI_HandleTypeDef * hspi,
uint8_t chip_number )

Checks if the FLASH chip is reachable by checking it's ID.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- The chip select number to activate
Return values
FLASH_ERR_OK(0) on success, <0 on failure (from the FLASH_error_enum_t enum)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_read_block_lock_register()

FLASH_error_enum_t FLASH_read_block_lock_register ( SPI_HandleTypeDef * hspi,
uint8_t chip_number,
uint8_t * buf )

Read Block Lock Register and store the values in given buffer.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
buf- Pointer to a buffer to store Block Lock Register value. Length: 1 byte.
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_read_data()

FLASH_error_enum_t FLASH_read_data ( SPI_HandleTypeDef * hspi,
uint8_t chip_number,
lfs_block_t page,
uint8_t * rx_buffer,
lfs_size_t rx_buffer_len )

Sends Page Read Command.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- The chip select number to activate
page- page number to be read
rx_buffer- A buffer where the read data will be stored
rx_buffer_len- Integer that indicates the capacity of rx_buffer
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_read_status_register()

FLASH_error_enum_t FLASH_read_status_register ( SPI_HandleTypeDef * hspi,
uint8_t chip_number,
uint8_t * buf )

Read Status Register and store the values in given buffer.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
buf- Pointer to a buffer to store SR1 value. Length: 1 byte.
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_reset()

FLASH_error_enum_t FLASH_reset ( SPI_HandleTypeDef * hspi,
uint8_t chip_number )

Resets the NAND flash memory module.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- The chip select number to activate
Returns
FLASH_ERR_OK on success, <0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_unblock_block_lock()

FLASH_error_enum_t FLASH_unblock_block_lock ( SPI_HandleTypeDef * hspi,
uint8_t chip_number,
uint8_t * buf )

Unblocks all blocked blocks of memory on the NAND flash memory module.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
buf- Pointer to a buffer to store the new Block Lock Register value. Length: 1 byte.
Returns
FLASH_ERR_OK on success, < 0 on failure
Note
unblocking blocks of memory is necessary to write to memory
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_write_data()

FLASH_error_enum_t FLASH_write_data ( SPI_HandleTypeDef * hspi,
uint8_t chip_number,
lfs_block_t page,
uint8_t * packet_buffer,
lfs_size_t packet_buffer_len )

Sends Page Program Command.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
page- page number the data is to be written to
packet_buffer- Pointer to buffer containing data to write
packet_buffer_len- integer that indicates the size of the data to write
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_write_disable()

FLASH_error_enum_t FLASH_write_disable ( SPI_HandleTypeDef * hspi,
uint8_t chip_number )

Sends Write Disable Command.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:

◆ FLASH_write_enable()

FLASH_error_enum_t FLASH_write_enable ( SPI_HandleTypeDef * hspi,
uint8_t chip_number )

Sends Write Enable Command.

Parameters
hspi- Pointer to the SPI HAL handle
chip_number- the chip select number to activate
Returns
FLASH_ERR_OK on success, < 0 on failure
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ FLASH_CMD_BLOCK_ERASE

const uint8_t FLASH_CMD_BLOCK_ERASE = 0xD8
static

◆ FLASH_CMD_GET_FEATURES

const uint8_t FLASH_CMD_GET_FEATURES = 0x0F
static

◆ FLASH_CMD_PAGE_READ

const uint8_t FLASH_CMD_PAGE_READ = 0x13
static

◆ FLASH_CMD_PROGRAM_EXEC

const uint8_t FLASH_CMD_PROGRAM_EXEC = 0x10
static

◆ FLASH_CMD_PROGRAM_LOAD

const uint8_t FLASH_CMD_PROGRAM_LOAD = 0x02
static

◆ FLASH_CMD_READ_FROM_CACHE

const uint8_t FLASH_CMD_READ_FROM_CACHE = 0x03
static

◆ FLASH_CMD_READ_ID

const uint8_t FLASH_CMD_READ_ID = 0x9F
static

◆ FLASH_CMD_RESET

const uint8_t FLASH_CMD_RESET = 0xFF
static

◆ FLASH_CMD_SET_FEATURES

const uint8_t FLASH_CMD_SET_FEATURES = 0x1F
static

◆ FLASH_CMD_WRITE_DISABLE

const uint8_t FLASH_CMD_WRITE_DISABLE = 0x04
static

◆ FLASH_CMD_WRITE_ENABLE

const uint8_t FLASH_CMD_WRITE_ENABLE = 0x06
static

◆ FLASH_FEAT_BLOCK_LOCK

const uint8_t FLASH_FEAT_BLOCK_LOCK = 0xA0
static

◆ FLASH_FEAT_CONFIG

const uint8_t FLASH_FEAT_CONFIG = 0xB0
static

◆ FLASH_FEAT_DIE_SELECT

const uint8_t FLASH_FEAT_DIE_SELECT = 0xD0
static

◆ FLASH_FEAT_STATUS

const uint8_t FLASH_FEAT_STATUS = 0xC0
static

◆ FLASH_SR1_ERASE_ERROR_MASK

const uint8_t FLASH_SR1_ERASE_ERROR_MASK = (1 << 2)
static

◆ FLASH_SR1_PROGRAMMING_ERROR_MASK

const uint8_t FLASH_SR1_PROGRAMMING_ERROR_MASK = (1 << 3)
static

◆ FLASH_SR1_WRITE_ENABLE_LATCH_MASK

const uint8_t FLASH_SR1_WRITE_ENABLE_LATCH_MASK = (1 << 1)
static

◆ FLASH_SR1_WRITE_IN_PROGRESS_MASK

const uint8_t FLASH_SR1_WRITE_IN_PROGRESS_MASK = (1 << 0)
static