Page 1 of 1

luckfox pico ultra w 使用ubuntu系统无法执行Linux交叉编译生成的文件

Posted: 2024-07-01 2:49
by Potato
test.c:

Code: Select all

#include <stdio.h>

int main()
{
        printf("hello world!\n");
        return 0;
}
spi.c:

Code: Select all

int main() {
    int spi_file;
    uint8_t tx_buffer[50] = {0x8f,0,0,0,0};
    uint8_t rx_buffer[50];

    // Open the SPI device
    if ((spi_file = open(SPI_DEVICE_PATH, O_RDWR)) < 0) {
        perror("Failed to open SPI device");
        return -1;
    }

    // Configure SPI mode and bits per word
    uint8_t mode = SPI_MODE_3;
    uint8_t bits = 8;
    if (ioctl(spi_file, SPI_IOC_WR_MODE, &mode) < 0) {
        perror("Failed to set SPI mode");
        close(spi_file);
        return -1;
    }
    if (ioctl(spi_file, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
        perror("Failed to set SPI bits per word");
        close(spi_file);
        return -1;
    }

    // Perform SPI transfer
    struct spi_ioc_transfer transfer = {
        .tx_buf = (unsigned long)tx_buffer,
        .rx_buf = (unsigned long)rx_buffer,
        .len = sizeof(tx_buffer),
        .delay_usecs = 0,
        .speed_hz = 1000000,  // SPI speed in Hz
        .bits_per_word = 8,
    };

    if (ioctl(spi_file, SPI_IOC_MESSAGE(1), &transfer) < 0) {
        perror("Failed to perform SPI transfer");
        close(spi_file);
        return -1;
    }

     /* Print tx_buffer and rx_buffer*/
    printf("\rtx_buffer: \n %s\n ", tx_buffer);
    printf("\rrx_buffer: \n %s\n ", rx_buffer);

    // Close the SPI device
    close(spi_file);

    return 0;
}
如图:

Re: luckfox pico ultra w 使用ubuntu系统无法执行Linux交叉编译生成的文件

Posted: 2024-07-01 2:53
by Eng38
您好,Luckfox-pico使用ubuntu系统对应的交叉编译工具为glibc,如果arm-rockchip830-linux-uclibcgnueabihf-gcc进行交叉编译是无法直接运行的,需要链接上对应的库,解决方法就是添加编译选项 -static

Code: Select all

rm-rockchip830-linux-uclibcgnueabihf-gcc test.c -o test -static 
具体内容可以参考viewtopic.php?t=713

Re: luckfox pico ultra w 使用ubuntu系统无法执行Linux交叉编译生成的文件

Posted: 2024-07-01 3:04
by Potato
Eng38 wrote: 2024-07-01 2:53 您好,Luckfox-pico使用ubuntu系统对应的交叉编译工具为glibc,如果arm-rockchip830-linux-uclibcgnueabihf-gcc进行交叉编译是无法直接运行的,需要链接上对应的库,解决方法就是添加编译选项 -static

Code: Select all

rm-rockchip830-linux-uclibcgnueabihf-gcc test.c -o test -static 
具体内容可以参考viewtopic.php?t=713
感谢回复,问题解决了