I was reading a book called "Insiders guide to the Phillips ARM7 based microcontrollers". There it says "The easiest way to program the Flash is by the built in bootloader which allows the code to be downloaded via UART 0 into RAM and then programmed into FLASH". In Flash magic when we dump the .hex file via the PC's COMM port to the LPC1778 UART 0 port, does the .hex file go into the RAM and then does the bootloader inside place the code into the flash? If so,the onchip RAM is 64K in size and the flash size is 512k in size. What if the .hex file size i want to dump is greater than the size of the RAM?
1 Answer
In general, firmware images are not transferred over the UART verbatim; instead you communicate with a bootloader that provides in-system programming (ISP) functionality.
Section 37 of the LPC1778 user manual discusses the ISP commands and functionality.
A tool like Flash Magic sends commands to the bootloader to reprogram the chip incrementally. The particular algorithm will vary, but it probably looks something like:
- Transfer a sector's worth of data to the LPC1778's buffer in RAM.
- Erase the next flash sector to be reprogrammed.
- Copy the buffer from RAM to flash
- Compute the checksum of the newly written flash sector
- Compute the checksum of the data in RAM to verify
- Repeat until the entire firmware image has been written.
Accordingly, the amount of RAM available doesn't limit the bootloader's ability to reprogram the flash, though having more RAM available can speed up the process by reducing the amount of data transferred back and forth between the bootloader and the PC.
-
\$\begingroup\$ Thanks.Now it makes sense of how a large .hex file is programmed \$\endgroup\$ Commented Feb 3, 2016 at 7:13
-
\$\begingroup\$ But what if there is no bootloader to do this? For example: RM57 by TI dont ship with a bootloader \$\endgroup\$ Commented Feb 3, 2016 at 7:14
-
\$\begingroup\$ Using a bootloader is a very common and convenient way to reprogram a microcontroller, but it is not the only way. Debug protocols such as JTAG can allow direct access to registers and RAM, which can be used to reprogram the flash, albeit operating at a much lower level than simply issuing commands to an existing bootloader. \$\endgroup\$– DevanCommented Feb 3, 2016 at 7:32
-
\$\begingroup\$ Another doubt: How does the bootloader have permission to write into the ROM? (If the bootloader can obtain that permission,even any user code also can do that right?Like,code running from ROM rewrites another area in the ROM) \$\endgroup\$ Commented Feb 3, 2016 at 9:48
-
\$\begingroup\$ User code reprogramming itself is a legitimate case. You can read up more about it if you search for "in-application programming" (IAP). User code is usually always allowed to modify the flash (potentially after doing some specific register access sequence to prevent runaway code from accidentally rewriting flash). AN10851 covers the code read protection (CRP) facilities for the LPC17xx series. \$\endgroup\$– DevanCommented Feb 3, 2016 at 16:46