Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

FRTOS crashes when writing to internal flash

Posted by Allure99 on February 23, 2009
Using the internal flash of sam7x as to log data.

When running in debugging mode with Jtag connected, the code Run (alternately -> didn't run 1st time and after reset it will run and redet again it will stop running and so on).

Also it will not run in release mode(no debugger attached).

following are my Flash command code and it is in .fast section.

Any one can give me some hint how to get the Internal flash working properly in FreeRTOS.

Many Thanks!

//----------------------------------------------------------------------------

e_FLASH_Result Flash_Command(e_FLASH_Cmd cmd, const int page)
{

e_FLASH_Result ret_val = FLASH_FAIL;
unsigned int fcr_val = 0x0; //Value to be placed in MC_FCR.
unsigned int fsr_val; //FSR reg content.
AT91S_MC *pEfc; //pointer to EFC.

pEfc = AT91C_BASE_MC; // Base address of EFC0 registers.

portDISABLE_INTERRUPTS();
switch(cmd)
{
case FLASH_LOCK_PAGE:// Lock a page.

fcr_val = (0x5A << 24) | (page << 8) | 0x2;
pEfc->MC_FMR = (48 << 16) | AT91C_MC_FWS_3FWS;
break;

case FLASH_UNLOCK_PAGE:// Unlock a page.

fcr_val = (0x5A << 24) | (page << 8) | 0x4;
pEfc->MC_FMR = (48 << 16) | AT91C_MC_FWS_3FWS;
break;

case FLASH_ERASE_PAGE:// Erase a page of data - write all zeroes (not 0xff)!
case FLASH_WRITE_PAGE:// Write data to a page (which should be unlocked already).

fcr_val = (0x5A << 24) | (page << 8) | 0x1;
pEfc->MC_FMR = (72 << 16) | AT91C_MC_FWS_3FWS;
break;

default:

return ret_val;
break;
}

// Wait for flash to be ready.
do
{
fsr_val = pEfc->MC_FSR;
}
while ((fsr_val & AT91C_MC_FRDY) == 0);

// Now send command.
pEfc->MC_FCR = fcr_val;

// Wait for flash to be ready.
do
{
fsr_val = pEfc->MC_FSR;
}
while ((fsr_val & AT91C_MC_FRDY) == 0);

//Check for errors and return.
if((fsr_val = pEfc->MC_FSR) & (AT91C_MC_PROGE | AT91C_MC_LOCKE))
{
return ret_val; // Error shown in PROGE or LOCKE bits.
}

portENABLE_INTERRUPTS();
return FLASH_OK;
}
//---------------------------------------------------------------------------

RE: FRTOS crashes when writing to internal flash

Posted by Borut on February 23, 2009
Hello,

i had a simillar problem with LPC2148 and the problem was becasue i didn't disabled the IRQ's - while writing to the FLASH i had to disable the IRQ's because the IAP functions messed with the stack. Try this.

Best of luck,

Borut

RE: FRTOS crashes when writing to internal flash

Posted by mike on February 24, 2009
Hello

I am using the swam7s family, which has a single plane of flash memory, and you cannot write to the flash while attempting to read it. The actual write must be run from RAM.

I think the 7x family has multiple planes, but you cannot write to the plane which you are readinh from I think.

The IAR toolset has the __ram_func qualifier which will carry out actual write function:

static __ramfunc unsigned int
writeCommand (unsigned int page)
{
unsigned int status;
while (!(AT91C_BASE_MC->MC_FSR & AT91C_MC_FRDY))
/*EMPTY*/;

AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF; // probably unecessary!

AT91C_BASE_MC->MC_FCR = page | AT91C_MC_CORRECT_KEY;
do
{
status = AT91C_BASE_MC->MC_FSR;
}
while (!(status & AT91C_MC_FRDY))
/*EMPTY*/;
return status;
}

Hope this helps

Mike N

RE: FRTOS crashes when writing to internal flash

Posted by Allure99 on February 25, 2009
Hi Mike and Borut,


Thanks for the reply. However still no getting much Joy.

The Interrupt was disable and the WriteFlash function was in the RAM (.fast using Rowley CrossWorks).

It always crash in "dabort_handler:" 1st time round running with debugger and it will Run successfully if i resetting the debugging after crash(tried many time, the problem seem to be constant). but it never run without debugger.

Anyone have similar problem before or any help.

Thanks!

HS

RE: FRTOS crashes when writing to internal flash

Posted by Allure99 on February 27, 2009
problem seem to be disappear by having the flash function in with thing above + in ARM mode.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner