CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
flash_driver.c File Reference
#include "main.h"
#include "littlefs/flash_driver.h"
#include "debug_tools/debug_uart.h"
#include "log/log.h"
#include "config/static_config.h"
Include dependency graph for flash_driver.c:

Macros

#define FLASH_HAL_TIMEOUT_MS   10
 Timeout duration for HAL_SPI_READ/WRITE operations.
 
#define FLASH_HAL_MAX_BYTE_TIMEOUT_MS   50
 
#define FLASH_LOOP_REGISTER_CHANGE_TIMEOUT_MS   10
 Duration to wait for the status register to show that Write Enable Latch changed status.
 
#define FLASH_LOOP_WRITE_TIMEOUT_MS   10
 Duration to wait for the status register to show that Write In Progress bit changed status, for writes.
 
#define FLASH_LOOP_SECTOR_ERASE_TIMEOUT_MS   4096
 Duration to wait for the status register to show that Write In Progress bit changed status, for erases.
 

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_reset (SPI_HandleTypeDef *hspi, uint8_t chip_number)
 Resets the NAND flash memory module.
 
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.
 

Macro Definition Documentation

◆ FLASH_HAL_MAX_BYTE_TIMEOUT_MS

#define FLASH_HAL_MAX_BYTE_TIMEOUT_MS   50

◆ FLASH_HAL_TIMEOUT_MS

#define FLASH_HAL_TIMEOUT_MS   10

Timeout duration for HAL_SPI_READ/WRITE operations.

◆ FLASH_LOOP_REGISTER_CHANGE_TIMEOUT_MS

#define FLASH_LOOP_REGISTER_CHANGE_TIMEOUT_MS   10

Duration to wait for the status register to show that Write Enable Latch changed status.

◆ FLASH_LOOP_SECTOR_ERASE_TIMEOUT_MS

#define FLASH_LOOP_SECTOR_ERASE_TIMEOUT_MS   4096

Duration to wait for the status register to show that Write In Progress bit changed status, for erases.

◆ FLASH_LOOP_WRITE_TIMEOUT_MS

#define FLASH_LOOP_WRITE_TIMEOUT_MS   10

Duration to wait for the status register to show that Write In Progress bit changed status, for writes.

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: