#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xuartps.h"
#define NUM_OF_BYTE 512*512
XUartPs_Config *Config_1;
XUartPs Uart_PS_1;
int main()
{
init_platform();
int Status;
u8 BufferPtr_rx[]={0};
u8 check[NUM_OF_BYTE] = {0};
/*************************
* UART 1 initialization *
*************************/
Config_1 = XUartPs_LookupConfig(XPAR_PS7_UART_1_DEVICE_ID);
if (NULL == Config_1) {
return XST_FAILURE;
}
Status = XUartPs_CfgInitialize(&Uart_PS_1, Config_1, Config_1->BaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
while(1){
XUartPs_Send(&Uart_PS_1, check, (NUM_OF_BYTE));
Status = -1;
while (Status < NUM_OF_BYTE) {
Status += XUartPs_Recv(&Uart_PS_1, BufferPtr_rx, 1);
if(BufferPtr_rx[0] != EOF){
check[Status] = BufferPtr_rx[0];
}
}
for(int i =0;i<NUM_OF_BYTE;i++)
{
XUartPs_Send(&Uart_PS_1, check, (NUM_OF_BYTE));
xil_printf("bytes : %0x",check[i]);
}
}
cleanup_platform();
return 0;
}
This is the code that i have for transferring from Computer to zedboard and again from FPGA to zedboard. I wrote a single python script for transferring data.
import serial
import os
## python -m serial.tools.list_ports -- listing ports
ser = serial.Serial('COM11',115200)
print(ser.is_open)
file_size = os.path.getsize("<file_path>")
print(file_size)
with open('<file_path>', 'rb') as file:
while True:
data = file.read(128) # Read 128 bytes at a time
#print(data)
if not data:
break
ser.write(data)
print("Broke from the loop")
print("finished transferring")
print(ser.read())
response = ser.read(file_size)
print(response)
ser.close()
The files are transferring to the zedboard but not the other way around. What is my mistake here?
Earlier working code was a simple file check
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xuartps.h"
#define NUM_OF_BYTE 5
XUartPs_Config *Config_0;
XUartPs Uart_PS_0;
XUartPs_Config *Config_1;
XUartPs Uart_PS_1;
char test[] = "Hello";
char hacked_string[] = "Hacked";
int main()
{
init_platform();
int Status;
//u8 BufferPtr_tx[10]={'1','2','3','4',5,6,7,8,9,10};
u8 BufferPtr_rx[]={0};
u8 check[NUM_OF_BYTE] = {0,0,0,0,0};
/*************************
* UART 1 initialization *
*************************/
Config_1 = XUartPs_LookupConfig(XPAR_PS7_UART_1_DEVICE_ID);
if (NULL == Config_1) {
return XST_FAILURE;
}
Status = XUartPs_CfgInitialize(&Uart_PS_1, Config_1, Config_1->BaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
while(1){
//
// for(int i =0;i<NUM_OF_BYTE;i++)
// {
// XUartPs_Recv(&Uart_PS_1, *check[i], 1);
// }
XUartPs_Send(&Uart_PS_1, check, (NUM_OF_BYTE));
Status = -1;
while (Status < NUM_OF_BYTE) {
Status += XUartPs_Recv(&Uart_PS_1, BufferPtr_rx, 1);
if(BufferPtr_rx[0] != '\n'){
check[Status] = BufferPtr_rx[0];
}
//Status++;//Status += XUartPs_Recv(&Uart_PS_1, BufferPtr_rx, (NUM_OF_BYTE - Status));
}
//XUartPs_Send(&Uart_PS_1, check, (NUM_OF_BYTE));
for(int i =0;i<NUM_OF_BYTE;i++)
{
xil_printf("check : %c",check[i]);
}
if(memcmp(check,test,NUM_OF_BYTE) == 0 ){
xil_printf("Success!!");
XUartPs_Send(&Uart_PS_1, hacked_string, 7);
}
else
{
printf("What?!");
}
}
cleanup_platform();
return 0;
}
This code was working with the exact output but not the previous code. I am sry if this too lengthy