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
115
116
117
118
119
120
121
|
/*****************************************************************************
* @file hw_flash.c
* @author MCD Application Team
* @brief This file contains the FLASH driver needed by EE module
*****************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
*****************************************************************************
*/
//#include "common.h"
#include "stm32_seq.h"
//#include "dbg_gpio.h"
#include "hw_flash.h"
#include "stm32wbxx_hal.h"
#include "flash_driver.h"
#include "app_common.h"
#include "shci.h"
#include "utilities_conf.h"
/*****************************************************************************/
int HW_FLASH_Write(uint32_t address, uint64_t data)
{
/**
* Take the semaphore to take ownership of the Flash IP
*/
while(LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID));
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR |FLASH_FLAG_PGSERR | FLASH_FLAG_OPTVERR);
/*Enable EOP interupt */
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
FD_WriteSingleData(address, data);
/* Disable EOP interrupt */
__HAL_FLASH_DISABLE_IT(FLASH_IT_EOP);
/* Clear the PG bit once data has been written */
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
HAL_FLASH_Lock();
/**
* Release the ownership of the Flash IP
*/
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, 0);
return (HW_OK);
}
/*****************************************************************************/
int HW_FLASH_Erase(uint32_t page, uint16_t n, int interrupt)
{
UNUSED(interrupt);
uint32_t loop;
/**
* Take the semaphore to take ownership of the Flash IP
*/
while(LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID));
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP |FLASH_FLAG_ALL_ERRORS);
/* Enable EOP interrupt */
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
/**
* Notify the CPU2 that some flash erase activity may be executed
* On reception of this command, the CPU2 enables the BLE timing protection versus flash erase processing
* The Erase flash activity will be executed only when the BLE RF is idle for at least 25ms
* The CPU2 will prevent all flash activity (write or erase) in all cases when the BL RF Idle is shorter than 25ms.
*/
SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_ON);
for( loop = 0; loop < n ; loop++)
{
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
FD_EraseSingleSector(page+loop);
}
/* Disable EOP interrupt */
__HAL_FLASH_DISABLE_IT(FLASH_IT_EOP);
/* Clear the page erase bit */
CLEAR_BIT(FLASH->CR, (FLASH_CR_PER | FLASH_CR_PNB));
/**
* Notify the CPU2 there will be no request anymore to erase the flash
* On reception of this command, the CPU2 disables the BLE timing protection versus flash erase processing
*/
SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
HAL_FLASH_Lock();
/**
* Release the ownership of the Flash IP
*/
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, 0);
return (HW_OK);
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE***/
|