HC908QT2 Monitor mode run

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC908QT2 Monitor mode run

1,293 Views
Impudence
Contributor I
    I have been able to enter monitor mode, write to ram, verify the ram write, and even blink an LED from monitor mode (by sending commands to write to PTA).  The problem I have now is that I cannot seem to run a user program.  I can upload an S19 file, like the one attached.   I don't actually write to the reset vector (so that it stays blank, making it easier to get into monitor mode).  Instead, I use the monitor mode READSP command (call the returned data SP_plus_1), and write what would have gone into the reset vector into (SP_plus_1 + 4) and (SP_plus_1+5).  This should, as I understand it, put the address of the beginning of the program into the stack at the point where the return address should be stored.  I don't know if it increments the program counter before it puts it on the stack, or after it pops it from the stack, so I added a NOP instruction to the beginning of the program I want to run, just to be sure. 

Once I've edited the stack in this way, I send the RUN monitor mode command....and nothing happens except that the stack pointer (which was 0x00FA) is now 0x00FF, indicating that it's executed the PULH and RTI instructions.


It doesn't seem to run the program, and the chip is back to responding to my serial inputs.  I am rather confused by this.

I know I could use a premade program to do the programming, but since I'm doing this for fun, I would rather not.
Labels (1)
0 Kudos
3 Replies

339 Views
bigmac
Specialist III
Hello,
 
There seems to be some misunderstanding about the reset process, and the reset vector.  The stack pointer plays no part.  When the reset vector is fetched from location $FFFE, it is used to set the program counter (PC).
 
For the device you are using, the stack pointer should not be altered from its reset default position ($00FF) without a specific reason.
 
From the contents of your S19 file, your program appears to commence at address $00B0 within RAM.  Additionally, if you were to use this file to program the flash memory, the reset vector would, in fact, point to the start of your program within RAM.  But this is not allowable for POR since the RAM contents are volatile.
 
Within your source assembly code, I might suggest that you ORG to the start of flash memory prior to the start of your code, so that non-volatile storage is used.  A simple test program might have the following structure.
 
  ORG  ROMStart
START:
       ; Initialisation code
 
MAIN:
       ; Main program loop
 
 
       JMP   MAIN     ; Loop always
 
  ORG  $FFFE          ; Reset vector location
       DC.W  START    ; Start of program
 
Regards,
Mac
 
0 Kudos

339 Views
Impudence
Contributor I
Does the monitor mode 'RUN' instruction reset the device?  I thought it was merely supposed to execute the PULH and RTI instructions, allowing a program written into RAM to be run.  Is it possible to write directly to the flash with the monitor mode 'WRITE' and 'IWRITE' instructions?
0 Kudos

339 Views
bigmac
Specialist III
Hello,
 
The operation of the RUN monitor command assumes that the current monitor operation was effectively caused by execution of a SWI instruction, and so performs the usual ISR exit process.  If the return address on the stack should be the entry point to the program, the initialisation code would then run, but MCU reset would not have taken place.
 
A reset from any source will always attempt to load the contents of the reset vector to the program counter
 
The WRITE and IWRITE commands do not alter the contents of flash memory.  Erase and programming procedures are required.
 
Regards,
Mac
 
0 Kudos