Error in SPI.h


(Balaji V) #1

When ever i run the sample spi code, I get an error in these lines
extern inline void metal_spi_init(struct metal_spi *spi, int baud_rate);
extern inline int metal_spi_transfer(struct metal_spi *spi, struct metal_spi_config *config, size_t len, char *tx_buf, char *rx_buf);
extern inline int metal_spi_get_baud_rate(struct metal_spi *spi);
extern inline int metal_spi_set_baud_rate(struct metal_spi *spi, int baud_rate);

and also this,

struct metal_spi_config config = {
	.protocol = METAL_SPI_SINGLE,
	.polarity = 0,
	.phase = 0,
	.little_endian = 0,
	.cs_active_high = 0,
	.csid = 0,
};

The error occures at METAL_SPI_SINGLE.

Please can anyone correct me code.
I have given the entire code below…

example-spi

/* Copyright 2019 SiFive, Inc /
/
SPDX-License-Identifier: Apache-2.0 */

#include <stdio.h>

#include <metal/spi.h>

int main(void) {
printf(“METAL SPI Driver Demo\n”);

struct metal_spi *spi;

/* Get SPI 1 */
spi = metal_spi_get_device(1);

/* Fallback to SPI 0 */
if(spi == NULL) {
	spi = metal_spi_get_device(0);
}

if(spi == NULL) {
	printf("Failed to get spi device\n");
	return 1;
}

/* Initialize the SPI device to 100_000 baud */
metal_spi_init(spi, 100000);

/* CPOL = 0, CPHA = 0, MSB-first, CS active low */
struct metal_spi_config config = {
	.protocol = METAL_SPI_SINGLE,
	.polarity = 0,
	.phase = 0,
	.little_endian = 0,
	.cs_active_high = 0,
	.csid = 0,
};

/* Transfer three bytes */
char tx_buf[3] = {0x55, 0xAA, 0xA5};
char rx_buf[3] = {0};

metal_spi_transfer(spi, &config, 3, tx_buf, rx_buf);
printf("%c",rx_buf);
return 0;

}


(Tommy Murphy) #2

What error do you get?
What gcc compilation flags are you using?


(Balaji V) #3

When i build there is no error…
But when i run with HiFive1 there is error in OpenOCD


(Balaji V) #4

Open On-Chip Debugger 0.10.0+dev (SiFive OpenOCD 0.10.0-2019.08.2)
Licensed under GNU GPL v2
For bug reports:
https://github.com/sifive/freedom-tools/issues
debug_level: 0
adapter speed: 10000 kHz
Error: Timed out waiting for debug int to clear.Increase timeout with riscv set_command_timeout_sec.
Error: Debug interrupt didn’t clear.
Error: Debug RAM 0x0: 0xfff04493
Error: Debug RAM 0x1: 0x01f4d493
Error: Debug RAM 0x2: 0x40902023
Error: Debug RAM 0x3: 0x01f4d493
Error: Debug RAM 0x4: 0x40902223
Error: Debug RAM 0x5: 0x3f00006f
Error: Debug RAM 0x6: 0x060c1218
Error: Debug RAM 0x7: 0xdffd6bd5
Error: Debug RAM 0x8: 0x00000000
Error: Debug RAM 0x9: 0x00000000
Error: Debug RAM 0xa: 0x00000000
Error: Debug RAM 0xb: 0x00000000
Error: Debug RAM 0xc: 0x00000000
Error: Debug RAM 0xd: 0x00000000
Error: Debug RAM 0xe: 0x00000000
Error: Debug RAM 0xf: 0x00000000
Error: Failed to discover xlen; word0=0xfff04493, word1=0x1f4d493, exception=0x60c1218
Error: Debug RAM 0x0: 0xfff04493
Error: Debug RAM 0x1: 0x01f4d493
Error: Debug RAM 0x2: 0x40902023
Error: Debug RAM 0x3: 0x01f4d493
Error: Debug RAM 0x4: 0x40902223
Error: Debug RAM 0x5: 0x3f00006f
Error: Debug RAM 0x6: 0x060c1218
Error: Debug RAM 0x7: 0xdffd6bd5
Error: Debug RAM 0x8: 0x00000000
Error: Debug RAM 0x9: 0x00000000
Error: Debug RAM 0xa: 0x00000000
Error: Debug RAM 0xb: 0x00000000
Error: Debug RAM 0xc: 0x00000000
Error: Debug RAM 0xd: 0x00000000
Error: Debug RAM 0xe: 0x00000000
Error: Debug RAM 0xf: 0x00000000
Error: Target not examined yet

Please solve my error


(Balaji V) #5

This is the place where i get error ( .protocol=METAL_SPI_SINGLE )

/* CPOL = 0, CPHA = 0, MSB-first, CS active low */
struct metal_spi_config config = {
	.protocol = METAL_SPI_SINGLE,  
	.polarity = 0,
	.phase = 0,
	.little_endian = 0,
	.cs_active_high = 0,
	.csid = 0,
};