0 Members and 1 Guest are viewing this topic.
/** * Name: communication_receive * Purpose: Waits for a page of firmware code and returns it * Inputs: * - Buffer in which to store the received page * Output: Size (in bytes) of the page received */unsigned int communication_receive(void * vAddress) {//debug_printf("Address: %X\n", vAddress); // Local variables unsigned int bytes; unsigned int remaining; unsigned int endOfFirmware; // Restart transfer media_writeChar(XON); // Wait for data, monitoring activity to detect the end of the firmware endOfFirmware = FALSE; bytes = 0; while (!endOfFirmware && (bytes < MEMORY_PAGE_SIZE)) { bytes = media_poll(); endOfFirmware = TRUE; for (unsigned int i=0; i < XON_XOFF_WAIT_COUNT; i++) { if (bytes != media_poll()) { endOfFirmware = FALSE; break; } } } if (bytes != 0) { // Read page if (bytes > MEMORY_PAGE_SIZE) { bytes = MEMORY_PAGE_SIZE; } bytes = media_read(vAddress, bytes); // Send XOFF control character and wait for remaining characters media_writeChar(XOFF); remaining = media_poll(); for (unsigned int i=0; i < XON_XOFF_WAIT_COUNT; i++) { if (remaining != media_poll()) { remaining = media_poll(); i = 0; } } } return bytes;}
You're using 115kbps and software flow control; do you see a problem there?Use a lower speed if you don't have RTS+CTS.
As a start, your endianess is broken. Get that fixed before doing too many other things.
Quote from: JVR on December 10, 2014, 01:20:07 pmAs a start, your endianess is broken. Get that fixed before doing too many other things.So I am just storing the data into the Flash in the wrong way. So does that mean I just have to just change from MSB to LSB. otherwise do I have to do something like swap joined sections like 926D0008 to 00089926d as it possibly looks like that in my screen shots.
XMODEM is more than just XON/XOFF if I cast my mind way back.
Looking at the code more closely, it seems that media_poll() and media_read() is where the action is. We probably need to see those to have any idea what is going on.I'm guessing it's probably going to be easier to write a bootloader from scratch than to understand what's going on though.
/** * Name: us0_poll * Purpose: Returns the number of bytes available in the read buffer * Output: Number of bytes that can be read in one call */unsigned int us0_poll() { return cyclic_GetSize();}#define cyclic_GetSize() \ ((cyclicDataEnd>=cyclicDataStart)?\ (cyclicDataEnd-cyclicDataStart):\ (cyclicDataEnd+US0_BUFFER_SIZE-cyclicDataStart))
/** * Name: us0_read * Purpose: Reads characters from the cyclic buffer * Inputs: * - Buffer in which to store read characters. If NULL, the whole * cyclic buffer is emptied * - Size of buffer * Output: Number of characters read. */unsigned int us0_read(void * vBuffer, unsigned int size) { // Local variables unsigned int bytes; char * pBuffer = (char *) vBuffer; // In case buffer is NULL, empty buffer if (vBuffer == NULL) { bytes = cyclic_GetSize(); cyclicDataStart += bytes; cyclic_DecSize(bytes); return bytes; } // Loop through available characters, storing them in the buffer bytes = 0; while ((bytes < size) && (cyclic_GetSize() > 0)) { pBuffer[bytes] = cyclicBuffer[cyclicDataStart]; cyclic_DecSize(1); cyclicDataStart = (cyclicDataStart+1)%US0_BUFFER_SIZE; bytes++; } return bytes;}
Quote from: wilfred on December 10, 2014, 06:23:20 amXMODEM is more than just XON/XOFF if I cast my mind way back.Yeah, XMODEM is an entire file transfer protocol, and the example code posted has nothing to do with it.Edit: Made dumb suggestion, deleted dumb suggestion.
"XMODEM" was both an early file transfer protocol (packet format approx SOH BLKNUM ~BLKNUM <128byte data> CKSUM),AND a common name for programs that implemented that protocol (along with, perhaps, simpler, protocol-less "upload" features.I'll assume:1) You're referring to the the bootloader described in "Atmel AT02333: Safe and Secure Bootloader Implementation for SAM3/4" (which does not include ANYTHING about "xmodem.")2) You're using some program that you're calling "xmodem" (which one?)3) this program is transmitting the extra F0s. (I'm not sure why; that isn't a sequence I remember being used in any XMODEM-like protocol...)4) The "protocol" described in this app note is pretty awful; they seem to be spending more attention to encryption issue that data transmission integrity.