FLASH program reading during application running

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

Srikanth Vemula
Posts: 5
Joined: Tue Jan 20, 2015 8:03 am

FLASH program reading during application running

Tue Jan 20, 2015 8:13 am

We are using ATSAM4E16E-ANR microcontroller,which comes with the in-built bootloader. And we are using SAM-BA to program the Flash. As per our requirement, we need to calculate the checksum for the application code at the time of programming the Flash. And this checksum will be compared every time with the checksum calculated for the same code, on every power-ON for Flash validation.We want to know whether the flash reading is possible after completion of the programming of Flash as well as during the application running.If it is so, please provide the method in detailed explanation as soon as possible.
jarnoldbrown
Posts: 36
Joined: Thu Aug 22, 2013 5:31 pm

Re: FLASH program reading during application running

Tue Jan 20, 2015 1:04 pm

Yes. As far as I recall the Flash is readable without any special methods. It's just an area of memory. If you have been used to working with AVRs, then this might come as a shock to you.

I hope this is soon enough for you, albeit maybe not detailed enough...
Srikanth Vemula
Posts: 5
Joined: Tue Jan 20, 2015 8:03 am

Re: FLASH program reading during application running

Tue Jan 20, 2015 2:21 pm

Thanks for your reply.
I am worried about the reading of flash immediately after upgrading the flash, as we are using the SAM-BA to upgrade the flash. FYI, SAM-BA is GUI interface to program the flash. Flash reading is possible O.K.! But the requirement is the MC should read the Flash immediately after programming flash and add it's contents byte by byte as part of main application. Is there any way to do that without programming the boot-loader ?
jarnoldbrown
Posts: 36
Joined: Thu Aug 22, 2013 5:31 pm

Re: FLASH program reading during application running

Tue Jan 20, 2015 2:45 pm

Sorry, I don't understand your question. Surely you just need to write a function that add all the bytes in Flash, and call it at the start of main(). What you use to program the Flash is irrelevant, I would have thought.
Srikanth Vemula
Posts: 5
Joined: Tue Jan 20, 2015 8:03 am

Re: FLASH program reading during application running

Tue Jan 20, 2015 2:52 pm

Exactly!!!
I will write a function to read the flash byte by byte. that is O.K. But after adding all these bytes of flash, the result need to be compared with the result of the same process,which was carried out immediately after programming the Flash.Could you help me out in this aspect please...
jarnoldbrown
Posts: 36
Joined: Thu Aug 22, 2013 5:31 pm

Re: FLASH program reading during application running

Tue Jan 20, 2015 5:39 pm

I believe the usual method is to calculate the sum on the PC(or whatever is used to prepare the code), append that pre-calculated sum to the hex file(or binary or whatever), and then you can have your firmware do the same thing at the start of main(), and compare the result with the stored result.
Srikanth Vemula
Posts: 5
Joined: Tue Jan 20, 2015 8:03 am

Re: FLASH program reading during application running

Fri Jan 23, 2015 12:17 pm

If i'm not wrong, we can perform sum operation for the code, only if it in hex format. The hex file will be generated when the code will get compiled by the compiler.We are Atmel Studio IDE to develop the code and SAM-BA for programming the Flash. Immediately after programming the Flash using SAM-BA, we have read the code from Flash. We got .hex file. How the .hex file can be read to calculate the sum ? and can we append the same to the Flash? Even while reading back also we need to know the memory location right, but there is no provision to program to a specific location of Flash using SAM-BA. I think this info. is enough to you to understand the problem. Please provide exact the solution ASAP.
jarnoldbrown
Posts: 36
Joined: Thu Aug 22, 2013 5:31 pm

Re: FLASH program reading during application running

Sat Jan 24, 2015 10:23 am

"Please provide exact the solution ASAP."

If you are prepared to pay me £50 per hour I would be prepared to help you sort this out.

Alternatively, you'll have to do some reading to find out how .hex files work, and then find or write a utility to calculate and append a checksum. Lucky for you, .hex files do allow you to specify a location.
Oh, and don't forget to take into account that the .hex file does not represent all the blank (0xff) memory locations, so you will probably need the decode the .hex file into a binary image in an area of memory you have filled with 0xff, work out the sum, produce a line of .hex text, append it to the original .hex file, and then load with SAM BA.
Last edited by jarnoldbrown on Mon Jan 26, 2015 12:54 am, edited 1 time in total.
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: FLASH program reading during application running

Sun Jan 25, 2015 8:34 pm

Srikanth Vemula wrote:"Please provide exact the solution ASAP."
ROFLMAO :lol:

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests