blob: df6a00e1f52a102ec3217a35b6908e81994f3cc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
******************************************************************************
* @file HAL_EFlash.c
* @version V1.0.0
* @date 2020
* @brief EFlash HAL module driver.
* This file provides firmware functions to manage the following
* functionalities of the internal FLASH memory:
* @ Program operations functions
* @ Erase operations functions
******************************************************************************
*/
#include "ACM32Fxx_HAL.h"
/*********************************************************************************
* Function : HAL_EFlash_Init
* Description : Configure eflash parameter as system clock
* Input : system clock frequency
* Output : None
* Author : Chris_Kyle
**********************************************************************************/
void HAL_EFlash_Init(uint32_t fu32_freq)
{
HAL_EFlash_Init_Para(fu32_freq);
}
#if (__ACCELERATE_EH_PRESENT == 0)
/*********************************************************************************
* Function : HAL_EFlash_Erase_Page
* Description : Erase a Page, TERASE has been configured in System_Clock_Init()
* Input :
* Output : false: FAIL
true: SUCCESS
* Author : Chris_Kyle
**********************************************************************************/
bool HAL_EFlash_ErasePage(uint32_t fu32_Addr)
{
EFC->CTRL |= EFC_CTRL_PAGE_ERASE_MODE;
EFC->SEC = 0x55AAAA55;
*((volatile uint32_t *)fu32_Addr) = 0;
while (!(EFC->STATUS & EFC_STATUS_EFLASH_RDY));
EFC->CTRL &= ~EFC_CTRL_PAGE_ERASE_MODE;
return true;
}
/*********************************************************************************
* Function : HAL_EFlash_Programe
* Description : Program a word, TPROG has been configured in System_Clock_Init()
* Input :
* Output : false: FAIL
true: SUCCESS
* Author : Chris_Kyle
**********************************************************************************/
bool HAL_EFlash_Program_Word(uint32_t fu32_Addr, uint32_t fu32_Data)
{
if (fu32_Addr % 4)
{
return false;
}
EFC->CTRL |= EFC_CTRL_PROGRAM_MODE;
EFC->SEC = 0x55AAAA55;
*((volatile uint32_t *)fu32_Addr) = fu32_Data;
while (!(EFC->STATUS & EFC_STATUS_EFLASH_RDY));
EFC->CTRL &= ~EFC_CTRL_PROGRAM_MODE;
return true;
}
#else
/*********************************************************************************
* Function : HAL_EFlash_Erase_Page
* Description : Erase a Page, TERASE has been configured in System_Clock_Init()
* Input :
* Output : false: FAIL
true: SUCCESS
* Author : Chris_Kyle
**********************************************************************************/
bool HAL_EFlash_ErasePage(uint32_t fu32_Addr)
{
HAL_EFlash_ErasePage_EX(fu32_Addr);
return true;
}
/*********************************************************************************
* Function : HAL_EFlash_Programe
* Description : Program a word, TPROG has been configured in System_Clock_Init()
* Input :
* Output : false: FAIL
true: SUCCESS
* Author : Chris_Kyle
**********************************************************************************/
bool HAL_EFlash_Program_Word(uint32_t fu32_Addr, uint32_t fu32_Data)
{
if (fu32_Addr % 4)
{
return false;
}
HAL_EFlash_Program_Word_EX(fu32_Addr, fu32_Data);
return true;
}
#endif
|