j'ai programmé un petit bout de code qui permet de modifier la partie flash de mon microcontroleur. il marche correctement et j'arrive en envoyant le fichier .hex (découper en 3 sous fichier .hex de 256octets) par RS232 a changer la partie application.
voici mon code : (il n'est pas du tout optimal car je test dans un premier temps la faisabilité)
int main(void)
{
unsigned char finalbuffer[NBR_LIGNES][32];
unsigned char finalbufferpage3[1][32];
unsigned char finalpage1[256];
unsigned char finalpage2[256];
unsigned char finalpage3[256];
int j,y;
int indice;
int indicefinal;
toto=0;
// Set the interrupt vector to the start of the bootflash
cli(); // disable interrupt in order to move the interrupt vector
MCUCR = (1<<IVCE);
MCUCR = (1<<IVSEL);
sei(); //re-enable the interrupt
initIO();
initUSART1();
initVariateur(); //Initialise le variateur pour que le moteur reste bloqué pendant une mise à jour soft.
while(1)
{
PORTJ &= ~(1<<LED1);
PORTJ &= ~(1<<LED2);
PORTJ &= ~(1<<LED3);
PORTJ &= ~(1<<LED4);
while( toto<718 );
if (toto >= 718)
{
indice=0;
for(j=0;j<NBR_LIGNES;j++)
{
indice+=9;
for(y=0;y<32;y++)
{
finalbuffer[j][y] = buffer[indice];
indice++;
}
indice+=4;
}
indicefinal=0;
for(j=0;j<NBR_LIGNES;j++)
{
for(y=0;y<16;y++)
{
finalpage1[indicefinal] = asciitohexa(finalbuffer[j][y*2],finalbuffer[j][(y*2)+1]);
indicefinal++;
}
}
boot_program_page(0,finalpage1);
toto=0;
}
while( toto<718 );
if (toto >= 718)
{
indice=0;
for(j=0;j<NBR_LIGNES;j++)
{
indice+=9;
for(y=0;y<32;y++)
{
finalbuffer[j][y] = buffer[indice];
indice++;
}
indice+=4;
}
indicefinal=0;
for(j=0;j<NBR_LIGNES;j++)
{
for(y=0;y<16;y++)
{
finalpage2[indicefinal] = asciitohexa(finalbuffer[j][y*2],finalbuffer[j][(y*2)+1]);
indicefinal++;
}
}
boot_program_page(256,finalpage2);
toto=0;
}
while( toto<52 );
if (toto >= 52)
{
indice=0;
for(j=0;j<1;j++)
{
indice+=9;
for(y=0;y<28;y++)
{
finalbufferpage3[j][y] = buffer[indice];
indice++;
}
indice+=4;
}
indicefinal=0;
for(j=0;j<1;j++)
{
for(y=0;y<14;y++)
{
finalpage3[indicefinal] = asciitohexa(finalbufferpage3[j][y*2],finalbufferpage3[j][(y*2)+1]);
indicefinal++;
}
}
boot_program_page(512,finalpage3);
toto=0;
}
}
return 0;
}
aurait-tu une idéé pour prendre en compte toute les données du fichier .hex? et ne pas sauter le start code, byte count etc... comme je le fait dans mon code?