Hello, I work with an EASY UTAH board with C161U microprocessor and a Flash ST M29F040B 90K1 on target. I'd like to have my program loaded on Flash but executed on RAM. First I work with the blinky example to check the well functionning. When I load the blinky program to flash with the Flash Tool provided by Infineon, I effectively see that the led switch well. For executing the program in RAM, I wrote two different applications, one with the startup code and a copy routine for copying code from flash (segment 1) to RAM. I load this startup application in Flash at segment 0. The second program is the blinky one (without startup code) that I load in Flash at segment 1. When I reset the board, I could observe on oscilloscope a lot of access to flash (CS0) and RAM (CS1). But the led doesn't switch. In the startup code I specify CS1/RAM from 0x80000 with a size of 4K. I am really new to this so I don't know if the program is freeze doing the copying loop from flash to RAM, or if the execution is wrong. Someone have an idea of what is happening? Just to say that I don't want to use the application note 138 because I think this is not the solution to my problem. Effectively I want all my program executed in RAM and not only the critical routines. If someone have an idea or have same problems, I will be very grateful to have some help and to understand what I'm doing wrong. Thanks Regards
I believe the blinky program uses interrupts which reside at 0x00'0000 - probably still in Flash space after the copy. There are several ways to get around this: 1) Don't use interrupts - not very good solution. 2) Re-vector the interrupts in Flash to the RAM locations with ISR code. The RAM function addresses must be at a fixed location known to the Flash code or have a table of function addresses at a fixed location so the Flash can look up the location of the ISR at runtime. 3) Relocate the RAM to 0x00'0000 after copying the code to it. The way to do this is: A) Copy the code block to the base of RAM (the address which will become 0x00'0000). B) Copy a second small function to internal XRAM. C) Branch to this function. D) This function remaps CS1/ to 0x00'0000. E) The function then jumps to the Reset vector location. F) The program runs in RAM, including the vector table. Notes: The internal RAM function exists because you cannot change CSx/ addressing while using the CSx/ for code. Also the remapping doesn't take affect right away due to pipeline delays. This solution allows the RAM program to have it's own startup which will initialize the 'C' variables, etc. Just remember that writes to SYSCON are ignored after the EINIT instruction. EINIT is usually configured in startup.a66 after SYSCON has been set. Best luck Scott
Thanks for your suggestions Scott, but the blinky program I use have no interrupts. Nevertheless I will try your suggestion 3. Thanks.
Take a lok at the following application note: http://www.keil.com/appnotes/docs/apnt_138.asp It describes exactly how to do what you are trying. Jon
Hello, As I said before I don't want to use the application note 138 because if I understand well this is for executed in RAM few critical functions, and what I'd like is to execute ALL my program in RAM. Nevertheless I tried it but this does not function too. So I think that probably the problem I have is a memory map one. But I don't know how to identify it. Could someone help me on this? Thanks a lot Regards
Carmen, The program boots into external flash at 0x00'0000 which is the vector table of your loader routine. Therefore this program must be linked with something like the following memory map (assume 512KB flash & 256KB RAM):
ROM 0x00'0000 - 0x07 FFFF RAM 0x10'0000 - 0x13 FFFF
ROM 0x00'0000 - 0x02 FFFF (actually will be RAM) RAM 0x03'0000 - 0x03'FFFF
Hello Scott, Thank you a lot for your explanation and your valuable help, now it works!!! I have a startup program loaded on sectors 0 and 1 of the flash with the following memory map: ROM 0x0 0x80000 RAM 0x100000 0x40000 and an application loaded on sector two of the flash, with no memory map specified but with using the same .a66 startup file but with "Link Publics only". But now I need to visualize the address when executing, on a logic analyser. The target only have address bits from A0 to A19, and I need to visualize A20. I see in the data sheet that A20 correspond to the pin P4.4, and I need to have the field SALSEL of the register RP0H equal to 2 to could activate A20. But it is impossible to modify this register. Do someone know how I could visualize the A20 address line? Thanks a lot. Regards
Carmen, These lines are configured during reset by holding PORT 0 lines low (SALSEL is configured using lines P0H bits 4 & 3). This is all documented in the '167 Users manual under System Reset. Most development boards have jumpers or switches to control these bits during reset, check the documentation/schematic of yours. You would have to set the address space to 16Mbyte which enables A16-A23. Note that the CAN pins are mapped to A21 & A22. Best Regards Scott
Hello Carmen Moreno, I happen to see your query. The message says that you had written a code to transfer code from Flash to RAM. I am exactly looking for the same utility for C16X series. I happen to see an example in net, which says "memcpy" can transfer data from Flash to RAM. Is it true. If yes, do you have any idea about the time taken for this execution? Does it take the same time as when "memcpy" is used within RAM location? Could you please answer as soon as possible? Thanks you in advance Rashmi
Hi Scott: Because I will implement this function for my project.Do you have any sample code about this function for me reference? my email address: derek@trident.com.tw Thank you. Best regards, Derek
The boot program mentioned belongs to the client who I developed it for so I cannot pass it around:(. Because of the support for multiple processors (each with different flash algorithms) and multiple external flash types, and the limitations on resource use, it is a reasonably complex program. It had about a dozen assembly language modules with several hundred Kbytes source. To do the more traditional approach, follow App 138. It uses memcpy which works just fine. I started out doing it this way (App138) but changed course after a good percentage of the (industrial) customers disrupted the reprogramming in the middle by turning off the power, killing the communications channel or killing the application on the server which downloaded the new program (all this despite strong warnings in the manual, in the release notes and on the screen not to interfere). This left them with a totally dead unit which needed disassembly and special bootstrap software to reprogram the application. The separate boot sector solved this problem but took about 4 weeks to perfect. Best Scott
How does the flash RAM work? What are the molecular steps?
Hi, Can you say me, how did you write function which transfers your code from Flash to RAM.