Jump to content
  • 0

Blink CMOD-A7 LED withOUT Pmod IPs


RichardV

Question

Hello, I created a block diagram that has a axi_gpio_0 block, as you can see in my image. Below is most of my constraint file. My diagram synthesizes, implements and generates a bitstream. I was able to get into SDK with no problems. I am stuck in SDK now.

 

Goal: I am just trying to blink an LED (gpio_io_o[4]) using one of the the example code projects shown in system.mss file. I chose the "xgpio_example.c"; first on the list. The example code has these lines: #define LED 0x01   and    #define LED_CHANNEL 1.

This code should just simply blink an LED. I am not sure if LED_CHANNEL is channel "1", or what "LED_CHANNEL" means in the code. Using these original settings my LED did not blink or light up at all. Looking at my constraint file, you will see that I am using gpio_io_o[4] and gpio_io_o[5] for my LEDs, so I changed the first line to #define LED 0x04. This had no effect.

I tried everything I could think of. For example, I tried making a change like this: #define LED_CHANNEL 4, but this had no effect. I tried many combinations of things.

Using the oscilloscope, I looked at all of the pins on the PMOD connector, but nothing is active. I'm sure I programmed the FPGA and code correctly since the processes went smoothly.

I'm trying to avoid using any IP blocks other than the built in axi_gpio blocks. Those IP blocks from example code do not TEACH us anything and are rather useless in that regard. I've looked all over, but cannot find a working version of "BLINKY" code (which is fairly standard in MCU and Microprocessor examples). Can someone please point out a decent GPIO tutorial that actually works?

 

Here is a sample of the code:   XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);

The "LED_CHANNEL" AND ~LED parameters are confusing. Why is LED inverted? For example, if LED = 0x01, then ~LED = 0xfffffffe. Why?

 

Thank you, Richard V

 

My constraint file:

# LEDs
set_property -dict { PACKAGE_PIN A17   IOSTANDARD LVCMOS33 } [get_ports { gpio_io_o[4] }]; #led[0] }]; #IO_L12N_T1_MRCC_16 Sch=led[1]
set_property -dict { PACKAGE_PIN C16   IOSTANDARD LVCMOS33 } [get_ports { gpio_io_o[5] }]; #led[1] }]; #IO_L13P_T2_MRCC_16 Sch=led[2]

Here are my other GPIO bits:

#OLED
set_property -dict { PACKAGE_PIN G17   IOSTANDARD LVCMOS33 } [get_ports { spi_0_ss_io[0] }]; #CS   #IO_L5N_T0_D07_14 Sch=ja[1]
set_property -dict { PACKAGE_PIN G19   IOSTANDARD LVCMOS33 } [get_ports { spi_0_io0_io   }]; #MOSI #IO_L4N_T0_D05_14 Sch=ja[2]
set_property -dict { PACKAGE_PIN N18   IOSTANDARD LVCMOS33 } [get_ports { spi_0_io1_io   }]; #MISO #IO_L9P_T1_DQS_14 Sch=ja[3]
set_property -dict { PACKAGE_PIN L18   IOSTANDARD LVCMOS33 } [get_ports { spi_0_sck_io   }]; #SCK  #IO_L8P_T1_D11_14 Sch=ja[4]
set_property -dict { PACKAGE_PIN H17   IOSTANDARD LVCMOS33 } [get_ports { gpio_io_o[0]   }]; #DC   #IO_L5P_T0_D06_14 Sch=ja[7]
set_property -dict { PACKAGE_PIN H19   IOSTANDARD LVCMOS33 } [get_ports { gpio_io_o[1]   }]; #RES  #IO_L4P_T0_D04_14 Sch=ja[8]
set_property -dict { PACKAGE_PIN J19   IOSTANDARD LVCMOS33 } [get_ports { gpio_io_o[2]   }]; #VBAT #IO_L6N_T0_D08_VREF_14 Sch=ja[9]
set_property -dict { PACKAGE_PIN K18   IOSTANDARD LVCMOS33 } [get_ports { gpio_io_o[3]   }]; #VDDC #IO_L8N_T1_D12_14 Sch=ja[10]

 

This is an excerpt from the example code and was generated by SDK:

#include "xparameters.h"
#include "xgpio.h"

/************************** Constant Definitions *****************************/

#define LED 0x01   /* Assumes bit 0 of GPIO is connected to an LED  */

/*  The following constants map to the XPAR parameters created in the  * xparameters.h file. They are defined here such that a user can easily  * change all the needed parameters in one place. */
#define GPIO_EXAMPLE_DEVICE_ID  XPAR_GPIO_0_DEVICE_ID

/* * The following constant is used to wait after an LED is turned on to make  * sure that it is visible to the human eye.  This constant might need to be * tuned for faster or slower processor speeds. */
#define LED_DELAY     1000000

/*  * The following constant is used to determine which channel of the GPIO is  * used for the LED if there are 2 channels supported.  */

#define LED_CHANNEL 1

/**************************** Type Definitions *******************************/

* The purpose of this function is to illustrate how to use the GPIO * driver to turn on and off an LED.*

* @param    None

** @return    XST_FAILURE to indicate that the GPIO Initialization had
*        failed.
** @note        This function will not return if the test is running.
*
******************************************************************************/
int main(void)
{
    u32 Data;
    int Status;
    volatile int Delay;

    /* Initialize the GPIO driver */

    Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);

    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    /* Set the direction for all signals as inputs except the LED output */

    XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);

 

design_spi_oled.pdf

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

Hi @RichardV,

Here is the CmodA7-OOB demo that does a memory test as well as uses the leds, RGB led and the buttons. I was able to completely run this project in vivado 2016.4 with not issues. The sdk code for this is visible and should be a good reference. Once you have generated a bitstream in vivado, next export the hardware and launched sdk. Once in sdk import the project folders from the sdk folder. The main in located in memorytest.c. 

cheers,

Jon

Link to comment
Share on other sites

Hello Jon. Respectfully, this is the first GPIO example that I became frustrated with and abandoned. It does not generate a bitstream as is. Attached is the message. I tried creating a wrapper for the "top module", but the program is "locked" and won't let me. In any case, it doesn't work "as is". I'm using version 2016.2 too. I don't know if using this older version is part of the problem.

Okay, skipping Vivado, I opened SDK, but no project file was located. At first I thought creating the Vivado Project emptied the SDK of the project, but I started all over from the zip file again. There is no SDK code to look at.

The biggest problem of all is that this design does not use a constraint file to route the LEDs. I don't want to drive just the LEDS; I also want to drive ANY general purpose GPIO pin (like on the PMOD connector).

I see the "ports" are used to do this routing, which is what I want to avoid.

Attached is my block diagram, and my source code. I merged the polled SPI example with a GPIO example and it kind of works. I have multiple LEDS. Two are the built in LEDs that you will see connected through a port (even though I want to avoid this, I can't). You will see some other pins on that port. I'm trying to use one of them to drive an LED.

The problem is that I can't drive both the PMOD LED and the on-board LED at the same time. The PMOD is on Channel 2, and the built in wants to be on Channel 1. You can also see that I have attached my constraint file to help explain what I am trying to do.

Would you please take a look at this from the point of view of someone trying to drive the LEDS a general purpose IO bits using a constraint file to route signals?

Thank you, Richard V

Cmod-A7-15T-OOB Error Message.png

modified_xspi_polled_example.c

design_spi_oled.pdf

cmoda7_oled.xdc

Link to comment
Share on other sites

@RichardV

For the locked IPs, this is a version mismatch, specific versions of Xilinx IPs are tied to specific versions of Vivado, it is usually straightforward to upgrade them when you are going from an old version of Vivado to a newer one. I am not sure about the process for the other direction, Jon may be able to help more with this. The majority of our demos are currently distributed targeting 2016.4.

For Vivado SDK, you may need to import the SDK projects contained in the /sdk subdirectory of the directory extracted from Cmod-A7-15/35T-OOB.zip. This process is covered in the "Launch from Vivado" option for step 4 of this tutorial, which is linked in the project page that Jon provided. At the very least, you can find and open the source files for the project (found in /sdk/user/src/) in your text editor of choice. In order to view Board Support Package sources, you will need to open the project in SDK, by following either the SDK without Vivado or Vivado and SDK path of the tutorial linked above.

What does it look like when you expand the GPIO interface of the axi_gpio_0 block? Assuming that the GPIO block has that first channel configured to a Custom interface, 2 bit wide, output only, you should be able to right click on the gpio_io_o pins inside of the expanded interface, and select Make External, as long as the names of these pins match the appropriate ports in your XDC, you should be fine. This is the typical way of tying a block design to an XDC file.

Thanks,

Arthur

Link to comment
Share on other sites

Hello. Thank you Arthur. Yes, I get that now. I'm downloading the latest version of Vivado and trying again.

Back to my main problem though:

I have new information. I did some debugging and I found that this "XGpio_DiscreteRead" function isn't returning the correct value. Please see my posted code. Here are two lines that do the same thing. One works, and the other does not:

                Data = XGpio_DiscreteRead(&Gpio, LED_CHANNEL);        // This line does work.
                //Data = XGpio_DiscreteRead(&Gpio, PMOD_CHANNEL);    // This line doesn't work! Always "0"

As you see I commented out the line that doesn't work. I keep getting a "00000000" value even though this is just a register that it is reading back.

Here is the whole loop just to provide some context:

        while (1) {

                Data = XGpio_DiscreteRead(&Gpio, LED_CHANNEL);        // This line does work.
                //Data = XGpio_DiscreteRead(&Gpio, PMOD_CHANNEL);    // This line doesn't work!

                if (Data & LED) {
                        XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, Data & ~LED);
                        XGpio_DiscreteWrite(&Gpio, PMOD_CHANNEL, Data & ~RST_LED);
                }
                else {
                        XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, Data | LED);
                        XGpio_DiscreteWrite(&Gpio, PMOD_CHANNEL, Data | RST_LED);
                }
                for (Delay = 0; Delay < LED_DELAY; Delay++); // Wait a small amount of time so the LED is visible

        }

This code works to make both LEDs blink together. When I use the line that does not work both LEDs do nothing (always on). The variable "Data" is always set to 0.

Since this is just reading back a register, I have no clue as to how to fix this. Can anyone tell me what I did wrong?

 

Thank you, Richard V

 

 

 

Link to comment
Share on other sites

Hi @RichardV,

I just completed a project that the leds and the pmod pins you are wanting to use change at the same time. This should help you get your sdk code to work.  I have included the vivado wrapper, xdc and sdk code as well as the project done in 2016.4. I have also included a screen shot of the block design and the logic analizer showing the pin is toggling. I included a picture of my wiring setup as well.

cheers,

Jon

20170629_152939.zip

CmodA7_block_diagram.jpg

cmodA7_waveforms.jpg

CmodA7_wrapper.txt

CmodA7_xdc_pmod.xdc

CmodA7_led_Pmod_led.txt

cmodA7_2_leds.zip

Link to comment
Share on other sites

Thank you Jon, but I can't open this project with 2016.2 or the latest 2017.4. Below you can see the problem I get with 2017.4. I do not have the "IP" that this code wants, so I can't see the block diagram at all this time. Version 2016.2 indicates that the blocks are from a "future version". Version 2017.4 doesn't recognize the board you're using.

Do I really have to load EVERY single example board into Vivado just to get these examples working?

Thank you, Richard

New Vivado Problems.png

Link to comment
Share on other sites

Hello again Jon. I installed my board file, updated the files and got it to generate a bitstream. However, I cannot open SDK. here is the message (attached).

I went into Explorer and set the properties of the directory and all sub-directories to uncheck that "Read Only" box. However, Vivado keeps making it "Read Only" and I can't do anything about it. SDK will not open this project.

Can you please tell me why?

Thank you, Richard V

SDK wont open in 2017 code.png

Link to comment
Share on other sites

Hello again Jon. I have narrowed down the problem to 1 line of code.

        Data = XGpio_DiscreteRead(&Gpio, LED_CHANNEL);             // Read does work here
        //Data = XGpio_DiscreteRead(&Gpio, PMOD_CHANNEL);       // Read doesn't work here
          

The top line works. I can read back the register that sets the LED_CHANNEL. However, the line below does not work. I cannot read back the value of PMOD_CHANNEL.

I have watched this in the debugger window with a watch on the Data variable. The second line always returns 0, no matter what the real state of PMOD_CHANNEL is. Writing to PMOD_CHANNEL does work as an output. I can see the correct LED change.

I tried changing using the automated connection and it came up with port gpio_rtl. I turned off the box for "all outputs" on GPIO2. I also tried using the "tristate" before doing this. I also changed my XDC file in response to the errors that first showed up. I get a good bitstream and it runs just as well.

I have added a debug window where I added duplicated instances of the Data variable and gpio driver. The output works fine, but again Data2 just never updates. Why is only 1 variable shown in Yellow? I think this is an important clue since I can't read anything into Data2.

This readback of GPIO2 (channel 2) is the only issue I am having, Could you please help me debug this 1 line of code?

Thank you, Richard

gpio_design_spi_oled.pdf

Debug Window 2 Variables.png

Link to comment
Share on other sites

Hi @RichardV,

I usually use serial prints mostly to trouble shoot my issues so I am not sure why the line is highlighted. Would you be able to attach your project or share it on something like google drive? If not could you attach your wrapper, xdc and the sdk code. Another way to trouble shoot this issue would be to use something like my sdk code initially just to get the pins working and then deal with the logic that you want to occur. 

cheers,

Jon

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...