CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
stm32_internal_flash_telecommand_defs.c File Reference
#include "telecommands/stm32_internal_flash_telecommand_defs.h"
#include "telecommand_exec/telecommand_args_helpers.h"
#include "stm32/stm32_internal_flash_drivers.h"
#include "transforms/arrays.h"
#include "littlefs/littlefs_helper.h"
#include "log/log.h"
#include "stm32l4xx_hal.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
Include dependency graph for stm32_internal_flash_telecommand_defs.c:

Functions

uint8_t TCMDEXEC_stm32_internal_flash_write (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Write data to the internal flash bank starting from address 0x08100000.
uint8_t TCMDEXEC_stm32_internal_flash_read (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Read data from the internal flash bank.
uint8_t TCMDEXEC_stm32_internal_flash_page_erase (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Erase a range of pages in the internal flash bank.
uint8_t TCMDEXEC_stm32_internal_flash_bank_erase (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Erase an entire flash bank.
uint8_t TCMDEXEC_stm32_internal_flash_get_option_bytes (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Get the option bytes configuration from the stm32 internal flash memory.
uint8_t TCMDEXEC_stm32_internal_flash_set_active_flash_bank (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Given a 1 or 2, switches to the respective flash bank and runs the application stored there if present. Mostly useful for switching between 2 different version of the firmware (1 will be stored in Flash Bank 1, other will be stored in Flash Bank 2).
uint8_t TCMDEXEC_stm32_internal_flash_get_active_flash_bank (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Prints the active flash bank where the firmware boots from.
uint8_t TCMDEXEC_stm32_internal_flash_calculate_sha256 (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Calculates the SHA256 hash of a range of STM32 internal flash.
uint8_t TCMDEXEC_stm32_internal_flash_write_file_to_internal_flash (const char *args_str, char *response_output_buf, uint16_t response_output_buf_len)
 Telecommand: Write a file to internal flash memory from LittleFS.

Function Documentation

◆ TCMDEXEC_stm32_internal_flash_bank_erase()

uint8_t TCMDEXEC_stm32_internal_flash_bank_erase ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Erase an entire flash bank.

Parameters
args_str
  • Arg 0: Flash Bank to erase (1 or 2)
Returns
0 on success, > 0 on error
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_calculate_sha256()

uint8_t TCMDEXEC_stm32_internal_flash_calculate_sha256 ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Calculates the SHA256 hash of a range of STM32 internal flash.

Parameters
args_str
  • Arg 0: Start address in flash memory as uint32_t
  • Arg 1: Number of bytes to hash as uint32_t
response_output_bufOutputs the SHA256 hash as hex (wrapped in JSON)
Returns
0 on success, >0 on error
Note
Common useful values:
  • Start of BANK_1 (address): 0x08000000 = 134217728
  • Start of BANK_2 (address): 0x08100000 = 135266304
  • Length of each bank: 0x100000 = 1048576
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_get_active_flash_bank()

uint8_t TCMDEXEC_stm32_internal_flash_get_active_flash_bank ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Prints the active flash bank where the firmware boots from.

Parameters
response_output_bufPrints the active bank
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_get_option_bytes()

uint8_t TCMDEXEC_stm32_internal_flash_get_option_bytes ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Get the option bytes configuration from the stm32 internal flash memory.

Parameters
args_strNo args
Returns
0 on success, > 0 on error
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_page_erase()

uint8_t TCMDEXEC_stm32_internal_flash_page_erase ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Erase a range of pages in the internal flash bank.

Parameters
args_str
  • Arg 0: Flash Bank to erase (1 or 2)
  • Arg 1: The starting page to erase (0-255 for bank 1, 256-511 for bank 2)
  • Arg 2: The number of pages to erase (1-256)
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_read()

uint8_t TCMDEXEC_stm32_internal_flash_read ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Read data from the internal flash bank.

Parameters
args_str
  • Arg 0: The address to start reading from in hex
  • Arg 1: The number of bytes to read as a uint64_t
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_set_active_flash_bank()

uint8_t TCMDEXEC_stm32_internal_flash_set_active_flash_bank ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Given a 1 or 2, switches to the respective flash bank and runs the application stored there if present. Mostly useful for switching between 2 different version of the firmware (1 will be stored in Flash Bank 1, other will be stored in Flash Bank 2).

Parameters
args_str
  • Arg 0: A 1 or 2. 1 to switch to the application present in Flash Bank 1, 2 to switch to the application present in Flash Bank 2
response_output_bufPrints error if it occurs
Returns
0 on success, > 0 otherwise
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_write()

uint8_t TCMDEXEC_stm32_internal_flash_write ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Write data to the internal flash bank starting from address 0x08100000.

Parameters
args_str
  • Arg 0: Address to start writing from in hex format
  • Arg 1: The data in hex format to write up to PAGESIZE bytes (0x1000 bytes)
Note
This telecommand is only for testing purposes, it is purposfully not fully fleshed out as there is no intention on using this. Update as needed
Here is the call graph for this function:

◆ TCMDEXEC_stm32_internal_flash_write_file_to_internal_flash()

uint8_t TCMDEXEC_stm32_internal_flash_write_file_to_internal_flash ( const char * args_str,
char * response_output_buf,
uint16_t response_output_buf_len )

Telecommand: Write a file to internal flash memory from LittleFS.

Parameters
args_str
  • Arg 0: File name to read from LittleFS
  • Arg 1: Length to read from the file (in bytes). The maximum length to read is 4096 bytes (4kB).
  • Arg 2: Offset within the file to start reading (in bytes)
  • Arg 3: Address in internal flash memory to write to (in base 10)
Note
To use properly:
  • The internal flash memory region must be erased before writing.
  • The address must be in the main flash memory region (0x08000000 to 0x081FFFFF).
Here is the call graph for this function: