Skip to content

Commit f207944

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
enable HAL FLASH API on Fast Models MPS2 targets
1 parent be215a3 commit f207944

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-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+
/* Fast Model FVP MPS2 is modeling after V2M-MPS2 platform with a FPGA (AN385).
22+
* The implementation emulates flash over SRAM.
23+
*/
24+
25+
#define FLASH_PAGE_SIZE 256
26+
#define FLASH_OFS_START FLASH_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+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
/*
18+
* This file contains the information of memory zones for code and data on
19+
* ARM Versatile Express Cortex-M Prototyping Systems (V2M-MPS2) TRM.
20+
* It is used in startup code and linker scripts of supported compilers (ARM and
21+
* GCC_ARM).
22+
*
23+
* WARNING: IAR does not include this file and re-define these values in
24+
* MPS2.icf file. Please make sure that the two files share the same values.
25+
*
26+
* These memory zones are defined in section 4.2 of ARM V2M-MPS2 RTL and
27+
* Fast Model Reference Guide.
28+
*/
29+
30+
#ifndef MEMORY_ZONES_H
31+
#define MEMORY_ZONES_H
32+
33+
/*
34+
* Code memory zones
35+
* Please note that MPS2 on Fast Models do not simulate persistent flash memory.
36+
* The FLASH memory zone is a 256 KiB SRAM block and named FLASH
37+
* only to keep the same name than in the CMSDK RTL and Fast Models Reference
38+
* Guide.
39+
*/
40+
#define FLASH_START 0x00000000
41+
#define FLASH_SIZE 0x00040000 /* 256 KiB */
42+
#define ZBT_SRAM1_START 0x00400000
43+
#define ZBT_SRAM1_SIZE 0x00400000 /* 4 MiB */
44+
45+
/* Data memory zones */
46+
#define ZBT_SRAM2_START 0x20000000
47+
#define ZBT_SRAM2_SIZE 0x00800000 /* 8 MiB */
48+
49+
#endif /* MEMORY_ZONES_H */
50+

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ struct analogin_s {
7373
__IO uint32_t address;
7474
};
7575

76+
/* This structure is not used by the HAL implementation. */
77+
struct flash_s {
78+
uint8_t not_used;
79+
};
80+
7681
#include "gpio_object.h"
7782

7883
#ifdef __cplusplus

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4239,7 +4239,7 @@
42394239
"public": false,
42404240
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
42414241
"OUTPUT_EXT": "elf",
4242-
"device_has": ["AACI", "ANALOGIN", "CLCD", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SERIAL_FC", "SPI", "SPISLAVE", "TSC", "USTICKER"],
4242+
"device_has": ["AACI", "ANALOGIN", "CLCD", "FLASH", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "SERIAL", "SERIAL_FC", "SPI", "SPISLAVE", "TSC", "USTICKER"],
42434243
"release_versions": ["5"]
42444244
},
42454245
"FVP_MPS2_M0": {

0 commit comments

Comments
 (0)