-
Notifications
You must be signed in to change notification settings - Fork 3k
Flash support: Add flash support for LPC54114 & LPC546XX #6198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/flash_api.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2018 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "flash_api.h" | ||
#include "mbed_critical.h" | ||
|
||
#if DEVICE_FLASH | ||
|
||
#include "fsl_flashiap.h" | ||
|
||
int32_t flash_init(flash_t *obj) | ||
{ | ||
return 0; | ||
} | ||
|
||
int32_t flash_free(flash_t *obj) | ||
{ | ||
return 0; | ||
} | ||
|
||
int32_t flash_erase_sector(flash_t *obj, uint32_t address) | ||
{ | ||
uint32_t n; | ||
uint32_t status; | ||
int32_t ret = -1; | ||
|
||
/* We need to prevent flash accesses during erase operation */ | ||
core_util_critical_section_enter(); | ||
|
||
n = address / FSL_FEATURE_SYSCON_FLASH_SECTOR_SIZE_BYTES; // Get Sector Number | ||
|
||
status = FLASHIAP_PrepareSectorForWrite(n, n); | ||
if (status == kStatus_FLASHIAP_Success) { | ||
status = FLASHIAP_EraseSector(n, n, SystemCoreClock); | ||
if (status == kStatus_FLASHIAP_Success) { | ||
ret = 0; | ||
} | ||
} | ||
|
||
core_util_critical_section_exit(); | ||
|
||
return ret; | ||
} | ||
|
||
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size) | ||
{ | ||
uint32_t n; | ||
uint32_t sector_number; | ||
|
||
uint32_t status; | ||
int32_t ret = -1; | ||
uint8_t buf[FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES]; | ||
|
||
if (address == 0) { // Check for Vector Table | ||
n = *((unsigned long *)(data + 0)) + | ||
*((unsigned long *)(data + 1)) + | ||
*((unsigned long *)(data + 2)) + | ||
*((unsigned long *)(data + 3)) + | ||
*((unsigned long *)(data + 4)) + | ||
*((unsigned long *)(data + 5)) + | ||
*((unsigned long *)(data + 6)); | ||
*((unsigned long *)(data + 7)) = 0 - n; // Signature at Reserved Vector | ||
} | ||
|
||
/* Copy into a local buffer to ensure address is word-aligned */ | ||
memcpy(&buf, data, FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES); | ||
|
||
/* We need to prevent flash accesses during program operation */ | ||
core_util_critical_section_enter(); | ||
|
||
sector_number = address / FSL_FEATURE_SYSCON_FLASH_SECTOR_SIZE_BYTES; // Get Sector Number | ||
|
||
status = FLASHIAP_PrepareSectorForWrite(sector_number, sector_number); | ||
if (status == kStatus_FLASHIAP_Success) { | ||
status = FLASHIAP_CopyRamToFlash(address, (uint32_t *)&buf, | ||
FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES, SystemCoreClock); | ||
if (status == kStatus_FLASHIAP_Success) { | ||
ret = 0; | ||
} | ||
} | ||
|
||
core_util_critical_section_exit(); | ||
|
||
return ret; | ||
} | ||
|
||
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) | ||
{ | ||
uint32_t sectorsize = MBED_FLASH_INVALID_SIZE; | ||
uint32_t devicesize = FSL_FEATURE_SYSCON_FLASH_SIZE_BYTES; | ||
uint32_t startaddr = 0; | ||
|
||
if ((address >= startaddr) && (address < (startaddr + devicesize))) { | ||
sectorsize = FSL_FEATURE_SYSCON_FLASH_SECTOR_SIZE_BYTES; | ||
} | ||
|
||
return sectorsize; | ||
} | ||
|
||
uint32_t flash_get_page_size(const flash_t *obj) | ||
{ | ||
return FSL_FEATURE_SYSCON_FLASH_PAGE_SIZE_BYTES; | ||
} | ||
|
||
uint32_t flash_get_start_address(const flash_t *obj) | ||
{ | ||
uint32_t startaddr = 0; | ||
|
||
return startaddr; | ||
} | ||
|
||
uint32_t flash_get_size(const flash_t *obj) | ||
{ | ||
return FSL_FEATURE_SYSCON_FLASH_SIZE_BYTES; | ||
} | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work with bootloader, or does not have any affect? (not sure what
n
represents)From the code,
n
gets overwritten on line 81 (is it just reusing the variable? wouldn't it be more clear to have two separate ?n
on the line 81 represents sector number, here on this line it is signature calculation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is required by the ROM bootflow.
0x1C Vector checksum (set by tool vendors).
You are right, the variable is reused for a different purpose. If it is not clear we can create a different variable.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do, should help clarify the intention of those 2 variables in this function.
The rest LGTM