Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DirectoryList MODSERIAL mbed
Fork of ika_shouyu_poppoyaki by
Revision 11:8dfc3217d1ca, committed 2013-08-27
- Comitter:
- okano
- Date:
- Tue Aug 27 03:09:07 2013 +0000
- Parent:
- 10:90bd46dadeb4
- Child:
- 12:5a33b5d39792
- Commit message:
- more flexible transfer size
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Aug 25 20:50:45 2013 +0000
+++ b/main.cpp Tue Aug 27 03:09:07 2013 +0000
@@ -1,3 +1,16 @@
+/**
+ * Sample of ISP operation for NXP MCUs
+ *
+ * @author Akifumi (Tedd) OKANO, NXP Semiconductors
+ * @version 1.0
+ * @date Aug-2013
+ *
+ * ISP
+ *
+ *
+ *
+ */
+
#include "mbed.h"
#include "target_table.h"
@@ -15,7 +28,8 @@
#define SECTOR_SIZE 4096
#define RAM_START_ADDRESS 0x10000000
-#define RAM_WRITE_OFFSET 0x130
+//#define RAM_WRITE_OFFSET 0x130
+#define RAM_WRITE_OFFSET 0x200
#define RAM_WRITE_START (RAM_START_ADDRESS + RAM_WRITE_OFFSET)
#define BYTES_PER_LINE 45
#define STR_BUFF_SIZE 64
@@ -40,7 +54,7 @@
void erase_sectors( int last_sector );
int write_binary_data( FILE *fp, int ram_size );
void initialize_uue_table( void );
-long bin2uue( char *bin, char *str );
+long bin2uue( char *bin, char *str, int size );
int get_flash_writing_size( int ram_size );
void add_isp_checksum( char *b );
void send_RAM_transfer_checksum( int checksum );
@@ -102,7 +116,7 @@
erase_sectors( last_sector );
write_binary_data( fp, tpp->ram_size );
-
+
fclose( fp );
printf( "\r\n %s\r\n\r\n",
@@ -244,8 +258,9 @@
initialize_uue_table();
flash_writing_size = get_flash_writing_size( ram_size );
- lines_per_transfer=(((flash_writing_size / BYTES_PER_LINE) + 3) & ~0x3);
- transfer_size=(lines_per_transfer * BYTES_PER_LINE);
+ //lines_per_transfer = (((flash_writing_size / BYTES_PER_LINE) + 3) & ~0x3);
+ lines_per_transfer = ((flash_writing_size / BYTES_PER_LINE) + 1);
+ transfer_size = (((flash_writing_size + 11) / 12) * 12);
// char b[ transfer_size ]; // this can be done in mbed-compiler. but I should do it in common way
@@ -269,9 +284,11 @@
try_and_check( command_str, "0", 0 );
for ( int i = 0; i < lines_per_transfer; i++ ) {
- checksum += bin2uue( b + (i * BYTES_PER_LINE), command_str );
+
+ checksum += bin2uue( b + (i * BYTES_PER_LINE), command_str, i == (lines_per_transfer - 1) ? (transfer_size % BYTES_PER_LINE) : BYTES_PER_LINE );
-// printf( " data -- %02d %s\r", i, command_str );
+ printf( " data -- %02d %s\r", i, command_str );
+ printf( " (%d)\r\n", i == (lines_per_transfer - 1) ? (transfer_size % BYTES_PER_LINE) : BYTES_PER_LINE );
put_string( command_str );
@@ -312,15 +329,15 @@
}
-long bin2uue( char *bin, char *str )
+long bin2uue( char *bin, char *str, int size )
{
unsigned long v;
long checksum = 0;
int strpos = 0;
- *(str + strpos++) = ' ' + BYTES_PER_LINE;
+ *(str + strpos++) = ' ' + size;
- for ( int i = 0; i < BYTES_PER_LINE; i += 3 ) {
+ for ( int i = 0; i < size; i += 3 ) {
checksum += *(bin + i + 0) + *(bin + i + 1) + *(bin + i + 2);
v = (*(bin + i + 0) << 16) | (*(bin + i + 1) << 8) | (*(bin + i + 2) << 0);
*(str + strpos++) = uue_table[ (v >> 18) & 0x3F ];
