how to manipulating of GPIOs on Pulpissino platform
#1
Hi,
I would like to do some manipulation of the user and general purchase I/Os of the pianissimo platform, for example to light up a user LED via pressing down a pushbutton.
I found the functions in the sdk runtime doc for configuring the gpio as a bus such as rt_gpio_init and rt_gpio_pin_configure etc, but I did not find any document mentioning the exact address/pin or registers that are corresponding to the LEDs or pushbuttons. I am wondering where to get the detailed info of such so that I can light up a user LED?

Thanks,
Mapletree
Reply
#2
(09-23-2019, 02:46 PM)mapletree Wrote: Hi,
I would like to do some manipulation of the user and general purchase I/Os of the pianissimo platform, for example to light up a user LED via pressing down a pushbutton.
I found the functions in the sdk runtime doc for configuring the gpio as a bus such as rt_gpio_init and rt_gpio_pin_configure etc, but I did not find any document mentioning the exact address/pin or registers that are corresponding to the LEDs or pushbuttons. I am wondering where to get the detailed info of such so that I can light up a user LED?

Thanks,
Mapletree

Hi Mapletree,

You can use the following example:

  
Code:
/*
* This example shows how drive a GPIO as an output.
*/

#include "rt/rt_data.h"
#include <stdio.h>
#include <rt/rt_api.h>
#include <stdint.h>


#define GPIO 5 // LED0 on Genesys2 board
unsigned int __rt_iodev_uart_baudrate = 115200;
int __rt_fpga_fc_frequency = 20000000;
int __rt_fpga_periph_frequency = 10000000;

int main()
{
 // GPIO initialization
 rt_pad_set_function(GPIO, 1); //pad_func=1 means gpio functionality. pad_func=0 is default (e.g. in this case spim_csn1)
 rt_gpio_init(0, GPIO);

 // Configure GPIO as an outpout
 rt_gpio_set_dir(0, 1<<GPIO, RT_GPIO_IS_OUT);

 // Now set the output value

 rt_gpio_set_pin_value(0, GPIO, 1);

 return 0;
}


Unfortunately, the documentation on that regard is a little bit lacking. Here is a summary of the GPIO/Pad association currently in use:

 Pad Name    Assigned GPIO 
---------------------------
 spim_sdio0  GPIO 0        
 spim_sdio1  GPIO 1        
 spim_sdio2  GPIO 2        
 spim_sdio3  GPIO 3        
 spim_csn0   GPIO 4        
 spim_csn1   GPIO 5        
 spim_sck    GPIO 6        
 uart_rx     GPIO 7        
 uart_tx     GPIO 8        
 cam_pclk    GPIO 9        
 cam_hsync   GPIO 10       
 cam_data0   GPIO 11       
 cam_data1   GPIO 12       
 cam_data2   GPIO 13       
 cam_data3   GPIO 14       
 cam_data4   GPIO 15       
 cam_data5   GPIO 16       
 cam_data6   GPIO 17       
 cam_data7   GPIO 18       
 cam_vsync   GPIO 19       
 sdio_clk    GPIO 20       
 sdio_cmd    GPIO 21       
 sdio_data0  GPIO 22       
 sdio_data1  GPIO 23       
 sdio_data2  GPIO 24       
 sdio_data3  GPIO 25       
 i2c0_sda    GPIO 26       
 i2c0_scl    GPIO 27       
 i2s0_sck    GPIO 28       
 i2s0_ws     GPIO 29       
 i2s0_sdi    GPIO 30       
 i2s1_sdi    GPIO 31       



You can find this information in the pulpissimo/pad_control.sv.
I hope this helps.
Greetings,
Manuel
Reply
#3
(09-30-2019, 09:23 AM)meggiman Wrote:
(09-23-2019, 02:46 PM)mapletree Wrote: Hi,
I would like to do some manipulation of the user and general purchase I/Os of the pianissimo platform, for example to light up a user LED via pressing down a pushbutton.
I found the functions in the sdk runtime doc for configuring the gpio as a bus such as rt_gpio_init and rt_gpio_pin_configure etc, but I did not find any document mentioning the exact address/pin or registers that are corresponding to the LEDs or pushbuttons. I am wondering where to get the detailed info of such so that I can light up a user LED?

Thanks,
Mapletree

Hi Mapletree,

You can use the following example:

  
Code:
/*
* This example shows how drive a GPIO as an output.
*/

#include "rt/rt_data.h"
#include <stdio.h>
#include <rt/rt_api.h>
#include <stdint.h>


#define GPIO 5 // LED0 on Genesys2 board
unsigned int __rt_iodev_uart_baudrate = 115200;
int __rt_fpga_fc_frequency = 20000000;
int __rt_fpga_periph_frequency = 10000000;

int main()
{
 // GPIO initialization
 rt_pad_set_function(GPIO, 1); //pad_func=1 means gpio functionality. pad_func=0 is default (e.g. in this case spim_csn1)
 rt_gpio_init(0, GPIO);

 // Configure GPIO as an outpout
 rt_gpio_set_dir(0, 1<<GPIO, RT_GPIO_IS_OUT);

 // Now set the output value

 rt_gpio_set_pin_value(0, GPIO, 1);

 return 0;
}


Unfortunately, the documentation on that regard is a little bit lacking. Here is a summary of the GPIO/Pad association currently in use:

 Pad Name    Assigned GPIO 
---------------------------
 spim_sdio0  GPIO 0        
 spim_sdio1  GPIO 1        
 spim_sdio2  GPIO 2        
 spim_sdio3  GPIO 3        
 spim_csn0   GPIO 4        
 spim_csn1   GPIO 5        
 spim_sck    GPIO 6        
 uart_rx     GPIO 7        
 uart_tx     GPIO 8        
 cam_pclk    GPIO 9        
 cam_hsync   GPIO 10       
 cam_data0   GPIO 11       
 cam_data1   GPIO 12       
 cam_data2   GPIO 13       
 cam_data3   GPIO 14       
 cam_data4   GPIO 15       
 cam_data5   GPIO 16       
 cam_data6   GPIO 17       
 cam_data7   GPIO 18       
 cam_vsync   GPIO 19       
 sdio_clk    GPIO 20       
 sdio_cmd    GPIO 21       
 sdio_data0  GPIO 22       
 sdio_data1  GPIO 23       
 sdio_data2  GPIO 24       
 sdio_data3  GPIO 25       
 i2c0_sda    GPIO 26       
 i2c0_scl    GPIO 27       
 i2s0_sck    GPIO 28       
 i2s0_ws     GPIO 29       
 i2s0_sdi    GPIO 30       
 i2s1_sdi    GPIO 31       



You can find this information in the pulpissimo/pad_control.sv.
I hope this helps.
Greetings,
Manuel

Great! it is really helpful! Thanks a lot Manueal!

Mapletree
Reply
#4
(09-30-2019, 02:24 PM)mapletree Wrote:
(09-30-2019, 09:23 AM)meggiman Wrote:
(09-23-2019, 02:46 PM)mapletree Wrote: Hi,
I would like to do some manipulation of the user and general purchase I/Os of the pianissimo platform, for example to light up a user LED via pressing down a pushbutton.
I found the functions in the sdk runtime doc for configuring the gpio as a bus such as rt_gpio_init and rt_gpio_pin_configure etc, but I did not find any document mentioning the exact address/pin or registers that are corresponding to the LEDs or pushbuttons. I am wondering where to get the detailed info of such so that I can light up a user LED?

Thanks,
Mapletree

Hi Mapletree,

You can use the following example:

  
Code:
/*
* This example shows how drive a GPIO as an output.
*/

#include "rt/rt_data.h"
#include <stdio.h>
#include <rt/rt_api.h>
#include <stdint.h>


#define GPIO 5 // LED0 on Genesys2 board
unsigned int __rt_iodev_uart_baudrate = 115200;
int __rt_fpga_fc_frequency = 20000000;
int __rt_fpga_periph_frequency = 10000000;

int main()
{
 // GPIO initialization
 rt_pad_set_function(GPIO, 1); //pad_func=1 means gpio functionality. pad_func=0 is default (e.g. in this case spim_csn1)
 rt_gpio_init(0, GPIO);

 // Configure GPIO as an outpout
 rt_gpio_set_dir(0, 1<<GPIO, RT_GPIO_IS_OUT);

 // Now set the output value

 rt_gpio_set_pin_value(0, GPIO, 1);

 return 0;
}


Unfortunately, the documentation on that regard is a little bit lacking. Here is a summary of the GPIO/Pad association currently in use:

 Pad Name    Assigned GPIO 
---------------------------
 spim_sdio0  GPIO 0        
 spim_sdio1  GPIO 1        
 spim_sdio2  GPIO 2        
 spim_sdio3  GPIO 3        
 spim_csn0   GPIO 4        
 spim_csn1   GPIO 5        
 spim_sck    GPIO 6        
 uart_rx     GPIO 7        
 uart_tx     GPIO 8        
 cam_pclk    GPIO 9        
 cam_hsync   GPIO 10       
 cam_data0   GPIO 11       
 cam_data1   GPIO 12       
 cam_data2   GPIO 13       
 cam_data3   GPIO 14       
 cam_data4   GPIO 15       
 cam_data5   GPIO 16       
 cam_data6   GPIO 17       
 cam_data7   GPIO 18       
 cam_vsync   GPIO 19       
 sdio_clk    GPIO 20       
 sdio_cmd    GPIO 21       
 sdio_data0  GPIO 22       
 sdio_data1  GPIO 23       
 sdio_data2  GPIO 24       
 sdio_data3  GPIO 25       
 i2c0_sda    GPIO 26       
 i2c0_scl    GPIO 27       
 i2s0_sck    GPIO 28       
 i2s0_ws     GPIO 29       
 i2s0_sdi    GPIO 30       
 i2s1_sdi    GPIO 31       



You can find this information in the pulpissimo/pad_control.sv.
I hope this helps.
Greetings,
Manuel

Great! it is really helpful! Thanks a lot Manueal!

Mapletree
Hello,mapletree, Now I  encounter a problem about GPIO input.Would you like to share  your C code which implements lighting up a user LED via pressing down a pushbutton?
Reply
#5
Hi bunohdwnl,

Did you manage to get the gpio input working?
Because I'm also failing in reading the correct values from an input pin.
I always receive the same input value, independent of the inputs I apply to the pins.

Thanks !
Reply
#6
(09-30-2019, 09:23 AM)meggiman Wrote:
Code:
...
 rt_pad_set_function(GPIO, 1); //pad_func=1 means gpio functionality. pad_func=0 is default (e.g. in this case spim_csn1)
...


Unfortunately, the documentation on that regard is a little bit lacking. Here is a summary of the GPIO/Pad association currently in use:

 Pad Name    Assigned GPIO 
---------------------------
 spim_sdio0  GPIO 0        
...

You can find this information in the pulpissimo/pad_control.sv.

That helped me a lot in getting GPIOs at least somewhat running, thanks! The code in the SDK apparently has changed over time, and the pulp-rt-examples have not been updated.
For example, the more generic rt_pad_set_function() has replaced rt_gpio_init() in most CPU instances (where rt_gpio_init() has become a NOP).


After following the call tree and hardware modules up and down a bit I noticed that the input could never have worked as intended with the version 3 of the GPIO wrappers AFAICT... https://github.com/pulp-platform/hal/pull/20

The following program allows for testing all (polling) I/O functionality properly. I have left the rt_gpio_init() calls in there but they don't matter in my case - in fact, they are optimized away. The API clearly isn't that thought through so don't blame me for all the boiler plate code please :)


Code:
/*
* Copyright (C) 2018 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include "rt/rt_api.h"

#define LED0 5
#define LED1 9
#define LED2 10
#define LED3 11
#define LED4 0
#define LED5 1
#define LED6 2
#define LED7 3

#define SW0 12
#define SW1 13
#define SW2 18
#define SW3 19
#define SW4 22
#define SW5 23
#define SW6 24
#define SW7 25

#define BTNU 14
#define BTNR 15
#define BTND 16
#define BTNL 17


int __rt_fpga_fc_frequency = 20000000;
int __rt_fpga_periph_frequency = 10000000;
unsigned int __rt_iodev_uart_baudrate = 115200;

int main() {
   rt_pad_set_function(LED0, 1);
   rt_pad_set_function(LED1, 1);
   rt_pad_set_function(LED2, 1);
   rt_pad_set_function(LED3, 1);
   rt_pad_set_function(LED4, 1);
   rt_pad_set_function(LED5, 1);
   rt_pad_set_function(LED6, 1);
   rt_pad_set_function(LED7, 1);
   rt_pad_set_function(SW7, 1);
   rt_pad_set_function(SW6, 1);
   rt_pad_set_function(SW5, 1);
   rt_pad_set_function(SW4, 1);
   rt_pad_set_function(SW3, 1);
   rt_pad_set_function(SW2, 1);
   rt_pad_set_function(SW1, 1);
   rt_pad_set_function(SW0, 1);
   rt_pad_set_function(BTNU, 1);
   rt_pad_set_function(BTNR, 1);
   rt_pad_set_function(BTND, 1);
   rt_pad_set_function(BTNL, 1);
   rt_gpio_init(0, SW0);
   rt_gpio_init(0, SW1);
   rt_gpio_init(0, SW2);
   rt_gpio_init(0, SW3);
   rt_gpio_init(0, SW4);
   rt_gpio_init(0, SW5);
   rt_gpio_init(0, SW6);
   rt_gpio_init(0, SW7);
   rt_gpio_init(0, BTNU);
   rt_gpio_init(0, BTNR);
   rt_gpio_init(0, BTND);
   rt_gpio_init(0, BTNL);
   rt_gpio_init(0, LED0);
   rt_gpio_init(0, LED1);
   rt_gpio_init(0, LED2);
   rt_gpio_init(0, LED3);
   rt_gpio_init(0, LED4);
   rt_gpio_init(0, LED5);
   rt_gpio_init(0, LED6);
   rt_gpio_init(0, LED7);

   rt_gpio_set_dir(0, 1<<LED7 | 1<<LED6 | 1<<LED5 | 1<<LED4 | 1<<LED3 | 1<<LED2 | 1<<LED1 | 1<<LED0, RT_GPIO_IS_OUT);
   rt_gpio_set_dir(0, 1<<BTNU | 1<<BTNR | 1<<BTND | 1<<BTNL, RT_GPIO_IS_IN);
   rt_gpio_set_dir(0, 1<<SW7 | 1<<SW6 | 1<<SW5 | 1<<SW4 | 1<<SW3 | 1<<SW2 | 1<<SW1 | 1<<SW0, RT_GPIO_IS_IN);

   while(1) {

       unsigned int btn = 0 \
           | (rt_gpio_get_pin_value(0, BTNL) << 3) \
           | (rt_gpio_get_pin_value(0, BTNU) << 2) \
           | (rt_gpio_get_pin_value(0, BTNR) << 1) \
           | (rt_gpio_get_pin_value(0, BTND) << 0) \
       ;
       unsigned int sw = 0 \
           | (rt_gpio_get_pin_value(0, SW7) << 7) \
           | (rt_gpio_get_pin_value(0, SW6) << 6) \
           | (rt_gpio_get_pin_value(0, SW5) << 5) \
           | (rt_gpio_get_pin_value(0, SW4) << 4) \
           | (rt_gpio_get_pin_value(0, SW3) << 3) \
           | (rt_gpio_get_pin_value(0, SW2) << 2) \
           | (rt_gpio_get_pin_value(0, SW1) << 1) \
           | (rt_gpio_get_pin_value(0, SW0) << 0) \
       ;

       printf("Hello world! - 0x%02x - 0x%02x\n", btn, sw);
       rt_gpio_set_pin_value(0, LED0, 1);
       rt_gpio_set_pin_value(0, LED1, 1);
       rt_gpio_set_pin_value(0, LED2, 1);
       rt_gpio_set_pin_value(0, LED3, 1);
       rt_gpio_set_pin_value(0, LED4, 1);
       rt_gpio_set_pin_value(0, LED5, 1);
       rt_gpio_set_pin_value(0, LED6, 1);
       rt_gpio_set_pin_value(0, LED7, 1);
       rt_time_wait_us(200*1000);
       rt_gpio_set_pin_value(0, LED0, 0);
       rt_gpio_set_pin_value(0, LED1, 0);
       rt_gpio_set_pin_value(0, LED2, 0);
       rt_gpio_set_pin_value(0, LED3, 0);
       rt_gpio_set_pin_value(0, LED4, 0);
       rt_gpio_set_pin_value(0, LED5, 0);
       rt_gpio_set_pin_value(0, LED6, 0);
       rt_gpio_set_pin_value(0, LED7, 0);
       rt_time_wait_us(200*1000);
   }

 return 0;
}
Reply
#7
Hi @stefanct and @meggiman,

Does the following code provided by you, works for zedboard too? I tried running this on my zedboard, and led0 goes off but then after that, I am not able to observe any changes. Could you please guide me? Thank you.

Code:
/*
* Copyright (C) 2018 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include "rt/rt_api.h"

#define LED0 5
#define LED1 9
#define LED2 10
#define LED3 11
#define LED4 0
#define LED5 1
#define LED6 2
#define LED7 3

#define SW0 12
#define SW1 13
#define SW2 18
#define SW3 19
#define SW4 22
#define SW5 23
#define SW6 24
#define SW7 25

#define BTNU 14
#define BTNR 15
#define BTND 16
#define BTNL 17


int __rt_fpga_fc_frequency = 20000000;
int __rt_fpga_periph_frequency = 10000000;
unsigned int __rt_iodev_uart_baudrate = 115200;

int main() {
   rt_pad_set_function(LED0, 1);
   rt_pad_set_function(LED1, 1);
   rt_pad_set_function(LED2, 1);
   rt_pad_set_function(LED3, 1);
   rt_pad_set_function(LED4, 1);
   rt_pad_set_function(LED5, 1);
   rt_pad_set_function(LED6, 1);
   rt_pad_set_function(LED7, 1);
   rt_pad_set_function(SW7, 1);
   rt_pad_set_function(SW6, 1);
   rt_pad_set_function(SW5, 1);
   rt_pad_set_function(SW4, 1);
   rt_pad_set_function(SW3, 1);
   rt_pad_set_function(SW2, 1);
   rt_pad_set_function(SW1, 1);
   rt_pad_set_function(SW0, 1);
   rt_pad_set_function(BTNU, 1);
   rt_pad_set_function(BTNR, 1);
   rt_pad_set_function(BTND, 1);
   rt_pad_set_function(BTNL, 1);
   rt_gpio_init(0, SW0);
   rt_gpio_init(0, SW1);
   rt_gpio_init(0, SW2);
   rt_gpio_init(0, SW3);
   rt_gpio_init(0, SW4);
   rt_gpio_init(0, SW5);
   rt_gpio_init(0, SW6);
   rt_gpio_init(0, SW7);
   rt_gpio_init(0, BTNU);
   rt_gpio_init(0, BTNR);
   rt_gpio_init(0, BTND);
   rt_gpio_init(0, BTNL);
   rt_gpio_init(0, LED0);
   rt_gpio_init(0, LED1);
   rt_gpio_init(0, LED2);
   rt_gpio_init(0, LED3);
   rt_gpio_init(0, LED4);
   rt_gpio_init(0, LED5);
   rt_gpio_init(0, LED6);
   rt_gpio_init(0, LED7);

   rt_gpio_set_dir(0, 1<<LED7 | 1<<LED6 | 1<<LED5 | 1<<LED4 | 1<<LED3 | 1<<LED2 | 1<<LED1 | 1<<LED0, RT_GPIO_IS_OUT);
   rt_gpio_set_dir(0, 1<<BTNU | 1<<BTNR | 1<<BTND | 1<<BTNL, RT_GPIO_IS_IN);
   rt_gpio_set_dir(0, 1<<SW7 | 1<<SW6 | 1<<SW5 | 1<<SW4 | 1<<SW3 | 1<<SW2 | 1<<SW1 | 1<<SW0, RT_GPIO_IS_IN);

   while(1) {

       unsigned int btn = 0 \
           | (rt_gpio_get_pin_value(0, BTNL) << 3) \
           | (rt_gpio_get_pin_value(0, BTNU) << 2) \
           | (rt_gpio_get_pin_value(0, BTNR) << 1) \
           | (rt_gpio_get_pin_value(0, BTND) << 0) \
       ;
       unsigned int sw = 0 \
           | (rt_gpio_get_pin_value(0, SW7) << 7) \
           | (rt_gpio_get_pin_value(0, SW6) << 6) \
           | (rt_gpio_get_pin_value(0, SW5) << 5) \
           | (rt_gpio_get_pin_value(0, SW4) << 4) \
           | (rt_gpio_get_pin_value(0, SW3) << 3) \
           | (rt_gpio_get_pin_value(0, SW2) << 2) \
           | (rt_gpio_get_pin_value(0, SW1) << 1) \
           | (rt_gpio_get_pin_value(0, SW0) << 0) \
       ;

       printf("Hello world! - 0x%02x - 0x%02x\n", btn, sw);
       rt_gpio_set_pin_value(0, LED0, 1);
       rt_gpio_set_pin_value(0, LED1, 1);
       rt_gpio_set_pin_value(0, LED2, 1);
       rt_gpio_set_pin_value(0, LED3, 1);
       rt_gpio_set_pin_value(0, LED4, 1);
       rt_gpio_set_pin_value(0, LED5, 1);
       rt_gpio_set_pin_value(0, LED6, 1);
       rt_gpio_set_pin_value(0, LED7, 1);
       rt_time_wait_us(200*1000);
       rt_gpio_set_pin_value(0, LED0, 0);
       rt_gpio_set_pin_value(0, LED1, 0);
       rt_gpio_set_pin_value(0, LED2, 0);
       rt_gpio_set_pin_value(0, LED3, 0);
       rt_gpio_set_pin_value(0, LED4, 0);
       rt_gpio_set_pin_value(0, LED5, 0);
       rt_gpio_set_pin_value(0, LED6, 0);
       rt_gpio_set_pin_value(0, LED7, 0);
       rt_time_wait_us(200*1000);
   }

return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)