px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_flash.h
1#ifndef __PX_FLASH_H__
2#define __PX_FLASH_H__
3/* =============================================================================
4 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
5 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
6 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
7 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
8 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
9
10 Copyright (c) 2018 Pieter Conradie <https://piconomix.com>
11
12 License: MIT
13 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
14
15 Title: px_flash.h : Internal FLASH write routines
16 Author(s): Pieter Conradie
17 Creation Date: 2018-11-21
18
19============================================================================= */
20
21/**
22 * @ingroup STM32
23 * @defgroup STM32_FLASH px_flash.h : Internal FLASH write routines
24 *
25 * This module can erase a page and write a half page of internal FLASH.
26 *
27 * File(s):
28 * - arch/arm/stm32/inc/px_flash.h
29 * - arch/arm/stm32/src/px_flash.c
30 *
31 * @note
32 * The flash erase and program functions must be executed from SRAM, not FLASH.
33 *
34 * @{
35 */
36
37/* _____STANDARD INCLUDES____________________________________________________ */
38
39/* _____PROJECT INCLUDES_____________________________________________________ */
40#include "px_defs.h"
41#include "px_stm32cube.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46/* _____DEFINITIONS__________________________________________________________ */
47#define PX_FLASH_BASE_ADR FLASH_BASE
48
49#if STM32G0
50#define PX_FLASH_PAGE_SIZE 2048
51#define PX_FLASH_ROW_SIZE 256
52#define PX_FLASH_ROW_SIZE_WORDS (PX_FLASH_ROW_SIZE / 4)
53#define PX_FLASH_ROW_SIZE_DOUBLE_WORDS (PX_FLASH_ROW_SIZE / 8)
54#endif
55
56#if STM32L0
57#define PX_FLASH_PAGE_SIZE 128
58#define PX_FLASH_HALF_PAGE_SIZE (PX_FLASH_PAGE_SIZE / 2)
59#define PX_FLASH_HALF_PAGE_SIZE_WORDS (PX_FLASH_HALF_PAGE_SIZE / 4)
60#endif
61
62/* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
63/**
64 * Unlock FLASH for programming and erase.
65 *
66 */
67void px_flash_unlock(void);
68
69/**
70 * Lock FLASH to prevent programming or erase.
71 *
72 */
73void px_flash_lock(void);
74
75/**
76 * Function to erase a page.
77 *
78 * @param adr Page address
79 */
80void px_flash_erase_page(uint32_t adr);
81
82#if STM32L0
83/**
84 * Function to write a half page.
85 *
86 * @param adr Half page address
87 * @param data Pointer to buffer containing data to write
88 */
89void px_flash_wr_half_page(uint32_t adr, const uint32_t * data);
90#endif
91
92#if STM32G0
93/**
94 * Function to write a row.
95 *
96 * @param adr Row address
97 * @param data Pointer to buffer containing data to write
98 */
99void px_flash_wr_row(uint32_t adr, const uint32_t * data);
100#endif
101
102/* _____MACROS_______________________________________________________________ */
103
104#ifdef __cplusplus
105}
106#endif
107
108/// @}
109#endif
void px_flash_unlock(void)
Unlock FLASH for programming and erase.
Definition: px_flash.c:40
void px_flash_erase_page(uint32_t adr)
Function to erase a page.
void px_flash_lock(void)
Lock FLASH to prevent programming or erase.
Definition: px_flash.c:64