RaspberrPi project source code
guowenxue
5 days ago f6a80713cf7f27bdb7e4fbbade8db3ea8bebc7d6
update w25qflash to specify spidev
1 files modified
63 ■■■■■ changed files
modules/w25qflash.c 63 ●●●●● patch | view | raw | blame | history
modules/w25qflash.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libgen.h>
#include <getopt.h>
#include <fcntl.h>
#include <time.h>
@@ -57,19 +58,73 @@
void dump_buf(const char *prompt, char *buffer, size_t length);
static inline void banner(const char *progname)
{
    printf("%s program Version v1.0.0\n", progname);
    printf("Copyright (C) 2023 Avnet.\n");
}
static void program_usage(const char *progname)
{
    printf("Usage: %s [OPTION]...\n", progname);
    printf(" %s is W25Q SPI Norflash test program. \n", progname);
    printf(" -d[device  ]  Specify SPI device, such as /dev/spidevX.Y\n");
    printf(" -h[help    ]  Display this help information\n");
    printf(" -v[version ]  Display the program version\n");
    printf("\n");
    banner(progname);
    return;
}
char           *dev="/dev/spidev0.0"; /* SPI device 0 */
int main (int argc, char **argv)
{
    int             rv;
    char           *progname=NULL;
    struct option   long_options[] = {
        {"device", required_argument, NULL, 'd'},
        {"version", no_argument, NULL, 'v'},
        {"help", no_argument, NULL, 'h'},
        {NULL, 0, NULL, 0}
    };
    progname = basename(argv[0]);
    /* Parser the command line parameters */
    while ((rv = getopt_long(argc, argv, "d:m:vh", long_options, NULL)) != -1)
    {
        switch (rv)
        {
            case 'd': /*  Set SPI device path: /dev/spidev0.0 */
                dev = optarg;
                break;
            case 'v':  /*  Get software version */
                banner(progname);
                return EXIT_SUCCESS;
            case 'h':  /*  Get help information */
                program_usage(progname);
                return 0;
            default:
                break;
        }
    }
    spinor_test();
    return 0;
}
/*+-----------------------+
 *|   SPI API Functions   |
 *+-----------------------+*/
#define SPI_DEV                         "/dev/spidev0.0"
#define SPI_BITS                        8
#define SPI_MODE                        0//(SPI_CPHA|SPI_CPOL)
#define SPI_SPEED                       500000
@@ -84,10 +139,10 @@
    uint32_t            request;
    int                 ret;
    spi->hspi = open(SPI_DEV, O_RDWR);
    spi->hspi = open(dev, O_RDWR);
    if (spi->hspi < 0)
    {
        spinor_print("ERROR: open device %s failure: %s\r\n", SPI_DEV, strerror(errno));
        spinor_print("ERROR: open device %s failure: %s\r\n", dev, strerror(errno));
        return ;
    }