Help to dump led code in pynqz2 using vitis 2024.1

I am trying a project to capture the image through pynqz2 board with usb camera connected to it using C++ code in vitis (2024.1/2021.1) software. I have tried to write .cpp , .h and testbench to run this code but it has many errors . Please help me to get the code for above project and i also need a code (if switch 0 is on the led 0 and led 1 should be on and switch 1 is on the led2 and led3 should be on ) it should run in vitis software

1 Like

Hi,
Can you please provide the codes and the errors displayed?

Did you try chatgpt for your second code with the switch?

1 Like

Yes we tried chatgpt

But still it has errors we need .cpp .h and testbench for the code please provide the code to run in vitis software and to dump the code on pynqz2 board of the second code that is switch to on led

for your first project, can you please provide the C++ code you created?

1 Like

The project (if switch 0 is on then led 0 and 1 should be on else if switch 1 is on then led 2 and 3 should be on )
the code of first program has 3 file one is .cpp .h and testbench

.cpp
#include “gpio_control.h”

// Constructor
GpioControl::GpioControl(int deviceId, int switchChannel, int ledChannel)
: switchChannel(switchChannel), ledChannel(ledChannel) {
// Initialize GPIO
if (XGpio_Initialize(&gpio, deviceId) != XST_SUCCESS) {
throw “GPIO Initialization Failed!”;
}
}

// Initialize GPIO
int GpioControl::initialize() {
// Set GPIO directions
XGpio_SetDataDirection(&gpio, switchChannel, 0xFFFFFFFF); // Input for switches
XGpio_SetDataDirection(&gpio, ledChannel, 0x00000000); // Output for LEDs
return 0;
}

// Read the state of the switches
u32 GpioControl::readSwitchState() {
return XGpio_DiscreteRead(&gpio, switchChannel);
}

// Control the LEDs based on the switch states
void GpioControl::controlLEDs(u32 switchState) {
u32 ledState = 0;

if ((switchState & 0b01) != 0) { // Check if Switch 0 is ON
ledState |= 0b0011; // Turn on LED0 and LED1
}
if ((switchState & 0b10) != 0) { // Check if Switch 1 is ON
ledState |= 0b1100; // Turn on LED2 and LED3
}

XGpio_DiscreteWrite(&gpio, ledChannel, ledState); // Update LEDs
}

.h
#ifndef GPIO_CONTROL_H
#define GPIO_CONTROL_H

#include <xgpio.h> // Include GPIO driver header
#include <xparameters.h> // Include parameter definitions for AXI devices

class GpioControl {
private:
XGpio gpio; // GPIO instance
int switchChannel; // Channel for the switches
int ledChannel; // Channel for the LEDs

public:
// Constructor
GpioControl(int deviceId, int switchChannel, int ledChannel);

// Initialize GPIO
int initialize();

// Read the state of the switches
u32 readSwitchState();

// Control the LEDs based on the switch states
void controlLEDs(u32 switchState);
};

#endif // GPIO_CONTROL_H

testbench
#include “gpio_control.h”
#include

int main() {
const int DEVICE_ID = XPAR_AXI_GPIO_0_DEVICE_ID; // GPIO device ID
const int SWITCH_CHANNEL = 1; // Channel for switches
const int LED_CHANNEL = 2; // Channel for LEDs

try {
// Create an instance of GpioControl
GpioControl controller(DEVICE_ID, SWITCH_CHANNEL, LED_CHANNEL);

// Initialize the GPIO controller
if (controller.initialize() != 0) {
std::cerr << “GPIO initialization failed!” << std::endl;
return -1;
}

// Main control loop
std::cout << “Monitoring switches and controlling LEDs. Press Ctrl+C to exit.” << std::endl;
while (true) {
// Read the state of the switches
u32 switchState = controller.readSwitchState();

// Control the LEDs based on the switch states
controller.controlLEDs(switchState);
}
} catch (const char* error) {
std::cerr << "Error: " << error << std::endl;
return -1;
}

return 0;
}

error
INFO: [SIM 2] *************** CSIM start ***************
INFO: [SIM 4] CSIM will launch GCC as the compiler.
Compiling …/…/…/testbench.cpp in debug mode
csim.mk:72: recipe for target ‘obj/testbench.o’ failed
In file included from …/…/…/testbench.cpp:1:0:
…/…/…/gpio_control.h:4:50: fatal error: xgpio.h: No such file or directory
#include <xgpio.h> // Include GPIO driver header
^
compilation terminated.
make: *** [obj/testbench.o] Error 1
ERR: [SIM 100] CSim file generation failed: compilation error(s).
INFO: [SIM 3] *************** CSIM finish ***************

please solve the error the error faced is in first step in c simulation

fatal error: xgpio.h: No such file or directory

What is this GPIO driver header? Did you put it in the same folder as your others files?

Your problem is more a programmation problem than a board problem, You could get answer faster in a more appropriate forum, like stack overflow or C++.com .

1 Like

No there are no errors . I want to know how to dump the c++ code executed on vitis 2024.1 version to the pynqz2 board .please tell step by step procedure to dump the code from vitis 2024.1 to pynqz2 board