assembler for FLASH CW 5.7 MC9s08RE16

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

assembler for FLASH CW 5.7 MC9s08RE16

3,411件の閲覧回数
stevec
Contributor III
I am wishing to store and read data in FLASH memory. I have utilised the code for FLASH Application Examples in the HCS08 reference manual, using inline assembler. I am getting various errors mostly relating to references to label addresses within the code.
Can anyone point me towards any C/assembler code that will allow me to store/retrieve data in FLASH.
The type of thing the compiler doesn't like is

lda   #SubLabel1
.....
SubLabel1:
.
.
I have no experience of mixing assembler and C.
ラベル(1)
タグ(1)
0 件の賞賛
返信
8 返答(返信)

1,235件の閲覧回数
stevec
Contributor III
Further info.

I am using inline assembler not a separate assembler file.

errors for example

ldhx #SpSubEnd      Immediate/Global addres expected

cphx #SpSub -1     Illegal operands

SpSubEnd and SpSub are labels elsewhere in the inline assembly code
0 件の賞賛
返信

1,235件の閲覧回数
J2MEJediMaster
Specialist I
You've got two issues:

1) How to use inline assembly in C. For that, you you'll want to consult the HC(S)08/RS08 Assembler Manual for Microcontrollers. It explains how to mix C and assembly. The manual should be part of your CodeWarrior installation. Look under the \Help directory.

2) Programming Flash. Although the areas of Flash resemble memory and can be read like memory, writing to them to store data is completely different. As this topic comes up often, I'd recommend using the forum search (text entry box at the lower left of this web page) to conduct a search using the phrase "Flash programming".

---Tom
0 件の賞賛
返信

1,235件の閲覧回数
stevec
Contributor III
Thanks Tom,

1. The Assembler manual shows how to "mix assembler source files and C source files in a single application". I would ideally like to use in line assembler, which is not covered in the Assembler manual but in the C Compiler manual. I have printed this off and can find no reference as to how to reference a label address as in

ldhx #SpSubEnd
.
.
SPSubEnd:
.
.
This produces most of my errors.

2. The HCS08 reference manual covers writing into flash and has some application code (in assembler) to put the relevant code onto the stack and execute it from there while the Flash is being accessed. It is this code that I am trying to include into my C code. The assembler code copies part of itself to the stack and thus the requirement to reference labels as these mark the start and end of the code to be transferred. I only need to store four or five bytes of data as backup while the processor is powered down.

I will continue to search for 'flash programming' on this forum.

Steve
0 件の賞賛
返信

1,235件の閲覧回数
CrasyCat
Specialist III
Hello
 
According to my understanding what you are trying to achieve here is coping a code snippet on the stack and running it from there.
 
Am I right?
 
There is a technical note on that subject TN235 which describes how to achieve that.
You can retrieve the Technical Note from your installation CD or download them from following URL:
 
 
Around your question.
When you are programming in inline assembler, you are able to use assembler instruction within a ANSI C source file.
 
Labels you define in an inline assembly function have same property and scope as ANSI C labels.
In ANSI C a label does not have an absolute address, it is just a marker so you cannot retrieve the label absolute address.
 
This is a limitation in HLI assembler syntax.
 
CrasyCat


Message Edited by CrasyCat on 2008-02-07 11:21 AM
0 件の賞賛
返信

1,235件の閲覧回数
stevec
Contributor III
Thanks for clarifying about the limitations of the HLI assembler syntax.

As I mentioned in my previous post I can not find TN235 (not checked installation CD yet) and it is not under the link you sent. I found reference to a TN228 has some relevance.

In case anyone else finds this thread in a search, I have also just found FAQ-26240 which also looks helpful
0 件の賞賛
返信

1,235件の閲覧回数
CrasyCat
Specialist III
Hello
 
On the page I specified last time there is a link "816TNSP ", which will download all the Technical notes.
TN235 should be in there
 
CrasyCat

1,235件の閲覧回数
bigmac
Specialist III
Hello Steve,
 
I suspect that, from the label names you have used, you are attempting to adapt some existing flash programming code, written entirely in assembler, to inline assembly.  An alternative approach is to directly calling the assembly routines (within an .asm file), as a C function.  The only requirement is that the assembly routines use the same parameter passing convention as C.
 
I discovered the attached code for a "Standard software SGF driver" (for HCS08 devices), apparently downloaded previously from somewhere on the Freescale website, I can't remember where.  The header file shows how the assembly routines are called as C functions.  As an example, I will list one of the function prototypes from within the header file.
 
void Write_Flash(
   unsigned char *dest,   /* First address to be programmed */
   unsigned char length,  /* Number of data bytes to be written */
   unsigned char *source  /* Pointer to start of data buffer */
);
 
The assembly routine is named Write_Flash, and actually used burst mode to write a number of bytes to flash.  The data to be written is contained within a suitable buffer, identified by source.
 
If you examine the assembly code, you will find the following requirements on entry to the routine -
The first parameter, the destination address is pushed the stack, low byte first, prior to the call.
The second parameter, the data length, is present in the accumulator.
The third parameter, the buffer address, is present in H:X.
 
The Erase_Page routine has a single destination address parameter, and this is present in H:X.
 
If you need to alter the number of parameters, and/or their type, there would be differences from the above.  However, if you stick with the same parameters, the functions should work, whatever the inner workings of the assembly routines.
 
Yet another alternative is to provide a "C wrapper" for the assembly routines, where the inputs required by each routine are handled by inline assembler and then the routine is called as a JSR.  For example -
 
Write_Flash_Row(
   unsigned char *dest, unsigned char length, unsigned char *source)
{
   asm {
      ldhx dest
      pshx
      pshh
      lda  length
      ldhx source
      jsr  Write_Flash
   }
}
 
Regards,
Mac
 
 


Message Edited by bigmac on 2008-02-11 02:01 AM

1,235件の閲覧回数
stevec
Contributor III
After a search on the forums , one possible solution is to rewrite the assembler code in C and relocate it to RAM as covered in TN228. I have also found reference to TN235 but cannot find the note anywhere.
0 件の賞賛
返信