Skip to content

Commit bbb97c8

Browse files
Karl ZhangKarl Zhang
authored andcommitted
Flash API: Enable Flash api on CM3DS
Implement flash_api.c for CM3DS on MPS2+. Because MPS2+ board has no physical flash chip, the implementation emulates flash over SRAM.
1 parent 5bf483e commit bbb97c8

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2017-2018 ARM Limited
3+
*
4+
* Licensed under the Apache License Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing software
11+
* distributed under the License is distributed on an "AS IS" BASIS
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "device.h"
18+
#include "flash_api.h"
19+
#include "memory_zones.h"
20+
21+
/* CM3DS is deployed on MPS2 board with an FPGA image (AN511).
22+
* It doesn't have physical flash memory,the implementation emulates
23+
* flash over SRAM.
24+
*/
25+
#define FLASH_PAGE_SIZE 256
26+
#define FLASH_OFS_START ZBT_SSRAM1_START
27+
#define FLASH_SECTOR_SIZE 0x1000
28+
#define FLASH_OFS_END (FLASH_OFS_START + FLASH_SIZE)
29+
30+
int32_t flash_init(flash_t *obj)
31+
{
32+
(void)obj;
33+
34+
return 0;
35+
}
36+
37+
int32_t flash_free(flash_t *obj)
38+
{
39+
(void)obj;
40+
41+
return 0;
42+
}
43+
44+
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
45+
{
46+
(void)obj;
47+
48+
memset((void *)address, 0xff, FLASH_SECTOR_SIZE);
49+
50+
return 0;
51+
}
52+
53+
int32_t flash_read(flash_t *obj, uint32_t address,
54+
uint8_t *data, uint32_t size)
55+
{
56+
(void)obj;
57+
58+
memcpy(data, (void *)address, size);
59+
60+
return 0;
61+
}
62+
63+
int32_t flash_program_page(flash_t *obj, uint32_t address,
64+
const uint8_t *data, uint32_t size)
65+
{
66+
(void)obj;
67+
68+
memcpy((void *)address, data, size);
69+
70+
return 0;
71+
}
72+
73+
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
74+
{
75+
(void)obj;
76+
77+
if (address < FLASH_OFS_START || address >= FLASH_OFS_END) {
78+
return MBED_FLASH_INVALID_SIZE;
79+
}
80+
81+
return FLASH_SECTOR_SIZE;
82+
}
83+
84+
uint32_t flash_get_page_size(const flash_t *obj)
85+
{
86+
(void)obj;
87+
88+
return FLASH_PAGE_SIZE;
89+
}
90+
91+
uint32_t flash_get_start_address(const flash_t *obj)
92+
{
93+
(void)obj;
94+
95+
return FLASH_OFS_START;
96+
}
97+
98+
uint32_t flash_get_size(const flash_t *obj)
99+
{
100+
(void)obj;
101+
102+
return FLASH_SIZE;
103+
}

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ struct analogin_s {
7070
uint16_t ctrl_register; /* Control bits with the channel identifier */
7171
};
7272

73+
/* This structure is not used by the HAL implementation. */
74+
struct flash_s {
75+
uint8_t not_used;
76+
};
77+
7378
/* This TRNG structure is not used by the HAL implementation. */
7479
struct trng_s {
7580
uint8_t not_used;

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2802,7 +2802,7 @@
28022802
"extra_labels": ["ARM_SSG", "CM3DS_MPS2"],
28032803
"OUTPUT_EXT": "elf",
28042804
"macros": ["CMSDK_CM3DS"],
2805-
"device_has": ["ANALOGIN", "ETHERNET", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI", "TRNG"],
2805+
"device_has": ["ANALOGIN", "ETHERNET", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SPI", "TRNG", "FLASH"],
28062806
"release_versions": ["2", "5"],
28072807
"copy_method": "mps2",
28082808
"reset_method": "reboot.txt"

0 commit comments

Comments
 (0)