UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Newbie bassdscho
Newbie
486 Views
Registered: ‎08-08-2016

XGpioPs_ReadPin not working, always returns 0

Jump to solution

Hi,

 

I need to program a custom subsystem reset sequence on a proprietary board using a Zynq-7000.

The board is up and running, booting into a Petalinux from FSBL to U-Boot to Petalinux.

 

The high level reset sequence looks like this:

 

  1. Assert Reset Output Low (lets say EMIO pin 1, call it RST_PIN)
  2. Wait 500ms
  3. Check that Input Pin (let's say EMIO pin 2, DONE_PIN) is high
  4. If DONE_PIN == 1 -> reset another subsystem (EMIO pin 3 / RST_PIN2); else -> go into a fail-safe recover mechanism

The reset sequence is working properly when done as a user land application in linux utilizing the /sys/class/gpio interface.

 

However, I need to do that earlier in the FSBL since it just takes too long waiting for petalinux to boot.

 

The problem is that I cannot read a single input pin state in the FSBL. XGpioPs_ReadPin() returns 0, always. Asserting output pins works as expected. I checked with a scope that the input pin actually changes levels. I also tried with a pushputton input pin on the board, it does not work either. Both pin states can be read successfully in linux.

 

The reset() function is called in the FsblHookAfterBitstreamDload() hook.

Edit: I tried to setup an interupt for the done pin in a rising edge, also no luck :/

 

What can possibly go wrong here?

 

Here's a code example for that (not sure if that compiles, slightly changed due to non-disclosure requirements)

 

#include "xparameters.h"
#include "xgpiops.h"
#include "xstatus.h"
#include "xspi.h"
#include "xspi_l.h"
#include "fsbl_debug.h"
#include "sleep.h"

#define GPIO_DEVICE_ID  XPAR_XGPIOPS_0_DEVICE_ID
static XGpioPs gpio;            /* driver instance of gpio device */
#define GPIO_INPUT_DIR  0
#define GPIO_OUTPUT_DIR 1
#define GPIO_LOW        0
#define GPIO_HIGH       1

#define RST_PIN 54
#define DONE_PIN 55
#define RST_PIN2 56

void gpio_init(void)
{
    int status;
    XGpioPs_Config* cfg;

    cfg = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
    status = XGpioPs_CfgInitialize(&gpio, cfg, cfg->BaseAddr);
    if (status != XST_SUCCESS)
    {
        fsbl_printf(DEBUG_INFO, "ERROR: could not initialize gpio driver \r\n");
    }

    XGpioPs_SetDirectionPin(&gpio, RST_PIN, GPIO_OUTPUT_DIR);
    XGpioPs_SetOutputEnablePin(&gpio, RST_PIN, GPIO_OUTPUT_DIR);
    XGpioPs_WritePin(&gpio, RST_PIN, GPIO_HIGH);

    XGpioPs_SetDirectionPin(&gpio, DONE_PIN, GPIO_INPUT_DIR);

    XGpioPs_SetDirectionPin(&gpio, RST_PIN2, GPIO_OUTPUT_DIR);
    XGpioPs_SetOutputEnablePin(&gpio, RST_PIN2, GPIO_OUTPUT_DIR);
    XGpioPs_WritePin(&gpio, RST_PIN2, GPIO_HIGH);
}

void toggle_rst1(void)
{
    XGpioPs_WritePin(&gpio, RST_PIN, GPIO_HIGH);
    XGpioPs_WritePin(&gpio, RST_PIN, GPIO_LOW);
    usleep(1);   /* 1 us (requirement: 500ns) */
    XGpioPs_WritePin(&gpio, RST_PIN, GPIO_HIGH);
}

void toggle_rst2(void)
{
    XGpioPs_WritePin(&gpio, RST_PIN2, GPIO_HIGH);
    XGpioPs_WritePin(&gpio, RST_PIN2, GPIO_LOW);
    usleep(2 * 1000);   /* 2 ms */
    XGpioPs_WritePin(&gpio, RST_PIN2, GPIO_HIGH);
}

u32 is_done(void)
{
    return XGpioPs_ReadPin(&gpio, DONE_PIN);
}

void reset(void)
{
    gpio_init();

    fsbl_printf(DEBUG_INFO,"reset subsystem ... \r\n");
    toggle_rst1();

    usleep(500 * 1000); /* 500ms */
    
    if(is_done())
    {
        fsbl_printf(DEBUG_INFO,"reset subsystem 2 ... \r\n");
        toggle_rst2();
    }
    else
    {
        /* failsafe handling */
    }
}

 

0 Kudos
1 Solution

Accepted Solutions
Newbie bassdscho
Newbie
564 Views
Registered: ‎08-08-2016

Re: XGpioPs_ReadPin not working, always returns 0

Jump to solution

Found the solution: Have to call that Input / Interrupt stuff in the Before Handoff Hook, since only then the PS-PL level shifters are configured correctly.

1 Reply
Newbie bassdscho
Newbie
565 Views
Registered: ‎08-08-2016

Re: XGpioPs_ReadPin not working, always returns 0

Jump to solution

Found the solution: Have to call that Input / Interrupt stuff in the Before Handoff Hook, since only then the PS-PL level shifters are configured correctly.