Skip to content

Commit 0d1bd37

Browse files
asmellby0xc0170
authored andcommitted
[Silicon Labs] Add flash API support
1 parent 8e76bf6 commit 0d1bd37

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
@@ -147,6 +147,11 @@ typedef enum {
147147
} sleepstate_enum;
148148
#endif
149149

150+
#if DEVICE_FLASH
151+
struct flash_s {
152+
MSC_TypeDef *msc;
153+
};
154+
#endif
150155

151156
#if DEVICE_TRNG
152157
struct trng_s {
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
@@ -2039,7 +2039,7 @@
20392039
"EFM32GG_STK3700": {
20402040
"inherits": ["EFM32GG990F1024"],
20412041
"progen": {"target": "efm32gg-stk"},
2042-
"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"],
2042+
"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"],
20432043
"forced_reset_timeout": 2,
20442044
"config": {
20452045
"hf_clock_src": {
@@ -2091,7 +2091,7 @@
20912091
},
20922092
"EFM32LG_STK3600": {
20932093
"inherits": ["EFM32LG990F256"],
2094-
"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"],
2094+
"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"],
20952095
"forced_reset_timeout": 2,
20962096
"device_name": "EFM32LG990F256",
20972097
"config": {
@@ -2145,7 +2145,7 @@
21452145
"EFM32WG_STK3800": {
21462146
"inherits": ["EFM32WG990F256"],
21472147
"progen": {"target": "efm32wg-stk"},
2148-
"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"],
2148+
"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"],
21492149
"forced_reset_timeout": 2,
21502150
"config": {
21512151
"hf_clock_src": {
@@ -2305,7 +2305,7 @@
23052305
},
23062306
"EFM32PG_STK3401": {
23072307
"inherits": ["EFM32PG1B100F256GM32"],
2308-
"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"],
2308+
"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"],
23092309
"forced_reset_timeout": 2,
23102310
"config": {
23112311
"hf_clock_src": {
@@ -2366,7 +2366,7 @@
23662366
},
23672367
"EFR32MG1_BRD4150": {
23682368
"inherits": ["EFR32MG1P132F256GM48"],
2369-
"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"],
2369+
"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"],
23702370
"forced_reset_timeout": 2,
23712371
"config": {
23722372
"hf_clock_src": {
@@ -2409,7 +2409,7 @@
24092409
},
24102410
"TB_SENSE_1": {
24112411
"inherits": ["EFR32MG1P233F256GM48"],
2412-
"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"],
2412+
"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"],
24132413
"forced_reset_timeout": 5,
24142414
"config": {
24152415
"hf_clock_src": {
@@ -2455,7 +2455,7 @@
24552455
},
24562456
"EFM32PG12_STK3402": {
24572457
"inherits": ["EFM32PG12B500F1024GL125"],
2458-
"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", "TRNG"],
2458+
"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", "TRNG", "FLASH"],
24592459
"forced_reset_timeout": 2,
24602460
"config": {
24612461
"hf_clock_src": {
@@ -2506,7 +2506,7 @@
25062506
},
25072507
"TB_SENSE_12": {
25082508
"inherits": ["EFR32MG12P332F1024GL125"],
2509-
"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", "TRNG"],
2509+
"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", "TRNG", "FLASH"],
25102510
"forced_reset_timeout": 5,
25112511
"config": {
25122512
"hf_clock_src": {

0 commit comments

Comments
 (0)