This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Write file to flash using uart

Hello

I am new to embedded programming and i have been trying to transfer a binary file and save it to flash memory using uart. The problem is that i do not know when to stop reading bytes from uart. That is because in my project the files do not have standard size , nor have a special char in the end. Is there any technique for this to be done. I am using keil compiler and a beautifully "datasheeted" c8051f320. The uart ISR for reading the file is the bellow:

INTERRUPT(Uart_Isr, INTERRUPT_UART0)
{
        if(RI0 == 1 ){

                LED = !LED;     //Blink LED  for each input
                RI0 = 0;        //Reset the uart read flag
                byte = SBUF0;                           //Store byte read
                flashBuffer[buffer_counter] = byte;     //save it to a FLASH buffer
                buffer_counter++;
                if(byte == 4){                                  //If End Of Transmition
                        fileTransfered = 1;
                        REN0 = 0;                                       //Disable RX
                }


        }
}

I also used a c script to write 0x4 (End of transmition byte or EOT) in the end of the files to be downloaded(weird but worked if the file had only char data).

Thank you in advance

P.S some more complex expressions dont seem to work , like
flashBuffer[buffer_counter+] = SBUF0;
Meaning that i get my code compiled but the program doesnt work

Parents
  • Thank you for the quick reply. That is indeed a nice solution. What do you mean by saying to make EOR detectable? Also(that is a bit off topic) my project is to run code to an mCU downloaded from uart using a binary file. Is there a standard technique for that? I have read about code banking and bootstrapping but i only see complicated stuff. I just want to do a JUMP to the address where the file is saved and continue running code from there.

Reply
  • Thank you for the quick reply. That is indeed a nice solution. What do you mean by saying to make EOR detectable? Also(that is a bit off topic) my project is to run code to an mCU downloaded from uart using a binary file. Is there a standard technique for that? I have read about code banking and bootstrapping but i only see complicated stuff. I just want to do a JUMP to the address where the file is saved and continue running code from there.

Children