Disable the MPU when flashing

When programming flash using the FlashIAP API allow execution from
ram. Many devices require flashing to be done from RAM.

Also allow execution from ram when running the low level flash tests.
pull/8871/head
Russ Butler 2018-10-18 16:18:32 -05:00 committed by Martin Kojtal
parent f44f87a196
commit c0ff98614a
2 changed files with 36 additions and 10 deletions

View File

@ -21,6 +21,7 @@
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "platform/mbed_mpu_mgmt.h"
#include "mbed.h"
#include "flash_api.h"
@ -251,11 +252,20 @@ Case cases[] = {
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
mbed_mpu_manager_lock_mem_xn();
GREENTEA_SETUP(20, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
void greentea_test_teardown(const size_t passed, const size_t failed, const failure_t failure)
{
mbed_mpu_manager_unlock_mem_xn();
greentea_test_teardown_handler(passed, failed, failure);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown);
int main()
{

View File

@ -25,6 +25,7 @@
#include <algorithm>
#include "FlashIAP.h"
#include "platform/mbed_assert.h"
#include "platform/MpuXnLock.h"
#ifdef DEVICE_FLASH
@ -56,8 +57,11 @@ int FlashIAP::init()
{
int ret = 0;
_mutex->lock();
if (flash_init(&_flash)) {
ret = -1;
{
MpuXnLock xn;
if (flash_init(&_flash)) {
ret = -1;
}
}
uint32_t page_size = get_page_size();
_page_buf = new uint8_t[page_size];
@ -70,8 +74,11 @@ int FlashIAP::deinit()
{
int ret = 0;
_mutex->lock();
if (flash_free(&_flash)) {
ret = -1;
{
MpuXnLock xn;
if (flash_free(&_flash)) {
ret = -1;
}
}
delete[] _page_buf;
_mutex->unlock();
@ -83,7 +90,10 @@ int FlashIAP::read(void *buffer, uint32_t addr, uint32_t size)
{
int32_t ret = -1;
_mutex->lock();
ret = flash_read(&_flash, addr, (uint8_t *) buffer, size);
{
MpuXnLock xn;
ret = flash_read(&_flash, addr, (uint8_t *) buffer, size);
}
_mutex->unlock();
return ret;
}
@ -126,9 +136,12 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
prog_buf = buf;
prog_size = chunk;
}
if (flash_program_page(&_flash, addr, prog_buf, prog_size)) {
ret = -1;
break;
{
MpuXnLock xn;
if (flash_program_page(&_flash, addr, prog_buf, prog_size)) {
ret = -1;
break;
}
}
size -= chunk;
addr += chunk;
@ -170,7 +183,10 @@ int FlashIAP::erase(uint32_t addr, uint32_t size)
int32_t ret = 0;
_mutex->lock();
while (size) {
ret = flash_erase_sector(&_flash, addr);
{
MpuXnLock xn;
ret = flash_erase_sector(&_flash, addr);
}
if (ret != 0) {
ret = -1;
break;