element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Forum How to write the contents of a text file to DDR RAM on the Arty S7-50 board (or any fpga)?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 12 replies
  • Subscribers 554 subscribers
  • Views 7505 views
  • Users 0 members are here
  • xilinx
  • fpga
  • vivado
  • spartan-7
  • Arty S7 50
  • vitis
  • Spartan_Migration
Related

How to write the contents of a text file to DDR RAM on the Arty S7-50 board (or any fpga)?

cbohra00627
cbohra00627 over 3 years ago

I am trying to load a image directly to the DDR SDRAM on the Art S7 board. I have converted the jpg image into a txt file containing the integer RGB values for each pixel in separate lines. The file is as shown below:

goku.txt

Then I created a block design in vivado for microcontroller preset with uartlite and the MIG as shown below and programmed my fpga board with this design.

Block Design

Now, I am trying to open a file in Vitis and load the contents of the file byte by byte into the SDRAM memory locations with the code given below:

#include <stdio.h>
#include <stdlib.h>
#include "platform.h"
#include "xparameters.h"
#include "xil_io.h"
#include "xil_printf.h"

int main() {

	char line[2];
	int num = 0;
	int num_rec = 0;
	int i = 0;

	FILE *source = fopen("C:/Users/Chinmay/Desktop/goku.txt", "r");
	FILE *target = fopen("C:/Users/Chinmay/Desktop/goku_vitis.txt", "w");

	if ((source == NULL) || (target == NULL)) {
		xil_printf("File Failure");
		exit(1);
	}

	init_platform();

	while (fscanf(source, "%s", line) == 1) {
		num = atoi(line);
		Xil_Out8(XPAR_MIG7SERIES_0_BASEADDR + i, num);
		i++;
	}

	for (long int j=0; j<4; j++) {
		num_rec = Xil_In8(XPAR_MIG7SERIES_0_BASEADDR + j);
		fprintf(target, "%d\n", num_rec);
	}

	cleanup_platform();

	fclose(source);
	fclose(target);

	return 0;
}

Now, I doubt that my approach is wrong. In fact, I am getting some error when I try to build this code in vitis. The console output is given below:

22:44:58 **** Incremental Build of configuration Debug for project MIG1 ****
make all 
'Building file: ../src/main.cpp'
'Invoking: MicroBlaze g++ compiler'
mb-g++ -Wall -O0 -g3 -c -fmessage-length=0 -MT"src/main.o" -IC:/Users/Chinmay/Desktop/Verilog_Vivado/MIG1_Vitis/MIG1_wrapper/export/MIG1_wrapper/sw/MIG1_wrapper/standalone_microblaze_0/bspinclude/include -mno-xl-reorder -mlittle-endian -mxl-barrel-shift -mxl-pattern-compare -mcpu=v11.0 -mno-xl-soft-mul -Wl,--no-relax -ffunction-sections -fdata-sections -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp"
'Finished building: ../src/main.cpp'
' '
'Building target: MIG1.elf'
'Invoking: MicroBlaze g++ linker'
mb-g++ -Wl,-T -Wl,../src/lscript.ld -LC:/Users/Chinmay/Desktop/Verilog_Vivado/MIG1_Vitis/MIG1_wrapper/export/MIG1_wrapper/sw/MIG1_wrapper/standalone_microblaze_0/bsplib/lib -mlittle-endian -mxl-barrel-shift -mxl-pattern-compare -mcpu=v11.0 -mno-xl-soft-mul -Wl,--no-relax -Wl,--gc-sections -o "MIG1.elf"  ./src/main.o ./src/platform.o   -Wl,--start-group,-lxil,-lgcc,-lc,-lstdc++,--end-group
d:/xilinx/vitis/2021.2/gnu/microblaze/nt/x86_64-oesdk-mingw32/usr/bin/microblaze-xilinx-elf/../../libexec/microblaze-xilinx-elf/gcc/microblaze-xilinx-elf/10.2.0/real-ld.exe: MIG1.elf section `.text' will not fit in region `microblaze_0_local_memory_ilmb_bram_if_cntlr_Mem_microblaze_0_local_memory_dlmb_bram_if_cntlr_Mem'
d:/xilinx/vitis/2021.2/gnu/microblaze/nt/x86_64-oesdk-mingw32/usr/bin/microblaze-xilinx-elf/../../libexec/microblaze-xilinx-elf/gcc/microblaze-xilinx-elf/10.2.0/real-ld.exe: region `microblaze_0_local_memory_ilmb_bram_if_cntlr_Mem_microblaze_0_local_memory_dlmb_bram_if_cntlr_Mem' overflowed by 88968 bytes
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:50: MIG1.elf] Error 1

22:45:00 Build Finished (took 1s.910ms)

At the end of the 12th line, it says "region `microblaze_0_local_memory_ilmb_bram_if_cntlr_Mem_microblaze_0_local_memory_dlmb_bram_if_cntlr_Mem' overflowed by 88968 bytes". So, my guess is that when I try to open the file, it first gets loaded into the BRAM which has less capacity than the file itself. Well, I might be wrong because when I tried to load a small 1KB file, it showed the same error.

I am stuck here. Is there any way through which I can load my file directly into the SDRAM? The size of my file is around 8MBs.

Actually I am trying to implement image processing on FPGA. I need to load an image on the board, then I will make a image processing IP in vitis HLS and use it in my design.

  • Sign in to reply
  • Cancel

Top Replies

  • saadtiwana_int
    saadtiwana_int over 3 years ago in reply to cbohra00627 +2 verified
    On your linker script screenshot, as i remember, the "memory region" values are drop-down items. Right now everything is assigned to be saved to bram (as you can see in your screenshot). You can use the…
  • Metaforest
    Metaforest over 3 years ago +2
    Make sure you have built and run the memory and platform test projects. Make sure you understand how they work. Including the base address configuration in your Object diagram. Prove you can read and write…
  • saadtiwana_int
    saadtiwana_int over 3 years ago in reply to cbohra00627 +1
    Glad it worked for you. So one way that i can think of to know where your array is stored at, is by looking the address of the variable. In one of the screenshots you shared above, the bram has the address…
  • ehernand
    0 ehernand over 2 years ago

    How did you convert the jpg image into a txt file containing the integer RGB values for each pixel in separate lines?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • paresh
    0 paresh over 3 years ago in reply to cbohra00627

    Hey, I'm trying to read and write data to DDR4 from an FPGA.  I had a similar error as above, and after changing the linker script to BRAM, I was able to view the output on the serial monitor.

    Is it necessary to use Xil_Out8() and Xil_In8() functions? I'm just using normal int pointers to read and write the data in those specific memory locations.
    But I'm unable to get the right output. And for some reason, I'm not able to print hex values.

    Can you share your code if possible?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cbohra00627
    0 cbohra00627 over 3 years ago in reply to cbohra00627

    Well, its solved now. I just had to enable AXI peripheral interface in the microblaze customize IP window.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cbohra00627
    0 cbohra00627 over 3 years ago in reply to saadtiwana_int

    I tried to initialize a variable and read it back after doing the changes in the linker file as you said but now when I run my code on the hardware, the terminal doesn't show anything. The terminal remains blank. I am not able to print any value on terminal Moreover I am not even able to get values directly from memory locations using Xil_In8() but strangely when I select BRAM for all the options in the linker file, the same code words fine!

    #include "platform.h"
    #include "xparameters.h"
    #include "xil_io.h"
    #include "xil_printf.h"
    //#include "data.h"
    
    int main() {
    
    	int x = 5;
    
    	init_platform();
    
    	int y = 6;
    	int num;
    
    	num = Xil_In8(0x80001000);
    
    	xil_printf("%d %d %d",x, y, num);
    
    	cleanup_platform();
    
    	return 0;
    }
    

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cbohra00627
    0 cbohra00627 over 3 years ago in reply to saadtiwana_int

    OK, Thank You very much!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • saadtiwana_int
    0 saadtiwana_int over 3 years ago in reply to cbohra00627

    Glad it worked for you.

    So one way that i can think of to know where your array is stored at, is by looking the address of the variable. In one of the screenshots you shared above, the bram has the address range in the beginning (I cannot read the exact) and then the DDR (mig_7series_0_memaddr) start at 0x80000000. So if the address of the variable pointer is 0x80000000 above, then it's getting stored in DDR. And in that case, it's already have it in RAM, so don't need to store it again :)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cbohra00627
    0 cbohra00627 over 3 years ago in reply to saadtiwana_int

    Oh, you don't need tools. It worked. It built successfully.

    So, does it mean that now my array will be stored in DDR instead of BRAM? Is there any way by which I can know between which addresses is this array getting stored on DDR?

    Now, if the array is already stored on the DDR, I don't need to store it again byte by byte using the Xil_Out8() as I was trying in  my code earlier, right?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cbohra00627
    0 cbohra00627 over 3 years ago in reply to Metaforest

    Well, I have already run the Hello World project and I have also been able to write to and read from both the BRAM and the DDR memory locations using the Xil_Out8() and Xil_In8() functions. Only after trying these I am trying to load the image.

    I haven't run the test projects yet. I guess I will try them.

    Thanks for your help!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Metaforest
    0 Metaforest over 3 years ago

    Make sure you have built and run the memory and platform test projects.  Make sure you understand how they work. Including the base address configuration in your Object diagram.  Prove you can read and write DDR with your own code.

    Loading image data into the DDR is more challenging.  There is a bootstrap project that Digilent developed for the Arty. It includes the SQI FLASH interface.  It allows you to store a bootstrap into the BITSTREAM.  Your DDR image is then stored as an attachment to the BITSTREAM in the SQI FLASH.  When the FPGA cold starts it loads the BitStream, which boots into the bootloader and then loads the DDR image from the SQI-FLASH.

    I've been able to do this with a Cora-z7 but it takes a lot of work to understand all the steps and get it right.  You also need to know your image is good to go. I'd start with a much smaller image; work up from hello world.  My experience with it was that the cold boot was not 100% reliable. Sometimes the FPGA would get confused because the debug interface is attached.  I found that it seemed to be stable when the Debug interface was not attached.   I have not done extensive testing.  I just proved that I could make the tools do it, and I understand the process on 2019.1  I have not tried it on more recent versions.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • saadtiwana_int
    +1 saadtiwana_int over 3 years ago in reply to cbohra00627

    On your linker script screenshot, as i remember, the "memory region" values are drop-down items. Right now everything is assigned to be saved to bram (as you can see in your screenshot). You can use the drop down to change the relevant ones to DDR instead. Try moving the following to DDR:
    .heap
    .stack
    .data
    .text

    See if it works? Again, sorry I don't have access to my tools right now, so my help is limited.

    Regards,
    Saad

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube