Skip to content

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 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/flash_api.c
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@0xc0170 0xc0170 Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the variable is reused for a different purpose. If it is not clear we can create a different variable.

Please do, should help clarify the intention of those 2 variables in this function.

The rest LGTM

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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ struct spi_s {
uint8_t bits;
};

#if DEVICE_FLASH
struct flash_s {
uint8_t dummy;
};
#endif

#include "gpio_object.h"

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
"macros": ["CPU_LPC54114J256BD64_cm4", "FSL_RTOS_MBED"],
"inherits": ["Target"],
"detect_code": ["1054"],
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
"release_versions": ["2", "5"],
"device_name" : "LPC54114J256BD64"
},
Expand All @@ -753,7 +753,7 @@
"is_disk_virtual": true,
"macros": ["CPU_LPC54628J512ET180", "FSL_RTOS_MBED"],
"inherits": ["Target"],
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "FLASH"],
"features": ["LWIP"],
"release_versions": ["2", "5"],
"device_name" : "LPC54628J512ET180"
Expand Down