element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
  • 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
Blog Implementing Microblaze based Microcontroller on Arty S7-50 (7 Ways to Leave Your Spartan-6 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!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: cbohra00627
  • Date Created: 20 Jul 2022 3:41 PM Date Created
  • Views 2909 views
  • Likes 9 likes
  • Comments 0 comments
  • 7 Ways to Leave Your Spartan-6 FPGA
  • spartan-7
  • cbohra00627
  • Spartan_Migration
  • spartan-6
Related
Recommended

Implementing Microblaze based Microcontroller on Arty S7-50 (7 Ways to Leave Your Spartan-6 FPGA)

cbohra00627
cbohra00627
20 Jul 2022

Introduction:
In this blog we will work with the MicroBlaze Processor IP block, build a basic microcontroller using it and deploy it on the board. The MicroBlaze is a soft microprocessor core designed for Xilinx FPGAs. I have followed the Arty S7 Workshop series to build my first custom microcontroller.
The link to the original workshop is here.

Prerequisites:
If  you are new to this, I would advice you to go through my previous blog first to get used to Vivado interface.
You must have Vivado and Vitis installed.

Creating the Block Design:

  1. Create a new project. Select "Do not specify design sources at this time". Choose your board.
  2. Click on "Create Block Design" from the "IP Integrator" drop down menu in the left pane.
  3. Give your design a name and click on "OK".
    Design name
  4. Click on the '+' button ("Add IP") inside the Diagram window.
  5. Search "Microblaze" and insert it.
    Microblaze
  6. You can double click on any IP in Vivado to customize it but we don't need it now.
  7. Now, click on "Run Block Automation".
  8. In the "Run Block Automation" wizard, set the preset as "Microcontroller" and Local Memory to 128KB (it can be changed later as required). Click on "OK".
    Block Automation
  9. All the important blocks will be automatically added and appropriately connected.
    Schematic
  10. There is an interesting button (looks like a refresh icon) in the Diagram window to regenerate the layout, pressing which will make it easier to read. All the inputs will be shifted towards the left side of the MicroBlaze IP and all the outputs on the right side.
    Regenerated Schematic
  11. There is a board tab available on the left side of the Diagram window. It lists all the components which are present on the chosen board. We can simply drag any component to our work area and use it in our project.
    Board tab
  12. The Arty S7-50 board uses active low reset but the clocking wizard has active high reset as shown below (bubble on the pin means its active low). So, we need to change it.
    Active Low Reset
  13. To fix this, double click on the clocking wizard block.
  14. In the clocking wizard, go to the "Output clocks" tab, scroll down and select "Active Low" for Reset type. Click on "OK".
    (This will insert a bubble on the reset pin of the clocking block)
    Insert bubble
  15. Now, we need to add the "System Clock" from the "Board" menu to our Diagram. To do it just drag and drop these from the "Board" menu.
  16. Now, we need to add the "System Reset" from the "Board" menu to our Diagram. Click on "Run Connection Automation". A window will appear, select "All Automation" and click on "OK".
    (We could have used the Connection Automation before also but since our board have two clocks - DDR Clock and System Clock, it would have inserted the DDR Clock but we needed System Clock that's why we had to drag and drop it).
    Connection Automation
  17. Now our Diagram will look like something like shown below:
    New Diagram
  18. Now, click on "Add IP" and add "AXI Uartlite" IP block for communication.
    Add UARTlite
  19. Now, Run connection automation. Select "All Automation". Click on "OK".
  20. Our design will now look like this:
    New Design
  21. Now add "4 LEDs" and "4 Push Buttons" from the Board menu to your Diagram and run connection automation. Regenerate the Layout.
  22. Your design will look like this:
    Final Block Design
  23. You can validate your design by clicking on the "Validate Design" button inside the Diagram window (small tick icon).
  24. Now save your block design by clicking on the save button.
  25. Vivado needs to synthesize RTL. So, now we can create an HDL file from our Block Diagram.
  26. Go to the Sources tab, right click on the "design_1.bd" file and click on "Create HDL Wrapper". A window will open.
    HDL Wrapper
  27. The auto-update option means that if you make any changes to your Block Diagram, Vivado will automatically do the corresponding change in the HDL Wrapper file. Click on "OK".
  28. You can now see the HDL file for your design in the Sources tab.
  29. Now generate the bitstream for your design by clicking on "Generate Bitstream" in the left pane.
  30. Generating bitstream will take few minutes (around 10-20 mins), wait for it to complete. If it seems to be stuck click on cancel and try to generate it again.
  31. Now, we are done with Vivado. We have built the custom processor and the bitstream.
  32. We now need to move this file to our software development tool(Vitis).
  33. Go to File->Export->Export Hardware.
  34. Click on "Next".
  35. Select "Include Bitstream". Click on "Next".
    Include Bitstream
  36. You can change the name of your Hardware wrapper file (XSA file name) or just leave it as it is. Click on "Next".
    XSA name
  37. Click on "Finish".
  38. After the process finishes, go to "Tools" and click on "Launch Vitis IDE".
  39. You can close Vivado now.

Working on Vitis:

  1. After opening the Vitis IDE, select your workspace (your project folder) to open it. Click on "Launch".
    Vitis Workspace
  2. In the welcome window, click on "Create Application Project".
  3. Click on "Next".
  4. Now, it will ask to choose a platform. Click on "Create a new platform from hardware". Browse the XSA file inside the project folder that we created in Vivado and select it. Click on "Next".
    Choose platform
  5. Give your Application project a name. I have named it "hello_world". Click on "Next".
    Give name to application
  6. Leave the defaults as it is. Click on "Next".
  7. Select the "Hello World" application template and click on "Finish".
    Select Template
  8. Now, if you look at the "Explorer" tab on the left side, you will find "helloworld.c" file under the "src" drop down menu. Open this file.
    Explorer
  9. You can modify this code according to your wish. You need to save it after modifying.
  10. Now, click on "Build" (hammer like icon) to build the project.
  11. You can now connect your board to the computer.
  12. The communication between the MicroBlaze and our computer will take place through the UART. We need a serial monitor for this.
  13. After the build process finishes, go to Window->Show View.
  14. In the "Show View" window, go to "Terminal" drop down menu and select "Terminal". Click on "Open".
    Terminal
  15. A "Terminal" window will appear in the bottom right side of the screen.
  16. Now, click on "Open a Terminal" (monitor like icon) in the "Terminal" window.
  17. A "Launch Terminal" window will appear, in that select "Serial Terminal" and click on "OK".
    Launch Terminal
  18. This will open a serial terminal.
  19. Now we need to program our device. We could have done this earlier but we can do it from Vitis also. Just go to Xilinx->Program Device. This will open a window. Click on "Program".
    Program Device
  20. Now, to run our "helloworld.c" code on the board, just right click on "hello_world" in the "Explorer" tab, go to "Run As" and click on "Launch Hardware (Single Application Debug)".
  21. Now, if everything goes correct, you should be able to see your message (which you printed through your C code) in the terminal window.
    Successful execution

Controlling LEDs and Push Buttons through C code:

  1. We had included LEDs and Push Buttons in our design. So, we can now try to do something with them.
  2. Create a new application project by going to File->New->Application Project.
  3. Click on "Next".
  4. Select the platform that we earlier created (design_1_wrapper.xsa). Click on "Next".
  5. Write the name of your Application Project. I have named mine as "LEDs". Click on "Next".
  6. Click on "Next".
  7. Select "Empty Application(C)". Click on "Finish".
  8. Create a source file by right clicking on the "src" drop down menu, then click on "New", then click on "File". I have named my source file as "main.c".
  9. You will also need to copy some header files to your "src" folder. You can find these files in the "design_1_wrapper" drop down menu in the "Explorer" tab.
  10. Copy all the files as shown below.
    Header Files
  11. Now, copy the below given code in the source file and save it.
    #include "xparameters.h"
    #include "xgpio.h"
    #include "xil_printf.h"
    
    /************************** Constant Definitions *****************************/
    
    #define GPIO_DEVICE_ID  XPAR_GPIO_0_DEVICE_ID
    #define LED_DELAY     1000000
    #define LED_CHANNEL 1
    #define BUTTON_CHANNEL 2
    
    /**************************** Type Definitions *******************************/
    
    XGpio Gpio; /* The Instance of the GPIO Driver */
    
    int main() {
    
    	int Status;
    	int delay;
    	int buttons = 0;
    	int led = 0;
    
    	/* Initialize the GPIO driver */
    	Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
    	if (Status != XST_SUCCESS) {
    		xil_printf("Gpio Initialization Failed\r\n");
    		return XST_FAILURE;
    	}
    
    	/* Set data direction for LEDs (0 for input) and Push Buttons (1 for output) */
    	XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0b0000);
    	XGpio_SetDataDirection(&Gpio, BUTTON_CHANNEL, 0b1111);
    
    	while (1) {
    		/* Read the Status of Buttons */
    		buttons = XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL);
    
    		switch(buttons) {
    			case 0b0001:
    				led = 0b0001;
    				break;
    
    			case 0b0010:
    				led = 0b0010;
    				break;
    
    			case 0b0100:
    				led = 0b0100;
    				break;
    
    			case 0b1000:
    				led = 0b1000;
    				break;
    
    			default: led = 0b0000;
    		}
    
    		/* Set the LED to High */
    		XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, led);
    
    		/* Wait a small amount of time so the LED is visible */
    		for(delay=0; delay<=LED_DELAY; delay++);
    	}
    
    	return 0;
    }
  12. Click on "Build", then run it on the hardware. You will see the below mentioned functionality.
    • When a push button is pressed, the corresponding LED will turn ON.
    • When more than one push buttons are pressed simultaneously, all the LEDs will turn OFF.

Board Video:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Conclusion:

The block automation and the connection automation features made it very easy to build and connect the whole design correctly. The design can be easily transported between the Vivado and Vitis. The IP Integrator tool is a very good feature in Vivado which can be used to rapidly connect various IP blocks and with connection automation feature, it becomes very easy to implement our design in just a few minutes.

It takes a few minutes everytime I modify my C code and run it on the board. I wonder if there is some faster way to run the code!

  • Sign in to reply
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