Forums

Reprogramming a uC FLASH while running code - STM32F

Started by John-Smith May 10, 2014
I have used a variety of different micros (Z80 onwards) since about
1980 but all the PROM or FLASH based ones (e.g. H8/300 or Atmel
90S1200) were programmed externally, via a spring-contact adaptor.

We have one product using an H8/300 with an external 28C256 32kbyte
parallel EEPROM for extra code, and we quickly found this could not be
written with code running in it! No sh*t Sherlock, as they say here in
the UK, but it took a good hour or two to realise why... The reason of
course is what while the EEPROM is executing its programming cycle, it
isn't readable for code and data fetching.

I am now looking at a new uP for another project and it is the ST ARM
STM32F range. For about a tenner you can get 1MB of on-chip FLASH
which is loads.

But how can one program this in situ?

Either there is a separate FLASH segment which remains available all
the time (how is that programmed?) or one has to load a loader into
the SRAM and execute it from there.

How do people typically do this?

I don't think the chip needs an elevated Vpp for programming - that
would really complicate things. I think some of the old Atmels needed
that.

Could anyone suggest the best developer kit for the 32F, for assembler
and C programming?
On 10.5.14 13:16, John-Smith wrote:
> I have used a variety of different micros (Z80 onwards) since about > 1980 but all the PROM or FLASH based ones (e.g. H8/300 or Atmel > 90S1200) were programmed externally, via a spring-contact adaptor. > > We have one product using an H8/300 with an external 28C256 32kbyte > parallel EEPROM for extra code, and we quickly found this could not be > written with code running in it! No sh*t Sherlock, as they say here in > the UK, but it took a good hour or two to realise why... The reason of > course is what while the EEPROM is executing its programming cycle, it > isn't readable for code and data fetching. > > I am now looking at a new uP for another project and it is the ST ARM > STM32F range. For about a tenner you can get 1MB of on-chip FLASH > which is loads. > > But how can one program this in situ? > > Either there is a separate FLASH segment which remains available all > the time (how is that programmed?) or one has to load a loader into > the SRAM and execute it from there. > > How do people typically do this?
Put the innermost code into RAM for the time of programming. Of course, you need also have the block of data to program in the same RAM. Only the code to do the programming and polling for ready needs to be in RAM (while the Flash is not accessible), other code can be in the Flash.
> I don't think the chip needs an elevated Vpp for programming - that > would really complicate things. I think some of the old Atmels needed > that.
At least those I have used can be programmed with the normal supply voltages.
> Could anyone suggest the best developer kit for the 32F, for assembler > and C programming?
I have used the GNU tool set, for Cortex-M. My selection for an IDE is Eclipse. Get a ST dev board for the processor (or some similar enough). The simple boards are cheap, and they can double as USB-to-JTAG adapters. For JTAG, I'm using OpenOCD. -- Tauno Voipio
John-Smith <noospam@noospam.com> wrote:

 >course is what while the EEPROM is executing its programming cycle, it
 >isn't readable for code and data fetching.

This is normal behavior for all controller I know, and I know many. :-)


 >But how can one program this in situ?

 >Either there is a separate FLASH segment which remains available all
 >the time (how is that programmed?) or one has to load a loader into
 >the SRAM and execute it from there.

Both is possible. When you read the data sheet of your controller you
will find that the flash is segmented in parts. It is very common to
use one segment for a bootloader that is written by yourself to
programm all the other segment.

And it is very common that there is another segment with a bootloader
that can only programmed by the manfuacturer with there own
bootloader.  

Of course it is also possible to copy a program from flash to ram and
start the program in ram. Than this program can delete and program the
flash. But it is dangerous, because you should not switch it of at
this point.

 >How do people typically do this?

That depends on the application. A good application from a good
company never need to flash in the field because it is well tested and
without errors. :-)

 >I don't think the chip needs an elevated Vpp for programming - that
 >would really complicate things. I think some of the old Atmels needed
 >that.

The chip needs a higher voltage, but it has an internal
boostconverter. So it means if you flash a new program by bootloader
it need more power for a short time.

 >Could anyone suggest the best developer kit for the 32F, for assembler
 >and C programming?

Buy one of the application kits from ST. They are cheap and the
debugger you will need to develope is for free, too. 
There is also a free enviroment for developement from IAR, but it is
codesize limited and the look and feel is a pain in the ass. You can
use the gcc too. In this case most people using Eclipse. The look and
feel for Eclipse is nice, but it needs a fast computer, because it is
java-crap and it is very complicate, without logic and behind humans
brains, what happens inside Eclipse.

Perhaps Assembler is possible, too. But nobody use it anymore. (with a
very few exceptions)

Olaf

Tauno Voipio <tauno.voipio@notused.fi.invalid> wrote

>I have used the GNU tool set, for Cortex-M. My selection for >an IDE is Eclipse. > >Get a ST dev board for the processor (or some similar enough). >The simple boards are cheap, and they can double as USB-to-JTAG >adapters. > >For JTAG, I'm using OpenOCD.
Many thanks (both of you). All my embedded devt was done with a makefile (lately a batch file because PCs are so fast that a makefile is pointless) and no IDE. I used Brief as the editor :) Am I right that an IDE basically gives you an intelligent editor e.g. one that knows where a function starts and ends, etc? And maybe syntac checking? Re assembler, I would think one still needs it for the C startup code, setting up initial register values, etc. This product will need to do bluetooth, for which we will buy a module of some sort. If it can support USB for factory programming etc that would be good too. What is the Jtag interface used for? Is it for programming the FLASH? I know I need to read the data sheet but I was after a few quick pointers... The other uC we looked at was the AT Mega 128 but the 32F seems about 5x faster, and a similar cost.
Den l=F8rdag den 10. maj 2014 14.32.36 UTC+2 skrev John-Smith:
> Tauno Voipio <tauno.voipio@notused.fi.invalid> wrote >=20 >=20 >=20 > >I have used the GNU tool set, for Cortex-M. My selection for >=20 > >an IDE is Eclipse. >=20 > > >=20 > >Get a ST dev board for the processor (or some similar enough). >=20 > >The simple boards are cheap, and they can double as USB-to-JTAG >=20 > >adapters. >=20 > > >=20 > >For JTAG, I'm using OpenOCD. >=20 >=20 >=20 > Many thanks (both of you). >=20 >=20 >=20 > All my embedded devt was done with a makefile (lately a batch file >=20 > because PCs are so fast that a makefile is pointless) and no IDE. >=20 >=20 >=20 > I used Brief as the editor :) >=20 >=20 >=20 > Am I right that an IDE basically gives you an intelligent editor e.g. >=20 > one that knows where a function starts and ends, etc? And maybe syntac >=20 > checking? >=20
You could call it an intelligent editor, you build with the push of button within the IDE, it "knows" the code so you can just jump to definitions, sh= ow when a function is called, jump to error line when building etc. etc. I've recently tried http://www.coocox.org/CooCox_CoIDE.htm looks like=20 a version of eclipse tailored to cortex-m so everything is setup out of=20 the box, getting a standard eclipse setup takes a bit more tweaking
>=20 >=20 > Re assembler, I would think one still needs it for the C startup code, >=20 > setting up initial register values, etc. >=20
with cortex very little is needed, basically one file zeroing and initializ= ing variables the rest can be in C
>=20 >=20 > This product will need to do bluetooth, for which we will buy a module >=20 > of some sort. If it can support USB for factory programming etc that >=20 > would be good too. >=20
many of the STM32Fs can boot from usb
>=20 >=20 > What is the Jtag interface used for? Is it for programming the FLASH? >=20
it can be used for that, it is a debug interface that can=20 read/write, start/stop single step the cpu etc.
>=20 >=20 > I know I need to read the data sheet but I was after a few quick >=20 > pointers... >=20 >=20 >=20 > The other uC we looked at was the AT Mega 128 but the 32F seems about >=20 > 5x faster, and a similar cost.
I wouldn't bother with an 8bit mcu =20 -Lasse
On 10.5.14 15:32, John-Smith wrote:
> > Tauno Voipio <tauno.voipio@notused.fi.invalid> wrote > >> I have used the GNU tool set, for Cortex-M. My selection for >> an IDE is Eclipse. >> >> Get a ST dev board for the processor (or some similar enough). >> The simple boards are cheap, and they can double as USB-to-JTAG >> adapters. >> >> For JTAG, I'm using OpenOCD. > > Many thanks (both of you). > > All my embedded devt was done with a makefile (lately a batch file > because PCs are so fast that a makefile is pointless) and no IDE.
Most of my projects in Eclipse are Makefile projects. Eclipse CDT (C development toolkit) lives happ&#2013265933;ly with make files.
> I used Brief as the editor :)
So did I years ago ...
> Am I right that an IDE basically gives you an intelligent editor e.g. > one that knows where a function starts and ends, etc? And maybe syntax > checking?
Yes. The Eclipse CDT checks plenty of C semantics, too, and it speeds up markedly getting rid of simple blunders. The Eclipse suite is a CPU hog, but with the current hardware, it is a no issue anymore. It is written in Java, and I have pretty similar set-ups running on Mac OS X, Linux and Windows, with Linux as the main O/S for embedded development. Eclipse supports a bewildering assortment of other target languages / systems besides C. At least in my use, it is pretty much all I need (for e.g. C, Doxygen, LaTeX, HTML, XML). The Web is full of examples how Eclipse and CDT work, have a look at them. -- -TV
"John-Smith" <noospam@noospam.com> wrote in message 
news:536dfc8c$0$1416$5b6aafb4@news.zen.co.uk...
> I am now looking at a new uP for another project and it is the ST ARM > STM32F range. For about a tenner you can get 1MB of on-chip FLASH > which is loads. > > But how can one program this in situ? > > Either there is a separate FLASH segment which remains available all > the time (how is that programmed?) or one has to load a loader into > the SRAM and execute it from there.
RTFM -- typically one copies to SRAM as mentioned (if this is available; obviously, that doesn't work on Harvard architectures), or uses a special "bootloader" segment which has different R/W settings. Flash is EEPROM more or less, but written a page at a time, usually 64-512 bytes. The rest of the memory remains available for access, usually with some restrictions. The bootloader area is special, I think, by usually being unrestricted during writes to the rest of memory. It can also be written to, in which case the CPU may stall until access is freed up again. Vpp is not required; Flash devices always have an onboard charge pump to do this. Which is one reason Flash writes can be so slow. Tim -- Seven Transistor Labs Electrical Engineering Consultation Website: http://seventransistorlabs.com
On Sat, 10 May 2014 11:16:13 +0100, John-Smith <noospam@noospam.com>
wrote:

>I am now looking at a new uP for another project and it is the ST ARM >STM32F range. For about a tenner you can get 1MB of on-chip FLASH >which is loads. > >But how can one program this in situ?
The STM32 Flash controller is done in such a way that you can program the Flash from code in Flash. What you cannot do, of course, is reprogram the sector containg any code you use while programming. If you want to reprogram the whole Flash, then you have to put the code in RAM. For (say) an XModem downloader over serial and program code, there's plenty of RAM on all but the very smallest STM32 devices. Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads
John-Smith <noospam@noospam.com> wrote:

 >All my embedded devt was done with a makefile (lately a batch file
 >because PCs are so fast that a makefile is pointless) and no IDE.

Nothing is wrong with a makefile. Even in modern times with Eclipse it
is a good idea to use it for professional work. 

 >I used Brief as the editor :)

And I use Emacs at home and Eclipe+Emacsmode at work. It is always
funny if a coworker tries to type something at my computer. :-D

 >Am I right that an IDE basically gives you an intelligent editor e.g.
 >one that knows where a function starts and ends, etc? And maybe syntac
 >checking?

Yes, and much more. For example spell checking and the Ide is checking
all other files of your project if you like to finde a declaration of
a variable or function. But sometimes it is bothersome.

For example Eclipse did not like this by default:

switch(blabla)
{
	case 1:
	     foo1();
	     break;
	case 2:
	case 3:
	     foo2();
	     break;

	
}

It is also possible to use git inside.


 >Re assembler, I would think one still needs it for the C startup code,
 >setting up initial register values, etc.

That is possible, but it is also possible to do this in C.

 >This product will need to do bluetooth, for which we will buy a module
 >of some sort. If it can support USB for factory programming etc that
 >would be good too.

Some of the bigger controller can do. For example I think the ST32F407
should do. But using USB for factory programming is a bad idea. Not
reliable enought. For this reason use the JTAG interface. 

A good quality programmer is about 600-1000Euro. It has network
connection and can program out of the factory database.

BTW: There is a cheap J-Link/JTAG for non professional use:
http://www.segger.com/j-link-edu.html

 >What is the Jtag interface used for? Is it for programming the FLASH?

The JTAG is for programming, debugging and also for factory
hardwaretest. It is good, reliable and fast. But it need some wires
and a bigger connector
The ST32 has JTAG, but also a second interface with two wires. That
one is okay too. It is used at the development board from ST.
The development board, for example this one:

http://www.st.com/web/en/catalog/tools/PF254044

had the microcontroller and also the debug interface for development
and programming. It is also possible open the wire by jumper and use
the debug interface with your own board.

Olaf
John-Smith <noospam@noospam.com> wrote:



 >I know I need to read the data sheet but I was after a few quick
 >pointers...

I just found this:

http://www.cs.indiana.edu/~geobrown/book.pdf

It explains almost everything at beginner/student level. :-)

Olaf