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
The concept is to download and execute using uart a fully operative binary file and execute it on the mCu. This binary file is not a part of a program or function, this a file that if you download on a 'clean' 8051 would actually do something. In my project i want to transfer an executable file , stop the one that is running and run the transfered from uart one. I do not know how boot loader would be usefull for such operation.
What you are attempting is called "In-Application Programming" or "IAP" for short.
The fundamental problem with this on the 8051 architecture is that it has no means to write to the CODE space - so it is impossible without additional "tricks"...
You need to check the specific chip documentation carefully to see if it does provide any such "tricks"...
I have read this somewhere else too. I have also read some tricks like memory mapping but i haven't tried anything yet. So far the last two days i managed to write a program to download files to flash from uart. Anyways, if you happen to know any good 'tricks' for a c8051f320 from silabs i would be really happy if you shared them. Otherwise thank you very much for all the rest advice :)
Because the Flash is internal, there are no "tricks" that you can do yourself - you are totally reliant on what the manufacturer provides...
Because the Flash is internal, there are no "tricks" that you can do yourself
The F3xx have a sfr bit that makes xdata writes go to flash
The OP is actually talking of a bootloader which is possible with all SILabs chips (that I know of)
Erik
Searching again in silab's application notes page (www.silabs.com/.../ApplicationNotes.aspx) , i found one called "AN112 UART In-Application Code Loading Examples" that is an app similar to what i'm trying to do. I think this coding example should help me a lot understanding how iap on C8051Fxxx works. Thank you all for the replies.