Flash Magic Forum

In-System Programming Support => LPC9xx/LPC9xxx => Topic started by: Jim Allen on June 05, 2005, 11:13:17 am

Title: P89LPC938 Programming
Post by: Jim Allen on June 05, 2005, 11:13:17 am
Dear Experts,

I have recently acquired a P89LPC938 to do some prototyping with for a new project.  I have used Flash Magic very successfully with several P89C51RD2BN devices but the 89LPC938 seems to be a different animal.  I have looked for info on how to program it using Flash Magic but I can't seem to find it.  I must be overlooking something.  Could someone please help me in learning how to program it with Flash Magic?

Thank you in advance for your help!

Jim Allen

Title: Re: P89LPC938 Programming
Post by: Andy Ayre on June 05, 2005, 03:18:29 pm
The most common way to get an LPC9xx device into ISP mode is using the three pulse method. However the timing requirements for the pulses are so tight that we had to come up with a method for a PC to generate them.

The result is the Keil MCB900 board. There is a link to the schematic diagram on the Flash Magic web page. Either buy one of these boards or copy the circuit and use it in your own hardware. Connect it to your PC's serial port and program using Flash Magic as usual. Don't forget to set the advanced options appropriately.

Title: Re: P89LPC938 Programming
Post by: Jim Allen on June 07, 2005, 10:21:32 am
Andy,

I know that this is not your fault but I gotta say this - why on earth do these guys make it so difficult to program these MCUs?  I mean, I give them credit for developing a great MCU with the unbelieveable features and then to have to stand on your head, with one eye closed while singing the national anthem but only the last half of it and only in C minor before you can program the blasted thing!  The 89C51RD2 micros were a piece of cake with your FlashMagic.  These LPC9xx are ridiculous to program!

What am I missing here?  My head is about to explode!  I am interested in your perspective.

Thanks for letting me vent.

Jim

Title: Re: P89LPC938 Programming
Post by: Andy Ayre on June 07, 2005, 10:26:43 am
I'm sorry for your frustration. You might want to pass your comments on to the support group at Philips Semiconductors. I am sure they will take them into consideration for future device families.

Title: Re: P89LPC938 Programming
Post by: Jan Waclawek on June 08, 2005, 03:45:24 am
My first personal experience was quite encouraging.
I wired up a LPC932 onto an old board with MAX232 and talked to it immediately - from factory the bootloader is there and runs immediately.

For added convenience you should implement something similar to NoTouch and you can forget the  "three-pulses" juggling.

Or, you can always write your own bootloader, e.g. in the P89V51RD2-style, waiting for the "U"s for some limited time, then jumping to the application.

Oh, and I even don't use FlashMagic, just a plain stupid terminal emulator...

:-)

Jan Waclawek
Title: Re: P89LPC938 Programming
Post by: Andy Ayre on June 08, 2005, 07:45:19 am
That's right - the devices come from the factory with the status bit set so they power up into ISP mode. If you want to program in your own alternative method of entering ISP mode at that point, then you will need to get it right the first time.

LPC9xx devices with a UART can also be set to enter ISP mode when a break condition is detected on RxD, however this has to be enabled by the running application. So this would have to be something you put into the very first program.

Title: Re: P89LPC938 Programming
Post by: erikm on June 13, 2005, 06:59:57 am
THE SOLUTION
as for most of the pains discussed here the solution is NoTouch.

If you install NoTouch (maybe in both update and backdoor mode) you will NEVER have to worry about 3 pulses, copying the Keil design or whatever, just do it ((C) Nike)

Erik
Title: Re: P89LPC938 Programming
Post by: Jim Allen on June 14, 2005, 04:51:09 pm
Erik,

I assume you are the author of the "No Touch" programming method of LPC9xx chips.  First of all, thanks for your response.  I have some questions on your method that I am trying to understand.  Please bear with me as I am somewhat new to the world of microcontrollers.

I understand the assembly code you wrote but what I don't know is where to put that in my program.  Do I make it a interrupt service routine activated by a pushbutton switch tied to an external interrupt on the LPC9xx?

Also, you mention in your article,"...this way a simple Rxd/Txd 232 chip connected to the PC is all that is required..." and "...activated by e.g. Txd held low..."

Finally, by using your method, does this put the uC in the state that it is in when it is shipped from the factory meaning that it will go into ISP mode automatically upon reset and power up?

Please help me (and possibly others too new or too embarassed to ask) understand your method by elaborating more on how to implement it from a software and hardware point of view.

Thank you in advance for your insight!

Jim

Title: Re: P89LPC938 Programming
Post by: Jan Waclawek on June 15, 2005, 12:09:19 am
Basically, Erik's idea is to implement the way to put the chip into virgin-like state in the _user_application_. Then, the choice of stimulus upon which this occurs is upon the user's choice. It can be actuation of some input, a long pulse on Rx line, or if there is some communication protocol implemented, this may be a part of the protocol, anything.

Jan Waclawek
Title: Re: P89LPC938 Programming
Post by: erikm on June 15, 2005, 05:33:58 am
re NoTouch

My versions are for the P89C51Rx2 series but the text (not the code) apply across the board).
I created a sketchy LPC version (were not working LPC at that time) which a kind person completed, tested and published.

Basically I recommend two methods for activation:
1) the normal: something that can be done without opening the box (pressing two keys simultaneously - sending "QWERTY" doen the setial line or whatever)
2) the "when everything goses awry": in startup.a51 test if Txd is held low, and, if so, activatre.

Erik
Title: Re: P89LPC938 Programming
Post by: erikm on June 15, 2005, 05:36:05 am
Oh, and...

When you take a LPC out of the box it IS in ISP mode.  Thus you do not need 3 pulses, spinach dip, funky reset or cabbage rolls to install NoTouch as long as you do this the very first time you program the chip.

Erik
Title: Re: P89LPC938 Programming
Post by: Jan Waclawek on June 15, 2005, 05:41:03 am
> Basically I recommend two methods for activation:
> 1) the normal: something that can be done without opening the box
> (pressing two keys simultaneously

Or, better, three.
Ctrl-Alt-Del
:-)

Jan Waclawek
Title: Re: P89LPC938 Programming
Post by: erikm on June 15, 2005, 07:31:35 am
Jan,

Get that PC hat off :)

Erik
Title: Re: P89LPC938 Programming
Post by: Jim Allen on June 15, 2005, 06:49:59 pm
Erik,

Thank you for responding.  

However, with all due respect and in hopes of helping many understand your ideas, please answer my questions:

1) I understand the assembly code you wrote but what I don't know is where to put that in my program. Do I make it a interrupt service routine activated by a pushbutton switch tied to an external interrupt on the LPC9xx?  Do I insert it at 0000H?  Where do you recommend it go?

2) Finally, by using your method, does this put the uC in the state that it is in when it is shipped from the factory meaning that it will go into ISP mode automatically upon the next reset after your code has run?

Thanks for your answers.

Jim

Title: Re: P89LPC938 Programming
Post by: Jan Waclawek on June 16, 2005, 01:14:25 am
Jim,

First, let's make one thing clear - Erik just sketched the procedure for LPCs (based on his prior experience with RD2/66x), but it needs a bit more - so I hope you are referring to http://www.esacademy.com/software/flashmagic/resources/touchless935.pdf (by Lex Timmerman, based on Erik's work). Erik mentioned this, too.

1. Place the routine where it suits to you. Placing it in an ISR activated by pushbutton is a good idea if you have a spare input; Erik's remark (activate it by holding down the Rx pin = break) aims to spare this pin (alternatively you can enable the bootloader activation by break as Andrew said earlier). If you have some communication protocol established, maybe it's also a good idea to implement a command which results in call to this routine, so you can get into bootloader without opening the box (again (C) Erik).
If you insert it on 0000h, upon first running your application it gets activated and the subsequent reset will invoke

2. Not absolutely completely - it is maybe also a good idea to include restoration of the boot vector (its exact value depends on amount of FLASH on that particular LPC9xx), just for the case you accidentally change it during ISP.

3. You can also embed the whole bootloader or its part into your application. There is an appnote at Philips site, including the bootloader's source code in the accompanying zipfile. You can at least get inspired by it...

Jan
Title: Re: P89LPC938 Programming
Post by: erikm on June 16, 2005, 06:19:17 am
"Finally, by using your method, does this put the uC in the state that it is in when it is shipped from the factory meaning that it will go into ISP mode automatically upon the next reset after your code has run?"
yes


"Place the routine where it suits to you. Placing it in an ISR activated by pushbutton is a good idea if you have a spare input"
OK, but that would require a separate PB and that one WILL be "accidentially" pushed

"Erik's remark (activate it by holding down the Rx pin = break) aims to spare this pin"
No, not the Rx - you may burn your transciever, configure Tx as Quasi and use that one as held down at power up/reset to activate.

"(alternatively you can enable the bootloader activation by break as Andrew said earlier). "
That requires all the funky hardware

"If you have some communication protocol established, maybe it's also a good idea to implement a command which results in call to this routine, so you can get into bootloader without opening the box (again (C) Erik).
If you insert it on 0000h, upon first running your application it gets activated and the subsequent reset will invoke"

Jan is mixing the two places.

a) The "closed box" is the "normal use which allow an update of the code in an installed system.

b) The "backdoor" (Tx held at start) is there to allow reprogramming of chips where a code malfunction does not allow reaching a)

 
Erik
Title: Re: P89LPC938 Programming
Post by: Jim Allen on June 16, 2005, 06:55:07 am
Gentlemen,

I apologize for what appeared to be "beating a dead horse" but thanks for your answers.

Jim

Title: Re: P89LPC938 Programming
Post by: Jan Waclawek on June 16, 2005, 06:56:28 am
> OK, but that would require a separate PB
> and that one WILL be "accidentially" pushed

That's why 3 buttons have to be installed on 3 sides of the box, at least 30cm (12") apart from each other, labelled "Ctrl", "Alt" and "Del", wired in series...

> No, not the Rx - you may burn your transciever, configure Tx
> as Quasi and use that one as held down at power up/reset to activate.

True, sorry.

>> "(alternatively you can enable the bootloader activation by break as
>> Andrew said earlier). "
> That requires all the funky hardware
Not at all, LPC932A1 user manual says:
The break detect can be used to reset the device and force the device into ISP mode by setting the EBRR bit (AUXR1.6)
Well, it is NOT mentioned in the ISP section, only in the UART section... (but probably all of us wrote various pieces of documentation...)

Jan Waclawek
Title: Re: P89LPC938 Programming
Post by: erikm on June 16, 2005, 11:36:20 am
That's why 3 buttons have to be installed on 3 sides of the box, at least 30cm (12") apart from each other, labelled "Ctrl", "Alt" and "Del", wired in series...

Jan, you forgot the :)

"The break detect  ..."
OK, you are right; however it is a bitch to make a PC generate a break.  

Andy: does FM do that now?

Erik
Title: Re: P89LPC938 Programming
Post by: Andy Ayre on June 16, 2005, 11:40:05 am
To generate a break condition in FM:

Go to ISP -> Start Bootloader...
Select "Send Break Condition"
Click on "Start Bootloader"

Title: Re: P89LPC938 Programming
Post by: Jim Allen on June 16, 2005, 12:12:11 pm
Andrew,

Based on the very interesting discussion that has transpired on this subject, maybe you could summarize the procedures mentioned and post a new Application Note on the Flash Magic website covering what we've been discussing.  

I cannot help but think that other individuals are struggling with this besides me and this would do nothing but help others use Flash Magic programming LPC9xx devices.  You know, a type of App Note that says, Step 1: Add the following code in your program here, Step 2: Start Flash Magic and generate a break by...  You get the idea.

What do you think?

Jim

Title: Re: P89LPC938 Programming
Post by: Andy Ayre on June 16, 2005, 12:17:56 pm
Jim, thanks for the suggestion of an application note. I'll add that to the to do list. Note however that if you only want to use the break detect method of ISP entry you don't need to add any code, simply set the relevent bit in the appropriate SFR.

Title: Re: P89LPC938 Programming
Post by: erikm on June 17, 2005, 05:41:02 am
"simply set the relevent bit in the appropriate SFR"

All very well, but what if the code (under development) does not reach the place where it "set the relevant bit"

This is not FM but LPC, but since it relates: can you "set the relevent bit in the appropriate SFR" as the first instruction (oer 0 - ljmp phread - org xxx - Phread: SBIT - crash) without any ill effects and will FM started with a reak then work if the program crashes

Erik
Title: Re: P89LPC938 Programming
Post by: Jim Allen on June 17, 2005, 07:48:09 am
Andrew,

I am interested in your comments to Erik's last post.  

I'm not sure I follow him.

Jim

Title: Re: P89LPC938 Programming
Post by: Andy Ayre on June 17, 2005, 08:46:06 am
Anything that relies on the application to set up is going to be at risk of it not working because due to some unforseen problem the code doesn't get far enough. I would guess (although I haven't tried it) that you could modify the Keil startup code to set the SFR bit to enable break detection, along with configuring the UART's baud rate, etc as one of the very first things that happens. I am not sure if the method would continue to work if later on the code crashed.

Title: Re: P89LPC938 Programming
Post by: erikm on June 17, 2005, 02:02:21 pm
I do not know about the LPC, but making the first thing in statup.a51 as follows:
?C_STARTUP: LJMP STARTUP1

           RSEG  ?C_C51STARTUP

STARTUP1:

;; here inserted
 jb P3.0, noboot
;;;;;;;;;; the code to activare the boot
jmp $
noboot:
;; continue with the Keil standard code (or whatever)

does work in the Rx2 as a guaranteed means of activating the ISP

Erik
Title: Re: P89LPC938 Programming
Post by: Jan Waclawek on June 18, 2005, 02:28:52 am
It can be done also the other way round - while using NoTouch with Backdoor (C)Erik the mcu starts in the application and "goes" to the bootloader upon "request"; it could also start in the bootloader which would jump to application when needed.

E.g. the standard bootloader can be modified to the style of P89V51RD2, i.e. if no successful autobaud occus within a certain time period, it would start the application.

Caveat: upgrading the bootloader  using ISP is nontrivial.

Jan Waclawek



Post Edited (06-18-05 02:32)