Skip to content

Commit 545a42f

Browse files
authored
Merge pull request #4037 from akselsm/feature/efm32-flash-api-support
[Silicon Labs] Add flash HAL API support
2 parents ea1306d + 2f6e37a commit 545a42f

File tree

3 files changed

+151
-8
lines changed

3 files changed

+151
-8
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/common/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ typedef enum {
145145
} sleepstate_enum;
146146
#endif
147147

148+
#if DEVICE_FLASH
149+
struct flash_s {
150+
MSC_TypeDef *msc;
151+
};
152+
#endif
148153

149154
#ifdef __cplusplus
150155
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/***************************************************************************//**
2+
* @file flash_api.c
3+
*******************************************************************************
4+
* @section License
5+
* <b>Copyright 2017 Silicon Laboratories, Inc. http://www.silabs.com</b>
6+
*******************************************************************************
7+
*
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*
22+
******************************************************************************/
23+
24+
#include "device.h"
25+
#if DEVICE_FLASH
26+
27+
#include "flash_api.h"
28+
#include "em_msc.h"
29+
30+
/** Initialize the flash peripheral and the flash_t object
31+
*
32+
* @param obj The flash object
33+
* @return 0 for success, -1 for error
34+
*/
35+
int32_t flash_init(flash_t *obj)
36+
{
37+
(void)obj;
38+
return 0;
39+
}
40+
41+
/** Uninitialize the flash peripheral and the flash_t object
42+
*
43+
* @param obj The flash object
44+
* @return 0 for success, -1 for error
45+
*/
46+
int32_t flash_free(flash_t *obj)
47+
{
48+
(void)obj;
49+
return 0;
50+
}
51+
52+
/** Erase one sector starting at defined address
53+
*
54+
* The address should be at sector boundary. This function does not do any check for address alignments
55+
* @param obj The flash object
56+
* @param address The sector starting address
57+
* @return 0 for success, -1 for error
58+
*/
59+
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
60+
{
61+
(void)obj;
62+
MSC_Status_TypeDef mscStatus = MSC_ErasePage((uint32_t *)address);
63+
64+
return (mscStatus == mscReturnOk) ? 0 : -1;
65+
}
66+
67+
/** Program one page starting at defined address
68+
*
69+
* The page should be at page boundary, should not cross multiple sectors.
70+
* This function does not do any check for address alignments or if size is aligned to a page size.
71+
* @param obj The flash object
72+
* @param address The sector starting address
73+
* @param data The data buffer to be programmed
74+
* @param size The number of bytes to program
75+
* @return 0 for success, -1 for error
76+
*/
77+
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
78+
{
79+
(void)obj;
80+
MSC_Status_TypeDef mscStatus = MSC_WriteWord((uint32_t *)address, data, size);
81+
82+
return (mscStatus == mscReturnOk) ? 0 : -1;
83+
}
84+
85+
/** Get sector size
86+
*
87+
* @param obj The flash object
88+
* @param address The sector starting address
89+
* @return The size of a sector
90+
*/
91+
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
92+
{
93+
(void)obj;
94+
(void)address;
95+
96+
if (address < FLASH_BASE || address >= FLASH_BASE + FLASH_SIZE) {
97+
// Address outside of flash -- invalid sector
98+
return MBED_FLASH_INVALID_SIZE;
99+
}
100+
101+
return FLASH_PAGE_SIZE;
102+
}
103+
104+
/** Get page size
105+
*
106+
* @param obj The flash object
107+
* @param address The page starting address
108+
* @return The size of a page
109+
*/
110+
uint32_t flash_get_page_size(const flash_t *obj)
111+
{
112+
(void)obj;
113+
return FLASH_PAGE_SIZE;
114+
}
115+
116+
/** Get start address for the flash region
117+
*
118+
* @param obj The flash object
119+
* @return The start address for the flash region
120+
*/
121+
uint32_t flash_get_start_address(const flash_t *obj)
122+
{
123+
(void)obj;
124+
return FLASH_BASE;
125+
}
126+
127+
/** Get the flash region size
128+
*
129+
* @param obj The flash object
130+
* @return The flash region size
131+
*/
132+
uint32_t flash_get_size(const flash_t *obj)
133+
{
134+
(void)obj;
135+
return FLASH_SIZE;
136+
}
137+
138+
#endif // DEVICE_FLASH

targets/targets.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@
19311931
"EFM32GG_STK3700": {
19321932
"inherits": ["EFM32GG990F1024"],
19331933
"progen": {"target": "efm32gg-stk"},
1934-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
1934+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
19351935
"forced_reset_timeout": 2,
19361936
"config": {
19371937
"hf_clock_src": {
@@ -1983,7 +1983,7 @@
19831983
},
19841984
"EFM32LG_STK3600": {
19851985
"inherits": ["EFM32LG990F256"],
1986-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
1986+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
19871987
"forced_reset_timeout": 2,
19881988
"device_name": "EFM32LG990F256",
19891989
"config": {
@@ -2037,7 +2037,7 @@
20372037
"EFM32WG_STK3800": {
20382038
"inherits": ["EFM32WG990F256"],
20392039
"progen": {"target": "efm32wg-stk"},
2040-
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2040+
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
20412041
"forced_reset_timeout": 2,
20422042
"config": {
20432043
"hf_clock_src": {
@@ -2197,7 +2197,7 @@
21972197
},
21982198
"EFM32PG_STK3401": {
21992199
"inherits": ["EFM32PG1B100F256GM32"],
2200-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2200+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
22012201
"forced_reset_timeout": 2,
22022202
"config": {
22032203
"hf_clock_src": {
@@ -2258,7 +2258,7 @@
22582258
},
22592259
"EFR32MG1_BRD4150": {
22602260
"inherits": ["EFR32MG1P132F256GM48"],
2261-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2261+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
22622262
"forced_reset_timeout": 2,
22632263
"config": {
22642264
"hf_clock_src": {
@@ -2301,7 +2301,7 @@
23012301
},
23022302
"THUNDERBOARD_SENSE": {
23032303
"inherits": ["EFR32MG1P233F256GM48"],
2304-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2304+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
23052305
"forced_reset_timeout": 5,
23062306
"config": {
23072307
"hf_clock_src": {
@@ -2347,7 +2347,7 @@
23472347
},
23482348
"EFM32PG12_STK3402": {
23492349
"inherits": ["EFM32PG12B500F1024GL125"],
2350-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2350+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
23512351
"forced_reset_timeout": 2,
23522352
"config": {
23532353
"hf_clock_src": {
@@ -2398,7 +2398,7 @@
23982398
},
23992399
"THUNDERBOARD_SENSE_12": {
24002400
"inherits": ["EFR32MG12P332F1024GL125"],
2401-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
2401+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "FLASH"],
24022402
"forced_reset_timeout": 5,
24032403
"config": {
24042404
"hf_clock_src": {

0 commit comments

Comments
 (0)