Hi there,
Yes this is an issue with serial :). I'm trying to send some bytes to a USART buffer that will be stored on an external flash.
I have verified that my write method to the flash works as intended. The strange thing is that I am able to send other commands through UART which are recognized in the infinite loop. The code never fails to recognize the command "fsh_page" to jump into the condition - but once it is inside the condition it seems like the USART is not writing the proper data.
else if(!strcmp("fsh_page", (char*)usart_buffer)){ static int pageNumber = 3; uint8_t page_buffer[PROGRAM_PAGE_SIZE+4]; usart_read_buffer_wait(&usart_module, page_buffer, PROGRAM_PAGE_SIZE+4); if( flash_WriteBuffer(PROGRAM_PAGE_SIZE*pageNumber,PROGRAM_PAGE_SIZE+4, page_buffer) == true ) { usart_write_buffer_wait(&usart_module, (unsigned char*) "Page Write to memory complete.\n", 31); } //pageNumber++; }
The python code:
try: import serial except ImportError: print("failed to import serial") #open the image file and read the data try: file = open("test_rgb565.bmp", "rb") data = file.read() file.close() except: print("file error") #calculations to divie the data in page-sized buffers byteNumber = 0 pageNumber = 0 fullPages = len(data)/256 #flash page-size is 256 bytes leftoverBytes = len(data)%256 print(fullPages) print(leftoverBytes) #four first bytes are reserved for command/address to SPI (handled in the MCU code) page_data = [b'\x00'] * 260 for i in range(256): page_data[i+4] = data[i] ser = serial.Serial('/dev/ttymxc2', 115200) ser.write("fsh_page") #send command for mcu to start reading byte data and storing it in the flash ser.write(page_data)
The hex values that I am trying to send:
0x0 0x0 0x0 0x0 0x42 0x4d 0x62 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x42 0x0 0x0 0x0 0x28 0x0 0x0 0x0 0xc 0x0 0x0 0x0 0xc 0x0 0x0 0x0 0x1 0x0 0x10 0x0 0x3 0x0 0x0 0x0 0x20 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xf8 0x0 0x0 0xe0 0x7 0x0 0x0 0x1f 0x0 0x0 0x0 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xe4 0xe8 0xff 0xff 0xff 0xff 0xff 0xff
The hex values that are stored on the flash:
00 00 00 00 00 00 00 00 00 00 40 00 00 00 28 00 00 00 0C 00 00 00 08 00 00 00 01 00 00 00 03 00 00 00 20 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 E0 00 00 E0 00 00 00 1F 00 00 00 E4 E8 E4 E8 E4 E4 E8 64 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 64 68 6F 6F 6F 6F 6F 6F 6F 6F 64 68 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 64 68 64 68 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 64 68 64 68 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 64 68 64 68 64 68 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 64 68 64 68 64 68 64 68 64 68 6F 6F 6F 6F 6F 6F 6F 6F 6F 6F 64 68 64 68 64 68 64 68 64 68 64 68 64 68 64 68
I can see for an example that it is storing the correct values from 0x1F and onward to 0xE8 but then it goes crazy again.
Baud rate for both is set to 115200.
I have not verified the speed with an oscilloscope but I have verified it with a blinking LED.