<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://socialledge.com/sjsu/index.php?action=history&amp;feed=atom&amp;title=Hyperload_Protocol</id>
		<title>Hyperload Protocol - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://socialledge.com/sjsu/index.php?action=history&amp;feed=atom&amp;title=Hyperload_Protocol"/>
		<link rel="alternate" type="text/html" href="http://socialledge.com/sjsu/index.php?title=Hyperload_Protocol&amp;action=history"/>
		<updated>2026-05-04T16:30:25Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.27.1</generator>

	<entry>
		<id>http://socialledge.com/sjsu/index.php?title=Hyperload_Protocol&amp;diff=1151&amp;oldid=prev</id>
		<title>Preet: /* Sample Code */</title>
		<link rel="alternate" type="text/html" href="http://socialledge.com/sjsu/index.php?title=Hyperload_Protocol&amp;diff=1151&amp;oldid=prev"/>
				<updated>2012-05-31T03:29:08Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Sample Code&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Hyperload ==&lt;br /&gt;
Hyperload is a program based off of UART to program a CPU at a &lt;br /&gt;
very high speed. Typically, this is 10-20 times faster than using&lt;br /&gt;
other flash programming programs such as FlashMagic.  This is a &lt;br /&gt;
good way to write your own bootloader for your own CPU.  It is &lt;br /&gt;
recommended to test your bootloader by not doing any real programming&lt;br /&gt;
and once you are past the protocol, then add your code to perform&lt;br /&gt;
real flash programming within your CPU.&lt;br /&gt;
&lt;br /&gt;
=== Hyperload Protocol ===&lt;br /&gt;
The Hyperload protocol is derived from the original &amp;quot;Megaload&amp;quot; program &lt;br /&gt;
&lt;br /&gt;
==== Protocol Phase 1 : Handshake ====&lt;br /&gt;
#  Upon bootup, initialize your UART at either 4800, 9600, 19200 or 38400bps&lt;br /&gt;
#  Send 0xFF over UART&lt;br /&gt;
#:  Regardless of your speed, Hyperload will detect your baud rate and send 0x55 back to you.&lt;br /&gt;
#:  When you receive 0x55, it is an indication that Hyperload is present&lt;br /&gt;
#  Send 0xAA back over UART&lt;br /&gt;
#  Hyperload will now send a baud rate control word to switch over to high speed mode.&lt;br /&gt;
#:  This control word is based on the following formula and the speed of CPU set @ Hyperload itself:&lt;br /&gt;
#:  Baud Rate = (CPU Speed / (Control Word + 1)) / 16&lt;br /&gt;
#:  Note that this control word dictates future speed, so if you want to continue at your original baud rate, be sure to choose that speed @ Hyperload COM Port speed.&lt;br /&gt;
#  Echo back the Control Word Hyperload sent while maintaining original baud rate&lt;br /&gt;
#  Switch over to the new baud rate or optionally if Hyperload COM Port speed is chosen as your original baud rate, disregard this control word.&lt;br /&gt;
&lt;br /&gt;
==== Protocol Phase 2 : Block size Setup &amp;amp; Bootloader Blocks ====&lt;br /&gt;
#  Send a CPU description string to Hyperload:&lt;br /&gt;
#:  $CPU Name:Block Size:Boot Size in Words:Flash Size in Kilobytes&lt;br /&gt;
#:  Example: &amp;quot;$LPC1758:4096:2048:512\n&amp;quot;&lt;br /&gt;
#:  This means your block(chunk) size is 4096 bytes, your bootloader size is 2048*2 bytes, and your flash size is 512Kbytes&lt;br /&gt;
#:  The block size is the chunks Hyperload will now send out of the HEX Programming file in &amp;quot;One shot&amp;quot;&lt;br /&gt;
#  Send Hyperload &amp;quot;OK&amp;quot; Character: &amp;quot;!&amp;quot; to continue&lt;br /&gt;
#  Hyperload will now send you empty blocks which span the size of your bootloader&lt;br /&gt;
#: Each block will contain 2 byte block number, and also contain 1 byte checksum (see Phase 3 below)&lt;br /&gt;
#: Send Hyperload_OK for each block for this dummy bootloader blocks&lt;br /&gt;
&lt;br /&gt;
==== Protocol Phase 3 : The Flash Program Blocks ====&lt;br /&gt;
# Based on your block size, hyperload will now send you block numbers followed by programming file contents (.Hex file)&lt;br /&gt;
#* Hyperload will send you 16-bit block number, MSB first&lt;br /&gt;
#: Hyperload will now send you the chunk of programming data, 4096 bytes according to the CPU description string above.&lt;br /&gt;
#: Hyperload will now send you 1 byte checksum of the programming chunk:&lt;br /&gt;
#:: Checksum is simply all the programming bytes added up&lt;br /&gt;
# Send back your status after you program this chunk in your processor:&lt;br /&gt;
#* ! for OK when checksum passes and you program and verify your flash correctly.&lt;br /&gt;
#* @ for checksum validation failure&lt;br /&gt;
#* ^ for any other error you experience during programming&lt;br /&gt;
#* '''Note: If ! is not sent, Hyperload will send you previous block again'''&lt;br /&gt;
# If ! was received, Hyperload will send you the rest of the chunks&lt;br /&gt;
# When no more chunks remain in your .Hex file, Hyperload will send you 0xFFFF for block number&lt;br /&gt;
#: At this point, send back &amp;quot;*&amp;quot; finish character and jump to your application code.&lt;br /&gt;
&lt;br /&gt;
=== Sample Code ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
	int blockNumber = 0;&lt;br /&gt;
	uart0Init(38400);&lt;br /&gt;
	&lt;br /&gt;
	uart0Getchar(100);  // Flushes UART and also provides delay of 100ms&lt;br /&gt;
	uart0Putchar(0xff); // Send 0xFF for Hyperload to sync with our baud rate&lt;br /&gt;
		&lt;br /&gt;
	// Hyperload will send 0x55 to notify that it is alive!&lt;br /&gt;
	if (0x55 == uart0Getchar(500))&lt;br /&gt;
	{&lt;br /&gt;
		// Notify Hyperload that we're alive too!&lt;br /&gt;
		uart0Putchar(0xAA);&lt;br /&gt;
&lt;br /&gt;
		char baudRateControlWord = uart0Getchar(500); // Get new baud rate control word&lt;br /&gt;
		uart0Putchar(baudRateControlWord);		      // Echo it back to verify&lt;br /&gt;
&lt;br /&gt;
		/**&lt;br /&gt;
		 * Hyperload Frequency should be set to 48,000,000 for this to work correctly&lt;br /&gt;
		 * It calculates the baud rate by: 48Mhz/(16*BAUD) - 1 = CW (control word)&lt;br /&gt;
		 * So we solve for BAUD:  BAUD = (48/(CW + 1))/16&lt;br /&gt;
		 */&lt;br /&gt;
		long baudRate = (48000000UL/(baudRateControlWord+1))/16;&lt;br /&gt;
		uart0Init(baudRate);&lt;br /&gt;
&lt;br /&gt;
		// Send our CPU information along with data parameters:&lt;br /&gt;
		// Name:Blocksize:Bootsize/2:FlashSize&lt;br /&gt;
		uart0Puts(&amp;quot;$LPC1758:4096:2048:512&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		uart0Putchar(HYPERLOAD_OK); // Now start programming...&lt;br /&gt;
		while(1)&lt;br /&gt;
		{&lt;br /&gt;
			blockNumber = (((int) uart0Getchar(500) &amp;amp; 0xff) &amp;lt;&amp;lt; 8) | (uart0Getchar(100) &amp;amp; 0xff);&lt;br /&gt;
&lt;br /&gt;
			if(0xffff == blockNumber) {&lt;br /&gt;
			    break;&lt;br /&gt;
			}&lt;br /&gt;
			else {&lt;br /&gt;
			    // Get 1 block + checksum and program this block number&lt;br /&gt;
			    uart0Putchar(WriteFlashPage(blockNumber));&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		uart0Putchar(HYPERLOAD_EXITING_TO_APP);&lt;br /&gt;
	}&lt;br /&gt;
	delay_ms(5); // Need this to finish sending previous char.&lt;br /&gt;
&lt;br /&gt;
	// Jump to application code&lt;br /&gt;
	uart0Init(38400);&lt;br /&gt;
	uart0Puts(&amp;quot;\nBooting Application . . .&amp;quot;);&lt;br /&gt;
	delay_ms(1000);&lt;br /&gt;
	&lt;br /&gt;
	executeApplication();&lt;br /&gt;
	return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hints ===&lt;br /&gt;
==== Uart Get Char Delay ====&lt;br /&gt;
Implement a getchar() that times out after 300-1000 milliseconds, if you don't receive anything&lt;br /&gt;
when you expect, start your application code or restart the entire bootloader process.&lt;br /&gt;
&lt;br /&gt;
==== High Speed Mode ====&lt;br /&gt;
High Speed Mode and baud rate switch is present to start handshake at a default rate and switch to &lt;br /&gt;
an optional high speed COM port rate if the device supports it.  Since this is configurable in&lt;br /&gt;
Hyperload, you can OPTIONALLY take advantage of this.&lt;br /&gt;
&lt;br /&gt;
==== Why send dummy bootloader blocks? ====&lt;br /&gt;
In a CPU like NXP, your bootloader lives at first 4K or so, and the programming .Hex file you want to&lt;br /&gt;
program lives at an offset of 4K from the flash location 0x000.0000   Taking this in account, Hyperload&lt;br /&gt;
sends the first 4K of data regardless and this leaves the protocol with more flexibility.  Since it is&lt;br /&gt;
hard to change this standard without breaking the protocol and existing compiled program, the best option&lt;br /&gt;
is simply to ignore this first chunk of data.&lt;/div&gt;</summary>
		<author><name>Preet</name></author>	</entry>

	</feed>