Escrita na Flash

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

Escrita na Flash

Mensagempor lafourcade » 25 Mar 2013 15:29

Eu estou usando um pic 24FJ256GB106 e uso a seguinte rotina para apagar e escrever na memoria:

cpp code
void EraseFlash (long progAddr)
{
//-----------------------------------------------------------------------------------------------------------//
//Rotina de Apagar a Memória
NVMCON = 0x4042;
TBLPAG = 0;
asm("tblwtl %0,[%0]"::"r"(progAddr));
__builtin_write_NVM();
while (NVMCON & 0x8000);
//-----------------------------------------------------------------------------------------------------------//
}

void WriteBufferFlash(long progAddr, int LenBuffer)
{
unsigned int offset, i;
// Set up NVMCON for word programming
//-----------------------------------------------------------------------------------------------------------//
//Rotina de Escrita na Memória
TBLPAG = progAddr >> 16; // Initialize PM Page Boundary SFR
// Set up pointer to the first memory location to be written
TBLPAG = progAddr >> 16; // Initialize PM Page Boundary SFR
offset = progAddr & 0xFFFF; // Initialize lower word of address
// Perform TBLWT instructions to write latches
asm("DISI #5");

for(i=0; i < LenBuffer; i++)
{
__builtin_tblwtl(offset, progData[i++]); // Write to address low word
__builtin_tblwth(offset, progData[i]); // Write to upper byte
offset += 2;
}

NVMCON = 0x4001; // Initialize NVMCON
__builtin_write_NVM(); // C30 function to perform unlock
while (NVMCON & 0x8000);
//-----------------------------------------------------------------------------------------------------------//
}


Em alguns momentos acontece de ficar travado no while (NVMCON & 0x8000); e nunca mais sai (esse bit é limpo por hardware). Eu preciso regravar o firmware e então ele consegue passar.
Estou desconfiado que ele pode estar escrevendo na memoria, reseta e tenta rodar a rotina de escrita novamente.

Alguém sabe dizer porque acontece?
Como eu limpo esse bit via firmware.

Obrigado a todos.

Obirgado
lafourcade
Byte
 
Mensagens: 123
Registrado em: 20 Out 2006 06:40

Re: Escrita na Flash

Mensagempor vtrx » 25 Mar 2013 19:43

Na página 62 do datasheet tem uma rotina que voce pode usar.
Avatar do usuário
vtrx
Dword
 
Mensagens: 2239
Registrado em: 20 Abr 2008 21:01


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

cron

x