1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Resolved] Mimas V2, Can't Read Registers

Discussion in 'FPGA Boards' started by thomascheney, Jun 17, 2016.

Thread Status:
Not open for further replies.
  1. thomascheney

    thomascheney New Member

    Joined:
    Jun 17, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Location:
    United States
    I'm just trying to read the button registers in a C Microblaze environment, but nothing I have tried works. I keep getting all zeroes regardless of what I do.

    I've tried the following sets of code all with the same results (inside each set of curly braces is a different attempt):

    {
    XGpio_ReadReg(XPAR_PUSHBUTTONSWITCHES_BASEADDR ,0);
    }

    {
    Xil_In32LE(XPAR_PUSHBUTTONSWITCHES_BASEADDR);
    }

    {
    Xil_In32{XPAR_PUSHBUTTONSWITCHES_BASEADDR}
    }

    {
    XGpio GpioInput;
    XGpio_Initialize(&GpioInput, XPAR_PUSHBUTTONSWITCHES_DEVICE_ID);
    XGpio_SetDataDirection(&GpioInput, 1, 0xFFFFFFFF);
    XGpio_DiscreteRead(&GpioInput, 1)
    }

    {
    u32 *cur_but = 0;
    GpioInputExample(XPAR_PUSHBUTTONSWITCHES_DEVICE_ID, cur_but);
    }

    }
    uint32_t buttons_readGpioRegister(uint32_t offset) {
    // Note that you have to include a cast (uint32_t *) to keep the compiler happy.
    // I included the base address for the buttons directly from xparameters
    uint32_t *ptr = (uint32_t *) XPAR_PUSHBUTTONSWITCHES_BASEADDR + offset;
    return *ptr;

    buttons_readGpioRegister(0);
    }


    All of these just read out as all zeroes, not matter which buttons are pressed/not pressed. In all cases I put the read function as well as a way to print in a while (1) loop. What is the proper way to read the registers to see the value of the buttons?
     
    Last edited: Jun 17, 2016
  2. rohith

    rohith Administrator Staff Member

    Joined:
    Mar 3, 2016
    Messages:
    66
    Likes Received:
    11
    Trophy Points:
    8
    Gender:
    Male
    Location:
    Bangalore
    Hi,

    I used this code with MimasV2 and it worked quite okay for me. MimasV2 has active-low push-buttons so unpressed state is all 6 buttons high (0b111111) or (0x3F).

    Code:
    #include <stdio.h>
    #include "platform.h"
    #include "xparameters.h"
    #include "xgpio_l.h"
    
    void print(char *str);
    
    int main()
    {
        init_platform();
    
        XGpio_WriteReg((XPAR_GPIO_0_BASEADDR),XGPIO_TRI_OFFSET, 0xFFFFFFFF);
        u32 Data, NewData;
    
        while(1) {
            NewData = XGpio_ReadReg(XPAR_GPIO_0_BASEADDR, XGPIO_DATA_OFFSET);
            if (NewData != Data)
                xil_printf("Data: 0x%x\n\r", NewData);
            Data = NewData;
        }
        return 0;
    }
    
    
    And I get this kind of output:
    MimasV2GpioRead.PNG
     
    Alexander Lang likes this.
  3. thomascheney

    thomascheney New Member

    Joined:
    Jun 17, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Location:
    United States
    Hi, thanks very much for the great reply. When I use your code, however, I get the same result. It won't print unless I take out the If statement, and when I do, it just prints out "Data: 0x00" on every line.

    I suppose there may be something wrong with the hardware setup. I followed the tutorial at http://numato.com/learning-fpga-and-verilog-a-beginners-guide-part-5-embedded-system, except I left all the IPs in the spot where it says to take them all out except the UART.
     
  4. rohith

    rohith Administrator Staff Member

    Joined:
    Mar 3, 2016
    Messages:
    66
    Likes Received:
    11
    Trophy Points:
    8
    Gender:
    Male
    Location:
    Bangalore
  5. thomascheney

    thomascheney New Member

    Joined:
    Jun 17, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Location:
    United States
    I got the following error when I tried to construct the bin file:

    ERROR:Data2MEM:33 - Matching ADDRESS_SPACE for code segment #1 not found in 'C:\
    Users\ecestudent\Desktop\mimas\mimasV2GpioRead\SDK\SDK_Export\hw\system_bd.bmm'.

    Code segment #1 occupies [0xA4000000:0xA40014E9]

    I had to map the memory to the bram in the linker script before it would allow me to construct the bin file. Should it work while mapped to the ddr? Once I did get the bin file built though, the result was the same, and nothing printed out.

    Also, would it be possible to send a bin file from the project that you know is working and I'll try loading that. Thanks for your continued help.
     
    Last edited: Jun 22, 2016
  6. rohith

    rohith Administrator Staff Member

    Joined:
    Mar 3, 2016
    Messages:
    66
    Likes Received:
    11
    Trophy Points:
    8
    Gender:
    Male
    Location:
    Bangalore
  7. thomascheney

    thomascheney New Member

    Joined:
    Jun 17, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Location:
    United States
    OK, awesome, that worked. Could the computer I'm building on affect the bin file? I've got a MAC running Windows, and that is the only thing I can really think of that could be causing the issue, because I used your exact project to build the other bin file.

    Also, how do you build your bin file once you have the elf, bit, and bmm files.
     
    Last edited: Jun 24, 2016
  8. thomascheney

    thomascheney New Member

    Joined:
    Jun 17, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Location:
    United States
    OK, so I built it on a PC with the same result, so I guess it isn't the Mac hardware that is causing the problem. However, I still have the question with how I'm building the bin. I just followed the tutorial provided by you guys for that as well. I'm running the following three commands:

    call "c:\Xilinx\14.7\ISE_DS\settings64.bat"
    data2mem -bm "system_bd.bmm" -bd "helloWorld.elf" -bt "system.bit"
    promgen -w -p bin -u 0x0 "system_rp.bit" -spi -o "download_me.bin"
     
  9. rohith

    rohith Administrator Staff Member

    Joined:
    Mar 3, 2016
    Messages:
    66
    Likes Received:
    11
    Trophy Points:
    8
    Gender:
    Male
    Location:
    Bangalore
    Hi thomas,

    Did you get this issue resolved? These commands should work properly. I can't think of any reason they shouldn't. Would be interesting to know if there is some peculiarity going on.
     
Thread Status:
Not open for further replies.

Share This Page