Skip to content

Commit 1afcbbf

Browse files
author
Cruz Monrreal
authored
Merge pull request #9316 from bentcooke/add_flash_MAX32620FTHR
Add FLASH support to TARGET_MAX32620C and brd targets
2 parents 436d3d0 + 95a050b commit 1afcbbf

File tree

4 files changed

+179
-1
lines changed

4 files changed

+179
-1
lines changed

targets/TARGET_Maxim/TARGET_MAX32620C/device/TOOLCHAIN_IAR/MAX32620.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
2020
}
2121

2222
define symbol __size_cstack__ = MBED_BOOT_STACK_SIZE;
23-
define symbol __size_heap__ = 0x4000;
23+
define symbol __size_heap__ = 0xF000;
2424
define block CSTACK with alignment = 8, size = __size_cstack__ { };
2525
define block HEAP with alignment = 8, size = __size_heap__ { };
2626

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
18+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* Except as contained in this notice, the name of Maxim Integrated
23+
* Products, Inc. shall not be used except as stated in the Maxim Integrated
24+
* Products, Inc. Branding Policy.
25+
*
26+
* The mere transfer of this software does not imply any licenses
27+
* of trade secrets, proprietary technology, copyrights, patents,
28+
* trademarks, maskwork rights, or any other form of intellectual
29+
* property whatsoever. Maxim Integrated Products, Inc. retains all
30+
* ownership rights.
31+
*******************************************************************************
32+
*/
33+
34+
#if DEVICE_FLASH
35+
#include "flash_api.h"
36+
#include "mbed_critical.h"
37+
#include "cmsis.h"
38+
#include "flc.h"
39+
40+
41+
/**
42+
* * \defgroup flash_hal Flash HAL API
43+
* * @{
44+
* */
45+
46+
/** Initialize the flash peripheral and the flash_t object
47+
* *
48+
* * @param obj The flash object
49+
* * @return 0 for success, -1 for error
50+
* */
51+
int32_t flash_init(flash_t *obj)
52+
{
53+
return FLC_Init();
54+
}
55+
56+
/** Uninitialize the flash peripheral and the flash_t object
57+
* *
58+
* * @param obj The flash object
59+
* * @return 0 for success, -1 for error
60+
* */
61+
int32_t flash_free(flash_t *obj)
62+
{
63+
return 0;
64+
}
65+
66+
/** Erase one sector starting at defined address
67+
* *
68+
* * The address should be at sector boundary. This function does not do any check for address alignments
69+
* * @param obj The flash object
70+
* * @param address The sector starting address
71+
* * @return 0 for success, -1 for error
72+
* */
73+
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
74+
{
75+
if(FLC_PageErase(address, MXC_V_FLC_ERASE_CODE_PAGE_ERASE, MXC_V_FLC_FLSH_UNLOCK_KEY) != 0)
76+
{
77+
return -1;
78+
} else {
79+
return 0;
80+
}
81+
82+
}
83+
84+
/** Program pages starting at defined address
85+
* *
86+
* * The pages should not cross multiple sectors.
87+
* * This function does not do any check for address alignments or if size is aligned to a page size.
88+
* * @param obj The flash object
89+
* * @param address The sector starting address
90+
* * @param data The data buffer to be programmed
91+
* * @param size The number of bytes to program
92+
* * @return 0 for success, -1 for error
93+
* */
94+
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
95+
{
96+
int32_t status = E_BUSY;
97+
98+
while ( status == E_BUSY )
99+
{
100+
status = FLC_Write(address, data, size, MXC_V_FLC_FLSH_UNLOCK_KEY);
101+
}
102+
103+
if (status != 0)
104+
{
105+
return -1;
106+
} else {
107+
return 0;
108+
}
109+
110+
}
111+
112+
/** Get sector size
113+
* *
114+
* * @param obj The flash object
115+
* * @param address The sector starting address
116+
* * @return The size of a sector
117+
* */
118+
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
119+
{
120+
/* 1 sector = 1 page */
121+
if (address >= (MXC_FLASH_MEM_BASE + MXC_FLASH_FULL_MEM_SIZE)) {
122+
return MBED_FLASH_INVALID_SIZE;
123+
} else {
124+
return MXC_FLASH_PAGE_SIZE;
125+
}
126+
}
127+
128+
/** Get page size
129+
* *
130+
* * The page size defines the writable page size
131+
* * @param obj The flash object
132+
* * @return The size of a page
133+
* */
134+
uint32_t flash_get_page_size(const flash_t *obj)
135+
{
136+
return MXC_FLASH_PAGE_SIZE;
137+
}
138+
139+
/** Get start address for the flash region
140+
* *
141+
* * @param obj The flash object
142+
* * @return The start address for the flash region
143+
* */
144+
uint32_t flash_get_start_address(const flash_t *obj)
145+
{
146+
return MXC_FLASH_MEM_BASE;
147+
}
148+
149+
/** Get the flash region size
150+
* *
151+
* * @param obj The flash object
152+
* * @return The flash region size
153+
* */
154+
uint32_t flash_get_size(const flash_t *obj)
155+
{
156+
return MXC_FLASH_FULL_MEM_SIZE;
157+
}
158+
159+
/** Get the flash erase value
160+
* *
161+
* * @param obj The flash object
162+
* * @return The flash erase value
163+
* */
164+
uint8_t flash_get_erase_value(const flash_t *obj)
165+
{
166+
(void)obj;
167+
168+
return 0xFF;
169+
}
170+
171+
#endif
172+

targets/TARGET_Maxim/TARGET_MAX32620C/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ struct port_s {
6161
PinMode mode;
6262
};
6363

64+
struct flash_s {
65+
uint8_t notused;
66+
};
67+
6468
struct gpio_irq_s {
6569
uint8_t port;
6670
uint8_t pin;

targets/targets.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5237,6 +5237,7 @@
52375237
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
52385238
"device_has": [
52395239
"ANALOGIN",
5240+
"FLASH",
52405241
"I2C",
52415242
"INTERRUPTIN",
52425243
"LPTICKER",
@@ -5267,6 +5268,7 @@
52675268
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
52685269
"device_has": [
52695270
"ANALOGIN",
5271+
"FLASH",
52705272
"I2C",
52715273
"INTERRUPTIN",
52725274
"LPTICKER",

0 commit comments

Comments
 (0)