Error while connecting to CPU on HiFive1 revb board [SOLVED]


(Krists) #1

I flashed a program and now I no longer can flash anything. I always get FAIL.TXT file with “Error while connecting to CPU”. I just drag the .hex file into HiFive device.

printf("Transfer start\n");
struct metal_spi *spi;

//Get SPI 1
spi = metal_spi_get_device(d_pin); // d_pin is 1, previosly it was 5

// 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 tx_buf[3] = {0x55, 0xAA, 0x00};
char rx_buf[3] = {0};

metal_spi_transfer(spi, &config, 3, tx_buf, rx_buf);

printf("Transfer end\n");

Problem started, when I tried to flash this. I played around with SPI. Can misuse of SPI brick the board?
I am using HiFive1 revb board on Kubuntu 19.10 64bit.

Edit: I managed to solve the problem using safe mode (connect board to pc with usb and when green led is on, instantly press reset button, if done correcly, red led will flash, for more info read documentation). That thing didn’t work previously, but trick aperently is to disconect board, wait some minutes and then on first connect perform this. Now I have unbricked board. Thanks people bellow for suggestions.


#2

You should have the bootloader code still intact so you should be able to press the button right after restarting the device.

You’ll know it’s there because it’ll blink the green LED at that point. That should make it work again. I can’t tell why playing around with SPI would do anything wrong here tho.

You can read about the “bootloader rescue” at the end of the quickstart pdf.


(Krists) #3

I tried that, but it still doesn’t work. The safe boot mode works (I get flashing red led)
I connected to serial output and got this:

ATE0--> Send Flag error: #255 #255 #255 #255 AT+BLEINIT=0--> Send Flag error: #255 #255 #255 #255 AT+CWMODE=0--> Send Flag error: #255 #255 #255 #255 
METAL SPI Driver Demo
LCDinit()
Transfer start

Should the first line be there? What else I can do to unbrick the board?


#4

But that output means you didn’t get to the bootloader properly…

Try connecting via

JLinkGDBServer -device FE310 -if JTAG -speed 4000 -port 3333 -nogui

You can then upload using gdb “as usual”.


(Krists) #5

I installed the Segger thingy (https://www.segger.com/products/debug-probes/j-link/tools/j-link-gdb-server/about-j-link-gdb-server/) and got this:

bumbieris112@bumbieris112-TUF-Gaming-FX505DU:~$ JLinkGDBServer -device FE310 -if JTAG -speed 4000 -port 3333 -nogui
SEGGER J-Link GDB Server V6.60b Command Line Version

JLinkARM.dll V6.60b (DLL compiled Dec 20 2019 17:55:44)

Command line: -device FE310 -if JTAG -speed 4000 -port 3333 -nogui
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     3333
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 FE310
Target interface:              JTAG
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link OB-K22-SiFive compiled Dec 12 2019 16:26:28
Hardware: V1.00
S/N: 979000432
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 3333
Connecting to target...

J-Link found 1 JTAG device, Total IRLen = 5
JTAG ID: 0x20000913 (RISC-V)
Connected to target
Waiting for GDB connection...

What should I do next to unbrick the board? Can you please provide detailed next steps?


#6

Ok that’s good that means it’s not bricked and is ready to accept a new program. I don’t use the freedom SDK or even C (I use Rust) but the process for uploading with gdb should be the same.

Once it says Waiting for GDB connection... you should be able to upload a new program via gdb on another terminal using the load command.


(Krists) #7

Can somebody explain how to load a program (.hex file) to the board via GDB load command in detail?

Edit - not necesarry anymore. Thanks