Programming flash

Started by "isaac.caldas" July 12, 2010
Hello everyone!

I'm a begginer in MCU programming.

I was trying to make my MCU get access the flash and write n-bytes on it, for when I reboot my MCU keep this bytes on the flash, for future use.

I program in Assembly and my MCU is HCS12X.

Can you make a tutorial or a example for me? (explaining how write and read)

Thank you very much!

Hello, Isaac

In order to write into flash area, you need
- even a BDM (Background Debug Module) connected on parallel or USB port,
and "the good soft" like NoIce or CodeWarrior,
- or a "monitor" present on your CPU and a serial link with it

For the first way (BDM), the operation is quite easy. I just ask NoIce to
download to flash the program I just compiled.
For the second way... I don't know.

For you, why don't try to write in C Language ? It's so better, so easier to
read and write than assembly?
Do you prefer write
ldab 3,x
clra
addd #5
stab 3,x
than
my_var = my_var + 5;

You can use CodeWarrior (free for size limited programs), or Imagecraft
compiler (free too for little programs).
99% of my developments are in C language. I only use assembly for some
functions were assembly is quicker than C, and I can tell you C can produce
a very small code (it depends on the quality of the compiler).

Look on the net, you can find very good C programming course.
Maybe you will have to spend some time before... to economize many time
after!

Hope this help.
Joel

-----Message d'origine-----
De : 6... [mailto:6...] De la part de
isaac.caldas
Envoy: lundi 12 juillet 2010 16:58
: 6...
Objet : [68HC12] Programming flash

Hello everyone!

I'm a begginer in MCU programming.

I was trying to make my MCU get access the flash and write n-bytes on it,
for when I reboot my MCU keep this bytes on the flash, for future use.

I program in Assembly and my MCU is HCS12X.

Can you make a tutorial or a example for me? (explaining how write and read)

Thank you very much!

Maby you really want to write to the EEPROM area to store configuration
settings and non volatile variables that are going to have their values
preserved between power off/on cycles?

EEPROM is actually also FLASH but arranged in a way that it will allow much
shorter erase lengths (2 or 4 bytes I think).

Or are you trying to make a boot loader that will be able to download the
program which will be executed in FLASH memory?

/Ruben
> Hello, Isaac
>
> In order to write into flash area, you need
> - even a BDM (Background Debug Module) connected on parallel or USB port,
> and "the good soft" like NoIce or CodeWarrior,
> - or a "monitor" present on your CPU and a serial link with it
>
> For the first way (BDM), the operation is quite easy. I just ask NoIce to
> download to flash the program I just compiled.
> For the second way... I don't know.
>
> For you, why don't try to write in C Language ? It's so better, so easier to
> read and write than assembly? Do you prefer write
> ldab 3,x
> clra
> addd #5
> stab 3,x
> than
> my_var = my_var + 5;
>
> You can use CodeWarrior (free for size limited programs), or Imagecraft
> compiler (free too for little programs).
> 99% of my developments are in C language. I only use assembly for some
> functions were assembly is quicker than C, and I can tell you C can produce a
> very small code (it depends on the quality of the compiler).
>
> Look on the net, you can find very good C programming course.
> Maybe you will have to spend some time before... to economize many time
> after!
>
> Hope this help.
> Joel
>
> -----Message d'origine-----
> De : 6... [mailto:6...] De la part de
> isaac.caldas
> Envoy: lundi 12 juillet 2010 16:58
> : 6...
> Objet : [68HC12] Programming flash
>
> Hello everyone!
>
> I'm a begginer in MCU programming.
>
> I was trying to make my MCU get access the flash and write n-bytes on it,
> for when I reboot my MCU keep this bytes on the flash, for future use.
>
> I program in Assembly and my MCU is HCS12X.
>
> Can you make a tutorial or a example for me? (explaining how write and read)
>
> Thank you very much!
>
>
Hello! Thank's for the answers.

So... I have a program working here.

My interest is to write some variables in my flash MCU, so that when I turn off and on my MCU these 'variables' are still there.

I already have a BDM working..

The problem is that I have consulted several manuals, but I do not understand what I do ...
From what I saw there is something related to some kind of clock and the PPAGE.

I do not understand what registers must allow access to the recording on this flash..

PS: Sorry about my post... My english is not the best...

Thanks for you attention!

--- In 6..., "Ruben Jsson" wrote:
>
> Maby you really want to write to the EEPROM area to store configuration
> settings and non volatile variables that are going to have their values
> preserved between power off/on cycles?
>
> EEPROM is actually also FLASH but arranged in a way that it will allow much
> shorter erase lengths (2 or 4 bytes I think).
>
> Or are you trying to make a boot loader that will be able to download the
> program which will be executed in FLASH memory?
>
> /Ruben
>
>
> > Hello, Isaac
> >
> > In order to write into flash area, you need
> > - even a BDM (Background Debug Module) connected on parallel or USB port,
> > and "the good soft" like NoIce or CodeWarrior,
> > - or a "monitor" present on your CPU and a serial link with it
> >
> > For the first way (BDM), the operation is quite easy. I just ask NoIce to
> > download to flash the program I just compiled.
> > For the second way... I don't know.
> >
> > For you, why don't try to write in C Language ? It's so better, so easier to
> > read and write than assembly? Do you prefer write
> > ldab 3,x
> > clra
> > addd #5
> > stab 3,x
> > than
> > my_var = my_var + 5;
> >
> > You can use CodeWarrior (free for size limited programs), or Imagecraft
> > compiler (free too for little programs).
> > 99% of my developments are in C language. I only use assembly for some
> > functions were assembly is quicker than C, and I can tell you C can produce a
> > very small code (it depends on the quality of the compiler).
> >
> > Look on the net, you can find very good C programming course.
> > Maybe you will have to spend some time before... to economize many time
> > after!
> >
> > Hope this help.
> > Joel
> >
> > -----Message d'origine-----
> > De : 6... [mailto:6...] De la part de
> > isaac.caldas
> > Envoy: lundi 12 juillet 2010 16:58
> > : 6...
> > Objet : [68HC12] Programming flash
> >
> > Hello everyone!
> >
> > I'm a begginer in MCU programming.
> >
> > I was trying to make my MCU get access the flash and write n-bytes on it,
> > for when I reboot my MCU keep this bytes on the flash, for future use.
> >
> > I program in Assembly and my MCU is HCS12X.
> >
> > Can you make a tutorial or a example for me? (explaining how write and read)
> >
> > Thank you very much!
> >
> >
> >
> >
> >
> >
Hi, here is a routine that I use to copy the contents of some RAM locations to EEPROM (FLASH). Hope this helps.

Mike.
ECLKDIV EQU 0110 ;EEPROM CLOCK DIVIDER
ECNFG EQU 0113 ;EEPROM CONFIGURATION
EPROT EQU 0114 ;EEPROM PROTECTION
ESTAT EQU 0115 ;EEPROM STATUS
ECMD EQU 0116 ;EEPROM COMMAND
EADDRHI EQU 0118 ;EEPROM HIGH ADDRESS
EADDRLO EQU 0119 ;EEPROM LOW ADDRESS
EDATAHI EQU 011A ;EEPROM HIGH DATA
EDATALO EQU 011B ;EEPROM LOW DATA

CMDVRFY EQU 05 ;ERASE VERIFY \
CMDPROG EQU 20 ;PROGRAM |
CMDERAS EQU 40 ;ERASE | EEPROM COMMANDS
CMDBULK EQU 41 ;BULK ERASE |
CMDMDFY EQU 60 ;SECTOR MODIFY /
CBEIF EQU %10000000 ;CMD BUFFER EMPTY \
CCIF EQU %01000000 ;CMD COMPLETE | 'ESTAT' FLAGS
PVIOL EQU %00100000 ;PROTECTION VIOLATION |
ACCERR EQU %00010000 ;ACCESS ERROR /

;******************************************************
;* *
;* EEPROG - PROGRAMS EEPROM (0600-0607) *
;* WITH VALUES AT (1000-1007) *
;* *
;******************************************************
EEPROG NOP
LDAA #%01001010 ;\ SET EE CLOCK FOR 16MHz XTAL
STAA ECLKDIV ;/ & 8MHz SYSTEM CLOCK
LDAA #%00110000 ;\ CLEAR PVIOL & ACCERR FLAGS
STAA ESTAT ;/ IF ANY
LDX #$0600 ;\ *** ERASE EEPROM ***
EECLRLP LDD #$0000 ; | \ DUMMY DATA
STD $00,X ; | /
LDAA #CMDERAS ; | \ SET ERASE COMMAND
STAA ECMD ; | /
BSET ESTAT,CBEIF ; | INITIATE COMMAND
BRCLR ESTAT,PVIOL,EECLR1;\
BSET ESTAT,PVIOL ; | | CHECK PROTECTION VIOLATION
BRA EECLRLP ; | / IF YES, CLEAR FLAG & REPEAT
EECLR1 BRCLR ESTAT,ACCERR,EECLR2;\
BSET ESTAT,ACCERR ; | | CHECK ACCESS ERROR
BRA EECLRLP ; | / IF YES, CLEAR FLAG & REPEAT
EECLR2 BRCLR ESTAT,CBEIF,EECLR2; WAIT FOR DATA & ADR BUFFER EMPTY
INX ; | \
INX ; | | CLEAR NEXT WORD
CPX #$0608 ; | |
BLS EECLRLP ; | /
EECLRX BRCLR ESTAT,CCIF,EECLRX;
NOP ;/
LDY #$1000 ;\ *** PROGAM EEPROM ***
LDX #$0600 ; |
EEPRGLP LDD $00,Y ; | \ GET DATA
STD $00,X ; | /
LDAA #CMDPROG ; | \ SET PROGRAM COMMAND
STAA ECMD ; | /
BSET ESTAT,CBEIF ; | INITIATE COMMAND
BRCLR ESTAT,PVIOL,EEPRG1;\
BSET ESTAT,PVIOL ; | | CHECK PROTECTION VIOLATION
BRA EEPRGLP ; | / IF YES, CLEAR FLAG & REPEAT
EEPRG1 BRCLR ESTAT,ACCERR,EEPRG2;\
BSET ESTAT,ACCERR ; | | CHECK ACCESS ERROR
BRA EEPRGLP ; | / IF YES, CLEAR FLAG & REPEAT
EEPRG2 BRCLR ESTAT,CBEIF,EEPRG2; WAIT FOR DATA & ADR BUFFER EMPTY
INX ; | \
INX ; | | GO TO NEXT WORD
INY ; | |
INY ; | |
CPX #$0608 ; | |
BLS EEPRGLP ; | /
EEPRGX BRCLR ESTAT,CCIF,EEPRGX;
NOP ;/
RTS
--- In 6..., "isaac.caldas" wrote:
>
> Hello! Thank's for the answers.
>
> So... I have a program working here.
>
> My interest is to write some variables in my flash MCU, so that when I turn off and on my MCU these 'variables' are still there.
>
> I already have a BDM working..
>
> The problem is that I have consulted several manuals, but I do not understand what I do ...
> From what I saw there is something related to some kind of clock and the PPAGE.
>
> I do not understand what registers must allow access to the recording on this flash..
>
> PS: Sorry about my post... My english is not the best...
>
> Thanks for you attention!
>
>
>
>
> --- In 6..., "Ruben Jsson" wrote:
> >
> > Maby you really want to write to the EEPROM area to store configuration
> > settings and non volatile variables that are going to have their values
> > preserved between power off/on cycles?
> >
> > EEPROM is actually also FLASH but arranged in a way that it will allow much
> > shorter erase lengths (2 or 4 bytes I think).
> >
> > Or are you trying to make a boot loader that will be able to download the
> > program which will be executed in FLASH memory?
> >
> > /Ruben
> >
> >
> > > Hello, Isaac
> > >
> > > In order to write into flash area, you need
> > > - even a BDM (Background Debug Module) connected on parallel or USB port,
> > > and "the good soft" like NoIce or CodeWarrior,
> > > - or a "monitor" present on your CPU and a serial link with it
> > >
> > > For the first way (BDM), the operation is quite easy. I just ask NoIce to
> > > download to flash the program I just compiled.
> > > For the second way... I don't know.
> > >
> > > For you, why don't try to write in C Language ? It's so better, so easier to
> > > read and write than assembly? Do you prefer write
> > > ldab 3,x
> > > clra
> > > addd #5
> > > stab 3,x
> > > than
> > > my_var = my_var + 5;
> > >
> > > You can use CodeWarrior (free for size limited programs), or Imagecraft
> > > compiler (free too for little programs).
> > > 99% of my developments are in C language. I only use assembly for some
> > > functions were assembly is quicker than C, and I can tell you C can produce a
> > > very small code (it depends on the quality of the compiler).
> > >
> > > Look on the net, you can find very good C programming course.
> > > Maybe you will have to spend some time before... to economize many time
> > > after!
> > >
> > > Hope this help.
> > > Joel
> > >
> > > -----Message d'origine-----
> > > De : 6... [mailto:6...] De la part de
> > > isaac.caldas
> > > Envoy: lundi 12 juillet 2010 16:58
> > > : 6...
> > > Objet : [68HC12] Programming flash
> > >
> > > Hello everyone!
> > >
> > > I'm a begginer in MCU programming.
> > >
> > > I was trying to make my MCU get access the flash and write n-bytes on it,
> > > for when I reboot my MCU keep this bytes on the flash, for future use.
> > >
> > > I program in Assembly and my MCU is HCS12X.
> > >
> > > Can you make a tutorial or a example for me? (explaining how write and read)
> > >
> > > Thank you very much!
> > >
> > >
> > >
> > >
> > >
> > >
Different S12X families have different flash and different EEPROM. You
should start from specifying exact part number. Then you should check
availbility of application notes on Freescale www, there must be some.
I think all S12X have some kind of EEPROM available. EEPROM is #1 of what
should be used for nonvolatile variables.

Edward

----- Original Message -----
From: "isaac.caldas"
To: <6...>
Sent: Tuesday, July 13, 2010 5:52 PM
Subject: [68HC12] Re: Programming flash
Hello! Thank's for the answers.

So... I have a program working here.

My interest is to write some variables in my flash MCU, so that when I turn
off and on my MCU these 'variables' are still there.

I already have a BDM working..

The problem is that I have consulted several manuals, but I do not
understand what I do ...
From what I saw there is something related to some kind of clock and the
PPAGE.

I do not understand what registers must allow access to the recording on
this flash..

PS: Sorry about my post... My english is not the best...

Thanks for you attention!

--- In 6..., "Ruben Jsson" wrote:
>
> Maby you really want to write to the EEPROM area to store configuration
> settings and non volatile variables that are going to have their values
> preserved between power off/on cycles?
>
> EEPROM is actually also FLASH but arranged in a way that it will allow
> much
> shorter erase lengths (2 or 4 bytes I think).
>
> Or are you trying to make a boot loader that will be able to download the
> program which will be executed in FLASH memory?
>
> /Ruben
> > Hello, Isaac
> >
> > In order to write into flash area, you need
> > - even a BDM (Background Debug Module) connected on parallel or USB
> > port,
> > and "the good soft" like NoIce or CodeWarrior,
> > - or a "monitor" present on your CPU and a serial link with it
> >
> > For the first way (BDM), the operation is quite easy. I just ask NoIce
> > to
> > download to flash the program I just compiled.
> > For the second way... I don't know.
> >
> > For you, why don't try to write in C Language ? It's so better, so
> > easier to
> > read and write than assembly ? Do you prefer write
> > ldab 3,x
> > clra
> > addd #5
> > stab 3,x
> > than
> > my_var = my_var + 5;
> >
> > You can use CodeWarrior (free for size limited programs), or Imagecraft
> > compiler (free too for little programs).
> > 99% of my developments are in C language. I only use assembly for some
> > functions were assembly is quicker than C, and I can tell you C can
> > produce a
> > very small code (it depends on the quality of the compiler).
> >
> > Look on the net, you can find very good C programming course.
> > Maybe you will have to spend some time before... to economize many time
> > after !
> >
> > Hope this help.
> > Joel
> >
> > -----Message d'origine-----
> > De : 6... [mailto:6...] De la part
> > de
> > isaac.caldas
> > Envoy: lundi 12 juillet 2010 16:58
> > : 6...
> > Objet : [68HC12] Programming flash
> >
> > Hello everyone!
> >
> > I'm a begginer in MCU programming.
> >
> > I was trying to make my MCU get access the flash and write n-bytes on
> > it,
> > for when I reboot my MCU keep this bytes on the flash, for future use.
> >
> > I program in Assembly and my MCU is HCS12X.
> >
> > Can you make a tutorial or a example for me? (explaining how write and
> > read)
> >
> > Thank you very much!
> >
> >
> >
> >
> >
> >