/* * magicFlash for LPC1830-Xplorer * by uratan! 2012.10.25 */ /* * I am a poor english speaker, corrections are welcome. :-) */ magicFlash is a name of a set of a boot-loader / ISP / monitor program, which is made by corner-cutting. Yes of course, it is made to use Flash Magic. (see about Flash Magic.) [*] boot-loader magicFlash will work as 2nd boot-loader if you place it on SPIFI-flash. In this case, magicFlash will see P1_8 (GPIO1[1]) at first, then run user-program if it is HIGH, or start ISP (thru USART3) if it is low. You may add a switch simply between P1_8 and GND because magicFlash enables internal-PULL-UP. As boot-loader, magicFlash will handle the contents of 0x10_0000-- on the SPIFI-flash as a user-program. Concretely, set 0x8010_0000 to M3MEMMAP register and reset M3-core by myself. (So the hardware settings that boot-ROM or magicFlash had done are (still remained. It seems that PLL1 is set to 288MHz, M3-core runs (at 96MHz and SCK frequency of SPIFI is 18MHz. Whether magicFlash had been run by uart-boot or SPIFI-boot, magicFlash will always copy his codes onto RAM and always run on RAM, magicFlash uses about 0x1008_0000--0x1008_4fff of RAM, and it takes some time to copy, don't care... [*] ISP You can run fake ISP if you shall place magicflash on SPIFI-flash and set P1_8 as low, it pretend to as LPC1857, thru UART3. On LPC-1830-Xplorer, USART3 pins are taken from external connecter J10. pin#13 is U3_TxD (LPC1830 talks) (named I2C1_SDA in Xplorer manual) pin#14 is U3_RxD (LPC1830 listen)(named I2C1_SCL in Xplorer manual) (I recommend 57600bps as uart speed, though I had tested 115200bps...) I had confirmed it functions well with Flash Magic v6.95, selecting LPC1857. Address range 0x8010_0000--0x8017_ffff (512kB) of Xplorer's SPIFI-flash is mapped to LPC1857's 0x1A00_0000--0x1A07_ffff. So you can run your user program directly by magicFlash boot-loader. You shall care about only 1 point. It is a address of HEX files. You make your user program along with LPC1830's memory map, like 0x0000_0000--, Flash Magic does not accept HEX files which address is out of 0x1A00_0000--. You can solve this problem by using a option to objcopy.exe. objcopy.exe -O ihex --change-addresses=0x1a000000 input.elf output.hex Only address of HEX files are simply shifted, by adding the parameter value. I had tested minimum functions like: read-device-signature / erase / program / verify(read). Fake ISP will ignore flash-bank, operations about security. Please use it as he correctly work. (See also screen-shot of Flash Magic on my web) The genuine ISP protocol is described in User-Manual. You can see how fake ISP act by fake_isp.c. A command '/' is specially added to magicFlash, which is to switch to mini monitor. You may send '/' + CTRL-J because the line terminater is in ISP mode. I wanted to make Flash Magic to calc boot-signature, but no signature is needed when SPIFI-boot. (Flash Magic v6.95 is not add boot-signature now. but he may start (to modify some-special-addresses in later release. You shall care (about this point. (I had awared that there is a template of another ISP program (which is released with Flash Magic package... orz. (Port it for target and register HEX file to Flash Magic, it is (used by uart-boot automatically... (See "External Flash" section in Manual.pdf of Flash Magic [*] (mini) monitor Above fake ISP is run first when you place magicFlash on SPIFI-flash and run it with P1_8=low. At this phase, genuine ISP is waiting only for '?' char to synchronize, but magicFlash is waiting '/' char also to switch mini monitor. (This '/' char is different from '/' as ISP command. no CTRL-J is needed. Do try-and-error to study usage of commands of this mini monitor. All parameters are handled as hexadecimal, you can use char '_' which is simply ignored. Commands are case sensive. see minimon.c in detail or hidden commands. You can omit parameters, the default values are: command | default value of parameters ---------+----------------------------------------------------- d/e/w/s | addr: 0x0000_0000 (same about D/E/W/S) L | hex-offset: 0x0000_0000 K | 0 (12MHz) B | flash-addr: 0x8010_0000 P | flash-addr: 0x8010_0000 src_addr: 0x2000_0000 len: 0x1_0000 c | flash-addr: 0x8010_0000 src_addr: 0x2000_0000 len: 0x1_0000 (*) comment about D/E/W/S command I had write only basic 'd'/'e' command at first, but... 'w' added because some register returns 0xBAAD_ADDE when 8bit access. 'W' added because 'w' may reach exception address. 'S' added because need to access to WRITE-ONLY registers. 'D'/'E' added because I had added 'W' and 'S'... (*) comment about L command With 'L' command, load contents of address from (hex-offset) in intel-HEX file are stored to 0x2000_0000--0x2000_ffff. Contents out of receive-memory-range is ignored. Do 'L' + [RETURN] at first, then send a file by your terminal software. It may not be needed to use 'binary transfer mode'. Send some ':'s until he detect a error if you abort transfer. (*) about erase/write of SPIFI-flash You shall do initial with 'I' command before SPIFI operation. With 'B' command, all sectors are handled as 64kB, you can specify anywhere address in target sector. With 'P' command, only write-operation is done, without automatic-erase. You can specify any length. FYI: about flash ROM. 'wirte' is to change the bit of '1' to '0', and 'erase' is to change '0' to '1'. So you can write 0x07 to where 0x0f is already written. You can not write 0x1f to where 0x0f is already written. It seems that write-process of NXP's library may do write+read-back+verify per every byte. write-process may fail when verify error like above 'writing 0x1f to 0x0f'. You can use both 0x0000_0000--0x003f_ffff and 0x8000_0000--0x803f_0000 as flash-addr. I recommend 0x8000_*, because to make little mistakes with other memory operation like 'd' command. You can select SCK speed by 'K' command, but I do not confirm it so deeply. Please initial again by 'I' after changing SCK speed. See also operation examples below, or screen-shots on my web. [*] howto boot from SPIFI-flash Make DipSw on Xplorer off-ON-ON-ON from #1. If you add some external switchs for convenience, you shall care that P1_1 can be driven by LPC1830 when he detect boot-failer. [*] howto boot from USART3 [1] connect to PC thru 3.3V-to-RS-232C level converter. on LPC-1830-Xplorer, USART3 pins are taken from external connecter J10. pin#13 is U3_TxD (LPC1830 talks) (named I2C1_SDA in Xplorer manual) pin#14 is U3_RxD (LPC1830 listen)(named I2C1_SCL in Xplorer manual) [2] start your terminal software (I uses Tera Term) use serial settings like: 57600bps/8bit/non-parity/1stopbit [3] set DipSw of Xplorer ON-ON-ON-off from #1 [4] after reset Xplorer, send '?' char, then 'OK' answerd. [5] send 'boot-magicFlash.bin' by your terminal software. in case of my Tera Term, I can do this by "File"-->"Send file" menu, do not forget to confirm 'binary mode'. [*] examples to how to use mini monitor (*) howto: write magicFlash onto SPIFI-flash (1) uart3-boot ==> send '?' ==> send boot-magicFlash.bin as binary '/' to start mini monitor 'I' to initial SPIFI-flash 'L' and send magicFlash.hex 'B 0' to erase top of SPIFI-flash 'P 0' to write magicFlash.hex to SPIFI-flash (*) howto: write magicFlash onto SPIFI-flash (2) (expect magicFlash is already written on SPIFI-flash) SPIFI-boot with P1_8=low '/' to start mini monitor 'I' to initial SPIFI-flash 'L' and send magicFlash.hex 'B 0' to erase top of SPIFI-flash 'P 0' to write magicFlash.hex to SPIFI-flash (you can erase magicFlash very easyly like this, take care) (*) howto: write user-program test.hex (1) (expect magicFlash is already written on SPIFI-flash) SPIFI-boot with P1_8=low connect USART3 to Flash Magic select test-hex-@1a00.hex, then "Start" (*) howto: write user-program test.hex (2) (expect magicFlash is already written on SPIFI-flash) SPIFI-boot with P1_8=low '/' to start mini monitor 'I' to initial SPIFI-flash 'L' and send test.hex 'B' to erase top of user area 'P' to write test.hex (no parameter is needed if your program is smaller than 64kB) (*) howto: write user-program test.hex (3) uart3-boot ==> send '?' ==> send boot-magicFlash.bin as binary '/' to start mini monitor 'I' to initial SPIFI-flash 'L' and send test.hex 'B' to erase top of user area 'P' to write test.hex (mini monitor can be used simply by uart-boot,) (no need to write on SPIFI-flash) (*) howto: write user-program over 64kB (operation after starting mini monitor) 'I' to initial SPIFI-flash 'L' and send test.hex (0x0000--0xffff are remaind on mem) 'B 8010_0000' to erase 'P 8010_0000' to write 'L 1_0000' and send test.hex (0x1_0000--0x1_ffff are remaind on mem) 'B 8011_0000' to erase 'P 8011_0000' to write (you can handle until 512kB seamlessly with Flash Magic) [*] FILES [ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY ] [ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ] [ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR ] [ PURPOSE AND NONINFRINGEMENT. ] 00README.txt --- Japanese version 0eREADME.txt --- this file Makefile --- Makefile for make.exe LPC1830.h --- register definitions link.cmd --- linker script (still difficult for me...) mem_usage.h --- memory usage (not automatically linked with link.cmd) version.h --- version number Startup.S --- CPU start up main.c --- boot-loader (?) common.h --- system shared definitions common.c --- system shared functions (GPIO, uart is here) rprintf.c --- simple printf() (from sample of WinARM_20060606.zip) fake_isp.c --- fake ISP minimon.c --- mini monitor ihex.c --- load intel-HEX spifi.c --- control SPIFI-flash spifi_rom_api.h --- from AN11206 by NXP spifi_drv_M3.lib --- (same above) boot-magicFlash.bin --- convert magicFlash.bin for uart-boot magicflash.hex --- hex file of magicFlash.bin zz-boot_header.exe --- a tool to convert bin for uart-boot zz-boot_header.c --- and its source test/* --- template for user program test/test.hex --- its result in hex test/test.hex-@1a00.hex --- its result in hex (on 0x1A00_0000) test-spifi/* --- examine SPIFI-flash Compiler used is gcc-4.7.1(2012-0616) from yagarto You may need sh.exe and rm.exe, seek it from web please. [*] FYI: about boot-header I add 16byte like this on the top of program binaries for uart-boot. Set number-of-frames at under-lined~~~~~ place. (512byte/frame) +---------------------------------------------------------- |FFFFFFF0 : 1A FF 04 00 55 55 55 55 55 55 55 55 FF FF FF FF | ~~~~~ +---------------------------------------------------------- The length of final boot image is (16 + 512 * N frame)bytes. Add dummy data at the tail until it satisfy the length. This operation is done by zz-boot_header.exe. [*] FYI: hardware initialization vs boot-process Hardware-level-RESET +-------+-------+-------+-------+ | init: CLOCK | SPIFI | USART3| GPIO | V ------+-------+-------+-------+-------+ +-----------------------+ : (*2)| | | (*1) | | (genuine) boot-ROM | ======> : IRC/ | | | boot- | + - - - - - - - - - - - + : 96MHz| (*6)| | pins | | SPIFI boot| ======> : | SCK= | | SPIFI | | +----------+ : | 18MHz| | pins | | USART3-boot| | ==========> : | | Auto- | | +------------+ | : | | rate | | V (0x1000*) V (0x8000*) : | | | | +-----------------------+ : | | | | | magicFlash boot-ROM | : | | | | | (copy codes on RAM) |(*3) : | | | | + - - - - - - - - - - - + : | | | | | main() (0x1008*) | ======> : | | | LEDs/ | +-----------------------+ : | | | TP1_8 | | V (*4) : | | | | | +--------+ : | | | | | | spifi | ====> : | | | | V (*5) | _boot()| : | | | | +-----------+ +--------+ : | | | | | fake_ISP()|--+ ==========> : | SCK= | Auto- | | +-----------+ V : | 18MHz| rate | | ^ +-----------+ : | | | | +---->| minimon() | ======> : | SCK= | | | +-----------+ : | 12MHz| | | : | or 'K'| | | (*1) the status of boot-pins may be sensed non-GPIO path... (*2) boot-ROM set PLL1 as 288MHz, M3-core as 96MHz. (magicFlash will not touch about clocks (except SPIFI clk of ISP) (*3) magicFlash core is always run on RAM, because: need to erase/write SPIFI-flash. need to modify M3MEMMAP. (*4) user-program is stored from 0x10_0000-- on SPIFI-flash, it is mapped on 0x0000_0000-- by M3MEMMAP function. load-image-with-header is not supported. (*5) magicFlash will not see P1_8 when uart-boot, always run ISP/monitor. (*6) 18MHz may be the result of unproperly initialization by boot-ROM. -- uratan@st.rim.or.jp