SPI DMA assign [CUSTOM SPI DRIVER]

Aeronautic
Posts: 11
Joined: Thu Jan 02, 2020 12:07 am

SPI DMA assign [CUSTOM SPI DRIVER]

Postby Aeronautic » Wed Jan 08, 2020 3:13 am

As I am struggling with enormous amount of problems with esp-idf SPI driver (see my other posts), I am working on custom SPI driver.
I cant assign DMA to SPI.
Interresting code spippet looks like below:

Code: Select all

	// Configure command phase
	SPIDEVICE.user.usr_command = (trans->command_bits) ? 1 : 0;
	SPIDEVICE.user2.usr_command_bitlen = trans->command_bits - 1;
	SPIDEVICE.user2.usr_command_value = trans->command; // todo: czy przesuwac

	// Configure address phase
	SPIDEVICE.user.usr_addr = (trans->address_bits) ? 1 : 0;
	SPIDEVICE.user1.usr_addr_bitlen = trans->address_bits - 1;
	SPIDEVICE.addr = trans->address << (32 - trans->address_bits);

	// TX Phase
	lldesc_setup_link(dmadesc_tx, trans->tx_buffer, trans->tx_bits, false);
	SPIDEVICE.dma_out_link.addr = (int)(&dmadesc_tx[0]) & 0xFFFFF;
	SPIDEVICE.dma_out_link.start = 1;
	SPIDEVICE.user.usr_mosi_highpart = 0;

	// RX Phase
	lldesc_setup_link(dmadesc_rx, trans->rx_buffer, trans->rx_bits, true);
	SPIDEVICE.dma_in_link.addr = (int)(&dmadesc_rx[0]) & 0xFFFFF;
	SPIDEVICE.dma_in_link.start = 1;
	SPIDEVICE.user.usr_miso_highpart = 0;

	// Configure tx/rx phase
	SPIDEVICE.mosi_dlen.usr_mosi_dbitlen = trans->tx_bits-1;
	SPIDEVICE.miso_dlen.usr_miso_dbitlen = trans->rx_bits-1;
	SPIDEVICE.user.usr_mosi = (trans->tx_buffer == NULL)?0:1;
	SPIDEVICE.user.usr_miso = (trans->rx_buffer == NULL)?0:1;
DMA should be applied but after command and address phase zeros are transmitted. When receiving, rx_buffer isnt changed at all (when I set whole buffer to some value before transmission, after transmission buffer is still the same).

SPIDEVICE.user.doutdin is set to zero (half duplex mode). When I change it to 1 (full duplex) a dead transmission loop occurs (CS low, CLK is ticking, MOSI is zero).

What should I do for starting this DMA?

Aeronautic
Posts: 11
Joined: Thu Jan 02, 2020 12:07 am

Re: SPI DMA assign [CUSTOM SPI DRIVER]

Postby Aeronautic » Tue Jan 14, 2020 12:15 pm

The problem was setting DMA channel wrong. Value was 2, not 4, so channel was set for HSPI not VSPI.

Code: Select all

	// Select DMA channel
	DPORT_SET_PERI_REG_BITS(DPORT_SPI_DMA_CHAN_SEL_REG, 3, 1, 4);

Who is online

Users browsing this forum: bugsplat404 and 9 guests