Forum Discussion
Altera_Forum
Honored Contributor
9 years agoHPS GPIO's ouputs stuck in high impedence?
I have an issue regarding a custom board the GPIOs where all the HPS IO’s are set to high impedance no matter to how they are set.
I have tested the following:- GPIO system on linux enabling each of the GPIOs as an output through the controller... and writing values to them... (findings it changes to output state but the value doesn’t alter and reads back high - unchanged)
- GPIO controller address read/write (findings values don’t change)
- Pre-Linux Hardware GPIO Loaning Pins driving a value change on preloader startup to enable a LED (findings no value on GPIO changes value)
31 Replies
- Altera_Forum
Honored Contributor
Hi Kyle,
even I was trying to access GPIO using DEO nano but faced issues...did you get any answer??..should we change the high impedance state in Linux boot if so how?? --Ravi - Altera_Forum
Honored Contributor
Hi Ravi,
I've Fixed this issue for both the GPIO and LOAN IO. GPIO Just make sure when you enable the GPIO's in the peripheral pins in Qsys... that you update the Assignment editor page to include your linked pin eg. hps_io_hps_io_gpio_inst_GPIO49 => HPS_GPIO49 -- loans out to the Top level Port HPS_GPIO49 so add this to Assigments > Assignment editor To [HPS_GPIO49] Assignment Name [I/O Standard] Value [Voltage value of output] Recompile the project and the GPIO should be available. LOAN pins are different you need make sure from your Qsys design you export the loanio pins back into your top level design. hps_0_h2f_loan_io_in : out std_logic_vector(66 downto 0); hps_0_h2f_loan_io_out : in std_logic_vector(66 downto 0) := (others => '0'); hps_0_h2f_loan_io_oe : in std_logic_vector(66 downto 0) := (others => '0'); the inputs are assigned to the in... and the outputs to outputs... (when they are output make the oe vector for that pin 1 to enable it as an output) This is pretty much it... happy to help the documentation is brief but pretty much it works well once you do this. Good Luck Kyle - Altera_Forum
Honored Contributor
" Hi kyle,
when you go to Assignment Editor there are 2 rows you see for each pins GPIO_1[0] Location( This is changed to HPS_IO) and select Enable(Yes) GPIO_1[1] I/O standard 3.3 V LVTTL Once I did this and compiled and flashed the .SOF then Pin 2 of GPIO_1 cannot be accessed. I have a C file which changes the Set bits and Clr bits..But I am not able to take control of the GPIO_1 pin.Is there any jumper which we need to change.also are my configurations correct. Once I get one pin I can map for others. Kindly let me know." regards Ravi - Altera_Forum
Honored Contributor
Hi Kyle,
Thanks for your support...also would like to know if there are any configurations in the Assignments->Device->Deviceandpinoptions->Unused pins (An input Tristated) to access the pin and see the output. I am using a C file which has hps.h through which I assign GPIO1_SWPORTA_DR_ADDR and configuring these registers to get the output. eg: # include <stdio.h> # include <unistd.h> # include <fcntl.h> # include <sys/mman.h> # include "hwlib.h" # include "soc_cv_av/socal/socal.h" # include "soc_cv_av/socal/hps.h" # include "soc_cv_av/socal/alt_gpio.h" # define HW_REGS_BASE ( ALT_STM_OFST ) # define HW_REGS_SPAN ( 0x04000000 ) # define HW_REGS_MASK ( HW_REGS_SPAN - 1 ) # define USER_IO_DIR (0x01000008) # define BIT_LED (0x01000008) # define BUTTON_MASK (0x02000000) int main(int argc, char **argv) { void *virtual_base; int fd; uint32_t scan_input; int i; // map the address space for the LED registers into user space so we can interact with them. // we'll actually map in the entire CSR span of the HPS since we want to access various registers within that span if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) { printf( "ERROR: could not open \"/dev/mem\"...\n" ); return( 1 ); } virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE ); if( virtual_base == MAP_FAILED ) { printf( "ERROR: mmap() failed...\n" ); close( fd ); return( 1 ); } // initialize the pio controller // led: set the direction of the HPS GPIO1 bits attached to LEDs to output alt_clrbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR) & ( uint32_t )( HW_REGS_MASK ) ) ), BIT_LED ); alt_setbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR) & ( uint32_t )( HW_REGS_MASK ) ) ), USER_IO_DIR ); so this should work..Let me know get some idea --Ravi - Altera_Forum
Honored Contributor
Ravi,
The Assignment editor needs to be set to Assignment Name [I/O Standard] this is a must is shouldn't be a "location" on the FPGA as there is no location it goes through into the preloader and is linked there. The Value is instead set to the Voltage level [3.3-V LVCMOS] your maybe less depending on the hps powered IO's it could be 2.5V or lower please check this. Enabled is yes too so that would be correct. Please try the linux commands from the HPS command line first (before memory mapping) to make sure that the GPIO's can be set... follow this tutorial for setting the GPIO's If there are LED's then you should be just write a active low or high signal to them from the command line.... Follow this tutorial and see if the LED's light on the gpio then you can start to progress into the memory mapping application code.. http://falsinsoft.blogspot.co.uk/2012/11/access-gpio-from-linux-user-space.html It looks like your code is correct but you need to just make sure that the GPIO is controllable from the drivers in linux the following echo commands will help you enable an GPIO output (number is significant please find out the number of the GPIO from linux and cyclone V handbook for specifying the correct GPIO) here 192 is used as this is from the GPIO controller 2 and is the 1st one your number will be different please check for your correct one. echo 192 > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio192/direction echo 1 > /sys/class/gpio/gpio192/value echo 0 > /sys/class/gpio/gpio192/value The first echo line enables the gpio.... if you get problems here the gpio is already attached to a linux driver and will need removing (look into removing a driver) The second enables that channel to become an output as all gpio's are either in or output the default is always input so this enables you send the gpio as high or low...etc The next 2 lines will write a high or low value to that gpio you should see the light move on and off if it is correctly enabled. Best of luck Kyle Without finding problems you never learn. - Altera_Forum
Honored Contributor
Hi kyle,
Not able to get the GPIO toggle working for GPIO_1 any suggestions from your side where in assignment editor changes need to be made so that we can toggle the switch??.will really help if you reply.waiting for your response regards Ravi chandran - Altera_Forum
Honored Contributor
Hi kyle,
thanks for your reply.I tried the way you told using the Linux but this did not work.The GPIO was not accessible.so from linux itself I am not able to control.if we solve this then user space code will work. My Assignment editor looks like this the 2 rows for each pin original To:GPIO_1[1] Assignment name-> Location PIN_Name(value) Enabled(yes) GPIO_1[1] Assignment name-> I/O standard 3.3V LVTTL(value) Enabled(yes) My changed version To:GPIO_1[1] Assignment name-> HPS_IO ON(value) Enabled(yes) GPIO_1[1] Assignment name-> I/O standard 3.3V LVTTL(value) Enabled(yes) Is this correct ??.. Like this I need to enable for all other pins.Is there any thing I missed assigning here???..Let me know.Any configuration changes. In the device option also I have chooseb UNUSED pin as INPUT state TRIGERRED. created the .SOF and programmed and ran the linux command but did not work..Kindly let me know if you see any errors here thanks in advance --Ravi --- Quote Start --- Ravi, The Assignment editor needs to be set to Assignment Name [I/O Standard] this is a must is shouldn't be a "location" on the FPGA as there is no location it goes through into the preloader and is linked there. The Value is instead set to the Voltage level [3.3-V LVCMOS] your maybe less depending on the hps powered IO's it could be 2.5V or lower please check this. Enabled is yes too so that would be correct. Please try the linux commands from the HPS command line first (before memory mapping) to make sure that the GPIO's can be set... follow this tutorial for setting the GPIO's If there are LED's then you should be just write a active low or high signal to them from the command line.... Follow this tutorial and see if the LED's light on the gpio then you can start to progress into the memory mapping application code.. http://falsinsoft.blogspot.co.uk/2012/11/access-gpio-from-linux-user-space.html It looks like your code is correct but you need to just make sure that the GPIO is controllable from the drivers in linux the following echo commands will help you enable an GPIO output (number is significant please find out the number of the GPIO from linux and cyclone V handbook for specifying the correct GPIO) here 192 is used as this is from the GPIO controller 2 and is the 1st one your number will be different please check for your correct one. echo 192 > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio192/direction echo 1 > /sys/class/gpio/gpio192/value echo 0 > /sys/class/gpio/gpio192/value The first echo line enables the gpio.... if you get problems here the gpio is already attached to a linux driver and will need removing (look into removing a driver) The second enables that channel to become an output as all gpio's are either in or output the default is always input so this enables you send the gpio as high or low...etc The next 2 lines will write a high or low value to that gpio you should see the light move on and off if it is correctly enabled. Best of luck Kyle Without finding problems you never learn. --- Quote End --- - Altera_Forum
Honored Contributor
Hi kyle,
thanks for your reply.I tried the way you told using the Linux but this did not work.The GPIO was not accessible.so from linux itself I am not able to control.if we solve this then user space code will work. My Assignment editor looks like this the 2 rows for each pin original To:GPIO_1[1] Assignment name-> Location PIN_Name(value) Enabled(yes) GPIO_1[1] Assignment name-> I/O standard 3.3V LVTTL(value) Enabled(yes) My changed version To:GPIO_1[1] Assignment name-> HPS_IO ON(value) Enabled(yes) GPIO_1[1] Assignment name-> I/O standard 3.3V LVTTL(value) Enabled(yes) Is this correct ??.. Like this I need to enable for all other pins.Is there any thing I missed assigning here???..Let me know.Any configuration changes. In the device option also I have chooseb UNUSED pin as INPUT state TRIGERRED. created the .SOF and programmed and ran the linux command but did not work..Kindly let me know if you see any errors here thanks in advance --Ravi - Altera_Forum
Honored Contributor
Hey Ravi,
Looks like you have too many assignments.... please remove all... For the HPS pin outs... from the GPIO you need to make sure they are selected in the peripheral pin outs as exported GPIO (which you look to have done with GPIO_1). This is then built into the top level file with your pin as GPIO_1: INOUT STD_LOGIC in the port declarations and then mapped to the port map for the qsys ip. (part of the tutorial). Now this map is to hps_io_hps_io_gpio_inst_GPIO1 => GPIO_1 in your case... so the system is linked to the top level pin (specified as INOUT as this is normal for a GPIO). Now in order for the preloader to know you want that top level pin [GPIO_1] enabled you need set it once in the assignment editor... GPIO_1 Assignment name-> I/O standard 3.3V LVTTL(value) Enabled(yes) <- this is the only one you need... i think you might of named it in a vector or something but just trial one first to make sure your doing it right. I cannot help you any more than this. If it still not works out it may still be a hardware failure but unlikely. Best of luck Kyle - Altera_Forum
Honored Contributor
Hi kyle ,
Really thankful to you.Just tell me where in the tool we can see the peripheral pin outs and top leve file as mentioned and then the mapping. If I get all three then I may get some hint......I cannot see the mapping if I get I might get some idea.. regards Ravi --- Quote Start --- Hey Ravi, Looks like you have too many assignments.... please remove all... For the HPS pin outs... from the GPIO you need to make sure they are selected in the peripheral pin outs as exported GPIO (which you look to have done with GPIO_1). This is then built into the top level file with your pin as GPIO_1: INOUT STD_LOGIC in the port declarations and then mapped to the port map for the qsys ip. (part of the tutorial). Now this map is to hps_io_hps_io_gpio_inst_GPIO1 => GPIO_1 in your case... so the system is linked to the top level pin (specified as INOUT as this is normal for a GPIO). Now in order for the preloader to know you want that top level pin [GPIO_1] enabled you need set it once in the assignment editor... GPIO_1 Assignment name-> I/O standard 3.3V LVTTL(value) Enabled(yes) <- this is the only one you need... i think you might of named it in a vector or something but just trial one first to make sure your doing it right. I cannot help you any more than this. If it still not works out it may still be a hardware failure but unlikely. Best of luck Kyle --- Quote End ---