Example: MB_16p2_07_PeripheralTestWorks
This design works and does the peripheral test over the UART. Unlike the example below, the "reset" issue was finally fixed by setting the "reset" in from the board to an active high and using the Locked output from the Clocking Wizard for the Processor System Reset ext_reset_in. (Creating the design was similar to the steps outlined below, except for these changes mentioned which were done after verifying the design.) The Microblaze uses 32 kB memory but no cache.
The design wrapper is given below:
module design_1_wrapper
(dip_switches_16bits_tri_i,
led_16bits_tri_o,
reset,
sys_clock,
usb_uart_rxd,
usb_uart_txd);
input [15:0]dip_switches_16bits_tri_i;
output [15:0]led_16bits_tri_o;
input reset;
input sys_clock;
input usb_uart_rxd;
output usb_uart_txd;
wire [15:0]dip_switches_16bits_tri_i;
wire [15:0]led_16bits_tri_o;
wire reset;
wire sys_clock;
wire usb_uart_rxd;
wire usb_uart_txd;
design_1 design_1_i
(.dip_switches_16bits_tri_i(dip_switches_16bits_tri_i),
.led_16bits_tri_o(led_16bits_tri_o),
.reset(reset),
.sys_clock(sys_clock),
.usb_uart_rxd(usb_uart_rxd),
.usb_uart_txd(usb_uart_txd));
endmodule
The modified SDK files are shown below. (The original files created by SDK did not include the GPIO led_16bits. I added the changes to include the GPIO output.)
#include <stdio.h>
#include "xparameters.h"
#include "xil_cache.h"
#include "xgpio.h"
#include "gpio_header.h"
int main()
{
Xil_ICacheEnable();
Xil_DCacheEnable();
print("---Entering main---\n\r");
{
u32 status;
print("\r\nRunning GpioInputExample() for axi_gpio_0...\r\n");
u32 DataRead;
status = GpioInputExample(XPAR_AXI_GPIO_0_DEVICE_ID, &DataRead);
if (status == 0) {
xil_printf("GpioInputExample PASSED. Read data:0x%X\r\n", DataRead);
}
else {
print("GpioInputExample FAILED.\r\n");
}
status = GpioOutputExample(XPAR_AXI_GPIO_0_DEVICE_ID, 16);
if (status == 0) {
xil_printf("GpioOutputExample PASSED. Read data:0x%X\r\n", DataRead);
}
else {
print("GpioOutputExample FAILED.\r\n");
}
}
print("---Exiting main---\n\r");
Xil_DCacheDisable();
Xil_ICacheDisable();
return 0;
}
Also the xgpio_tapp_example file was modified to accomodate the two different GPIO channels, "1" for input and "2" for output. See the added / modified code snippet from this file:
#define LED_CHANNEL 2
#define LED_CHANNELIN 1
int GpioInputExample(u16 DeviceId, u32 *DataRead)
{
int Status;
/*
* Initialize the GPIO driver so that it's ready to use,
* specify the device ID that is generated in xparameters.h
*/
Status = XGpio_Initialize(&GpioInput, DeviceId);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
/* Set the direction for all signals to be inputs */
XGpio_SetDataDirection(&GpioInput, LED_CHANNELIN, 0xFFFFFFFF);
/* Read the state of the data so that it can be verified */
*DataRead = XGpio_DiscreteRead(&GpioInput, LED_CHANNELIN);
//New try this! Seems to work
// XGpio_DiscreteWrite(&GpioInput, 2, 0xff);
return XST_SUCCESS;
}
The design only worked after using the "reset" settings shown above, i.e., reset active high and only connected to Clocking Wizard and not to the Processor System Reset's ext_reset_in. With the settings shown below (which are similar to the sample Xilinx design, however these are Active High), the reset button must be pressed for the entire program execution.
By default, reset on the BASYS3 board is LO; pressing it makes it go HI.
The scope screen shot below shows what happens when reset is first pushed:
Channel 1: (Top) is the "reset" button being pushed and going high
Channel 2: is is Clocking Wizard's "locked" output going low because of the reset
Channel 3: is the sys_clock which is not affected by this
Channel 4; (Bottom) is the Clocking Wizard's "clk_out1" which is terminated because of the reset.
Once reset is released the following occurs:
Channel 1: (Top) is the "reset" button being released and its output goes low again.
Channel 2: about 22 usec later, the Clocking Wizard's "locked" output goes high again and its clock is runing again.
Channel 3: is the sys_clock which is not affected by this but cannot be observed on this screen shot due to aliasing.
Channel 4; (Bottom) is the Clocking Wizard's "clk_out1" which again cannot be observed due to the scope's aliasing. Nevertheless, from the picture below it can be seen that the clock becomes active about 10 after the reset was released.
(Note the 10.00 us offset in the horizontal position.)
Finally, the screen shot below shows the Processor System Reset's mb_reset (channel 3) which goes temporarily high after reset (channel 1) is released; mb_reset goes low once the "locked" output (channel 2) goes high. Ignore the bottom trace.
In short:
the reset in goes high when pushed and the low again when it is released.
Once the reset goes high, the clocking wizard's locked output stays low; it goes high again about 22 usec after the reset has been released and has gone back to low.
About 10 usec after the reset was released, the Processor System Reset sends a high to the MB reset; the MB restarts once the clocking wizard has been locked again.
This example uses the Microblaze with the AXI interface and the UARTlite and sends a "Hello World" message to the terminal. The application only works as long as you keep pressing the 'reset' button. See example above on how to fix it.
See: MB_16p2_HelloworldWorks
Steps to create the design:
In Vivado, create a Block Design; drag the System Clock from the "Board" tab into the design; doulbe click on it and set under Output Clocks tab Reset Type to Active Low; don't run connection automation;
Add the Microblaze IP from the IP sources; run block automation and use 32 kB ofr Local Memory ; don't use data and instruction cache; run connection automation;
drag the USB UART from the Board into the design (double click it to change the BAUD rate to 115000) and run connection automation;
Verify design; reset should be active LOW;
Create the design Wrapper by clicking in the Block Design on the Design_1 and selecting "Create Design Wrapper";
run synthesis
File / Export / Export Hardware (do not include the bitstream)
File / Launch SDK
In SDK, create File / New / Application Project / give it a name and select the hello world project.
Back in Vivado, generate the bitstream; while it's churning along, open the a Terminal program (or use SDK) and connect to your remaining USB port.
Once the bitstream has been generated, use the hardware manager to program the board.
When you press the design's reset button on the BASYS board, which is the center button, BTNC, and NOT the upper red button, you should see the "Hello world" message in the terminal window.