Midnight Sun Firmware
Loading...
Searching...
No Matches
flash.h
1#pragma once
2
3/************************************************************************************************
4 * @file flash.h
5 *
6 * @brief Flash Library Header file
7 *
8 * @date 2024-11-05
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdint.h>
14
15/* Inter-component Headers */
16
17/* Intra-component Headers */
18#include "status.h"
19
27#define FLASH_MEMORY_ALIGNMENT 4U
28
30#define FLASH_BASE_ADDR (0x08000000U)
31
32#ifndef FLASH_PAGE_SIZE
34#define FLASH_PAGE_SIZE 0x800U
35#endif
36
38#define FLASH_PAGE_TO_ADDR(page) (FLASH_BASE_ADDR + ((page)*FLASH_PAGE_SIZE))
39
41#define FLASH_ADDR_TO_PAGE(addr) (((addr)-FLASH_BASE_ADDR) / FLASH_PAGE_SIZE)
42
44#define FLASH_TIMEOUT_MS 100U
45
47#define NUM_FLASH_PAGES 128U
48
54
64StatusCode flash_read(uintptr_t address, uint8_t *buffer, size_t buffer_len);
65
77StatusCode flash_write(uintptr_t address, uint8_t *buffer, size_t buffer_len);
78
87StatusCode flash_erase(uint8_t start_page, uint8_t num_pages);
88
StatusCode flash_read(uintptr_t address, uint8_t *buffer, size_t buffer_len)
Read from the flash memory and store data into a buffer.
Definition: flash.c:55
StatusCode flash_write(uintptr_t address, uint8_t *buffer, size_t buffer_len)
Write a buffer of data into the flash memory.
Definition: flash.c:73
StatusCode flash_init()
Initialize flash API.
Definition: flash.c:50
StatusCode flash_erase(uint8_t start_page, uint8_t num_pages)
Erase pages of flash memory.
Definition: flash.c:104
StatusCode
StatusCodes for various errors.
Definition: status.h:27