EmbeddedRelated.com
Forums

Switch between main app and flash monitor

Started by jeff31759 May 16, 2008
Note: This is a re-post, the original post turned to garbage
when HTML consumed extra spaces.

I am working on writing two programs that will both reside in
and run from MSP430 flash memory:
- Main Application
- Flash Monitor (can be used to download a new app)

Both of these will be C language programs.

I have started detailing what I need to do, including the
text/instruction below on:
1) EW430 ENVIRONMENT SETUP
2) SOURCE CODE
3) BOOT THE OTHER CODE (STOP CURRENT EXECUTION, START OTHER CODE)
4) INTERRUPT HANDLING

I think that I have the 1 - 2 correct.
Does anyone have comments on BOOTING or INTERRUPT HANDLING ?

Both programs will receive commands and send responses on the same
(SPI) interface. When I, for example, switch from the monitor to
the main app, I don't want incoming chars to still be going to
the monitor.
If I start the main app, from the monitor, then incoming chars
need to go to the main app.

I'm wondering if there is anything that I need to do
explictly for the ISR(s) or vector table(s) when changing from
one program to the other.
*********************************************************************
* BUILD TWO PROGRAMS THAT WILL BOTH RESIDE IN MSP430 FLASH MEMORY
*
* The two programs are
* - Main Application Resides in & runs from low MSP430 flash mem
* - Flash Monitor Resides in & runs from high MSP430 flash mem
*
* NOTE(s)
* 1) Target device is MSP430F155
*********************************************************************
==========================================================1) EW430 ENVIRONMENT SETUP
If there are two different programs in the same MSP430 flash memory,
they need to reside in different segments.
------------------
APPLICATION

Unmodifed lnk430F155.xcl file:
// Code
-Z(CODE)CSTART0-FFDF
-Z(CODE)CODE0-FFDF

------------------
FLASH MONITOR

custom_lnk430F155.xcl file:
-Z(CODE)CODE,CustomSeg0-FFD
==========================================================2) SOURCE CODE
For one of the programs, the C code needs to specify which
segment to use.
------------------
APPLICATION

C Source Code:
//#pragma location= don't use this
void MyFunc(int a) {/* */}

------------------
FLASH MONITOR

C Source Code:
#pragma location=CustomSeg
void MyFunc(int a) {/* */}

Do not use any library routines,
library routines are designed to
go to segment CODE.
==========================================================3) BOOT THE OTHER CODE
------------------
APPLICATION

asm(" mov mon_start_addr, PC;");

------------------
FLASH MONITOR

asm(" mov app_start_addr, PC;");
==========================================================4) INTERRUPT HANDLING
------------------
APPLICATION

#pragma vector=USART0RX_VECTOR
__interrupt void SPI0_rx_a (void)
{
ReadByte = U0RXBUF;
}

------------------
FLASH MONITOR

#pragma vector=USART0RX_VECTOR
__interrupt void SPI0_rx_m (void)
{
ReadByte = U0RXBUF;
}

Beginning Microcontrollers with the MSP430

Three comments.

1) Library routines work in any memory location. You do not need to
avoid them.

2) In order for the hardware to acknowledge interrupts correctly,
INTVEC must be assigned to FFE0-FFFD. You can fool Linker and place
INTVEC somewhere else, but you cannot fool the hardware. Thus you need
to re-vector them. I think the simplest way to avoid this is, you do
not enable interrupt in your Monitor and poll the flags.

3) Similarly, RESET must be assigned to FFFE-FFFF for the hardware to
recognize. Either your Application or your Monitor can assign a fake
RESET. The one with RESETFE-FFFF will get the CPU. It can hand the
CPU over to the other one by "BR &FakeReset". To go back, the other
one can use "BR &0xFFFE"

--- In m..., "jeff31759" wrote:
>
> Note: This is a re-post, the original post turned to garbage
> when HTML consumed extra spaces.
>
> I am working on writing two programs that will both reside in
> and run from MSP430 flash memory:
> - Main Application
> - Flash Monitor (can be used to download a new app)
>
> Both of these will be C language programs.
>
> I have started detailing what I need to do, including the
> text/instruction below on:
> 1) EW430 ENVIRONMENT SETUP
> 2) SOURCE CODE
> 3) BOOT THE OTHER CODE (STOP CURRENT EXECUTION, START OTHER CODE)
> 4) INTERRUPT HANDLING
>
> I think that I have the 1 - 2 correct.
> Does anyone have comments on BOOTING or INTERRUPT HANDLING ?
>
> Both programs will receive commands and send responses on the same
> (SPI) interface. When I, for example, switch from the monitor to
> the main app, I don't want incoming chars to still be going to
> the monitor.
> If I start the main app, from the monitor, then incoming chars
> need to go to the main app.
>
> I'm wondering if there is anything that I need to do
> explictly for the ISR(s) or vector table(s) when changing from
> one program to the other.
> *********************************************************************
> * BUILD TWO PROGRAMS THAT WILL BOTH RESIDE IN MSP430 FLASH MEMORY
> *
> * The two programs are
> * - Main Application Resides in & runs from low MSP430 flash mem
> * - Flash Monitor Resides in & runs from high MSP430 flash mem
> *
> * NOTE(s)
> * 1) Target device is MSP430F155
> *********************************************************************
> ==========================================================> 1) EW430 ENVIRONMENT SETUP
> If there are two different programs in the same MSP430 flash memory,
> they need to reside in different segments.
> ------------------
> APPLICATION
>
> Unmodifed lnk430F155.xcl file:
> // Code
> -Z(CODE)CSTART0-FFDF
> -Z(CODE)CODE0-FFDF
>
> ------------------
> FLASH MONITOR
>
> custom_lnk430F155.xcl file:
> -Z(CODE)CODE,CustomSeg0-FFD
> ==========================================================> 2) SOURCE CODE
> For one of the programs, the C code needs to specify which
> segment to use.
> ------------------
> APPLICATION
>
> C Source Code:
> //#pragma location= don't use this
> void MyFunc(int a) {/* */}
>
> ------------------
> FLASH MONITOR
>
> C Source Code:
> #pragma location=CustomSeg
> void MyFunc(int a) {/* */}
>
> Do not use any library routines,
> library routines are designed to
> go to segment CODE.
> ==========================================================> 3) BOOT THE OTHER CODE
> ------------------
> APPLICATION
>
> asm(" mov mon_start_addr, PC;");
>
> ------------------
> FLASH MONITOR
>
> asm(" mov app_start_addr, PC;");
> ==========================================================> 4) INTERRUPT HANDLING
> ------------------
> APPLICATION
>
> #pragma vector=USART0RX_VECTOR
> __interrupt void SPI0_rx_a (void)
> {
> ReadByte = U0RXBUF;
> }
>
> ------------------
> FLASH MONITOR
>
> #pragma vector=USART0RX_VECTOR
> __interrupt void SPI0_rx_m (void)
> {
> ReadByte = U0RXBUF;
> }
>