Issues with Drag & Drop


(Andrew England) #1

Hello, I’m running into an interesting issue simply trying to toggle some GPIO on the HiFive1 RevB. I’m attempting to toggle every GPIO on and off. When I run my code from Freedom Studio using the run button, everything works fine and all GPIO toggle as expected. However, building the same code and then utilizing the drag and drop operation refuses to toggle pins 11, 12, 13, and 15, which as far as I can tell, are attached to the SPI bus. My code is attached below, anybody know what I’m doing wrong?

#include <stdio.h>

//#include <unistd.h>
#include <time.h>
#include <metal/gpio.h>
#include <metal/cpu.h>

uint8_t net1[8] = {1, 3, 9, 11, 13, 19, 21, 23};
uint8_t net2[8] = {0, 2, 4, 10, 12, 18, 20, 22};

void delay(int number_of_microseconds) //not actually number of seconds
{

// Converting time into multiples of a hundred nS
int hundred_ns = 10 * number_of_microseconds;

// Storing start time
clock_t start_time = clock();

// looping till required time is not acheived
while (clock() < start_time + hundred_ns);

}

int main (void)
{

struct metal_gpio *gpio_device;

gpio_device = metal_gpio_get_device(0);
metal_gpio_enable_input(gpio_device, 18);
int selfTest = metal_gpio_get_input_pin(gpio_device, 18);

if (selfTest == 1)
{
	for (int gpioNum = 0; gpioNum < 8; gpioNum++)
	{
		metal_gpio_enable_output(gpio_device, net1[gpioNum]);
		metal_gpio_enable_output(gpio_device, net2[gpioNum]);
	}
	while(1)
	{
		for (int gpioNum = 0; gpioNum < 8; gpioNum++)
		{
			metal_gpio_set_pin(gpio_device, net1[gpioNum], 1);
			metal_gpio_set_pin(gpio_device, net2[gpioNum], 0);
		}
		delay(1000000); //1000000 = 1 second
		for (int gpioNum = 0; gpioNum < 8; gpioNum++)
		{
			metal_gpio_set_pin(gpio_device, net1[gpioNum], 0);
			metal_gpio_set_pin(gpio_device, net2[gpioNum], 1);
		}
		delay(1000000); //1000000 = 1 second
	}
}
else
{
	metal_gpio_enable_output(gpio_device, 5);
	while(1)
	{
		metal_gpio_set_pin(gpio_device, 5, 1);
		delay(1000000); //1000000 = 1 second
		metal_gpio_set_pin(gpio_device, 5, 0);
		delay(1000000); //1000000 = 1 second
	}
}
return 0;

}