Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists