• 0
sgiurgiu

PmodMTDS with Designware ARC EM SK

Question

Hi, I've been trying for some time to get the PmodMTDS to work with the EMSK board, and i have not been successful so far. I believe that the part I'm not getting right is the initialization of the board.  I have only modified the MtdsHal.h and MtdsHal.cpp .

The board is attached to the J5 PMOD on the EMSK board. The defines are as follows:

#include "embARC_toolchain.h"
#include "embARC_error.h"
#include "dev_spi.h"
#include "dev_gpio.h"
#include "board.h"

#define INPUT GPIO_DIR_INPUT
#define OUTPUT GPIO_DIR_OUTPUT
#define LOW 0
#define HIGH 1

#define EMSK_MTDS_SPI_ID 		DW_SPI_0_ID
#define EMSK_MTDS_0_SPI_LINE	EMSK_SPI_LINE_1
#define EMSK_MTDS_0_GPIO_ID		EMSK_GPIO_PORT_A


#define EMSK_MTDS_0_CS_PIN		(18)
#define EMSK_MTDS_0_MOSI_PIN	(19)
#define EMSK_MTDS_0_MISO_PIN	(20)
#define EMSK_MTDS_0_SCLK_PIN	(21)

#define MOSI EMSK_MTDS_0_MOSI_PIN
#define MISO EMSK_MTDS_0_MISO_PIN
#define SCK EMSK_MTDS_0_SCLK_PIN


#define MTDS_GPIO_INT_PIN_OFS		(24)
#define MTDS_GPIO_RST_PIN_OFS		(25)
#define MTDS_GPIO_STSA_PIN_OFS		(26)
#define MTDS_GPIO_STSB_PIN_OFS		(27)
#define MTDS_GPIO_RST_PIN_MASK		(1<<MTDS_GPIO_RST_PIN_OFS)
#define MTDS_GPIO_INT_PIN_MASK		(1<<MTDS_GPIO_RST_PIN_OFS)
#define MTDS_GPIO_STSA_PIN_MASK		(1<<MTDS_GPIO_STSA_PIN_OFS)
#define MTDS_GPIO_STSB_PIN_MASK		(1<<MTDS_GPIO_STSB_PIN_OFS)
  
#define	pinMtdsSelStd		EMSK_MTDS_0_CS_PIN				// standard SPI SS pin  
#define	pinMtdsIntA			MTDS_GPIO_STSA_PIN_OFS		// touch panel message status pin
#define	pinMtdsIntB			MTDS_GPIO_STSB_PIN_OFS		// shield ready status pin

  

 

In MtdsHal.cpp I have (important bits):

	DEV_SPI_PTR dev_spi;
	DEV_GPIO *dev_gpio;

	void digitalWrite(int pin,int what)
	{
		dev_gpio->gpio_write(what<<pin, 1<<pin);
	}
	int digitalRead(int pin)
	{
		uint32_t d;
		dev_gpio->gpio_read(&d,1<<pin);
		return d;
	}
	void pinMode(int pin,int mode)
	{
		dev_gpio->gpio_control(mode, CONV2VOID(1<<pin));
	}
void MtdsHalInit(int pinSel) {
	dev_gpio = gpio_get_dev(EMSK_MTDS_0_GPIO_ID);
	uint32_t direction = (GPIO_DIR_OUTPUT << MTDS_GPIO_RST_PIN_OFS);
	int32_t ercd = dev_gpio->gpio_open(direction);
	dev_gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, CONV2VOID(1<<MTDS_GPIO_INT_PIN_OFS));
	dev_gpio->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, CONV2VOID(1<<MTDS_GPIO_RST_PIN_OFS));
	pinMtdsSel = pinSel;
}

bool MtdsHalResetDisplay(int pinSel) {
    int pinRst = pinSel + 7;
    pinMode(pinRst, OUTPUT);
	digitalWrite(pinRst, LOW);
	MtdsHalDelayMs(1);
	digitalWrite(pinRst, HIGH);
	MtdsHalDelayMs(1);
	return true;
}
void MtdsHalInitSpi(uint32_t pspiInit, uint32_t frq) {
    dev_spi = spi_get_dev(EMSK_MTDS_SPI_ID);
	int32_t ercd = dev_spi->spi_open(DEV_MASTER_MODE,frq);
//this is just throwing stuff at the wall to see what sticks
	ercd = dev_spi->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(SPI_CLK_MODE_0));
	ercd = dev_spi->spi_control(SPI_CMD_MST_SET_FREQ, CONV2VOID(frq));
	ercd = dev_spi->spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
	ercd = dev_spi->spi_control(SPI_CMD_ENA_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
	ercd = dev_spi->spi_control(SPI_CMD_FLUSH_RX, 0);
	ercd = dev_spi->spi_control(SPI_CMD_FLUSH_TX, 0);
}
void MtdsHalEnableSlave(bool fEn) {
	if (fEn) {
		dev_spi->spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));
	}
	else {
		dev_spi->spi_control(SPI_CMD_MST_DSEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE));	
	}
}
bool MtdsHalSpiReady() {
	uint32_t st = 0;
	dev_spi->spi_control(SPI_CMD_GET_STATUS,&st);
	return st == 1;
}
uint8_t MtdsHalPutSpiByte(uint8_t bSnd) {
    uint8_t	bRcv;
	while(dev_spi->spi_write(&bSnd, 1) == 0);
    while(dev_spi->spi_read(&bRcv, 1) == 0);
  	MTDS_DEBUG("MtdsHalPutSpiByte: %d, rcv: %d\n",bSnd,bRcv);
    return bRcv;
}

 

During the initialization phase, the display is reset just fine, but in the sync stage, when MtdsHalPutSpiByte(chnCmdSync) is called, it returns chnStaIdle for the first time, then all subsequent calls are chnStaStartup, until it resets again.

So that's why I'm suspecting that I am not initializing the board properly. But I have no idea how to. Any help is appreciated.

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi @jperyon,

Yes, that's the board (although v2.0) but that is not an arduino board. The Designware SDK does not have an arduino.h header at all, therefore anything that applies to the ARDUINO definitions do not apply here.Which is why I added my own defines (much like you have in your example MtdsHal.cpp). I have implemented (as shown) the digitalRead and digitalWrite and reset and put SPIByte APIs, but the problem is that there's still something wrong that I'm doing in there that doesn't let the board fully initialize. It flickers, the screen becomes briefly white, the led under the screen lights up, but that's the extent of it. The response to a chnCmdSync command is chnStaStartup.

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @sgiurgiu,

TheARC EM SK board I linked to uses the Spartan 6 FPGA and has multiple ARC processor designs saved in flash.  Is the designware similar to xilinx SDK?  If so have you looked at our PmodMTDS IP Core here and can be downloaded here with our vivado-library.

thank you,

Jon

Share this post


Link to post
Share on other sites
  • 0

Hi,

Thank you for the help so far.  I have found the vivado github repository earlier and i've been trying to map the driver implementation there with what I have. Unfortunately, it's not really all that similar (or at least, doesn't look like that to me).

The SDK that I'm using can be found here: https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp .

More specifically, the GPIO and SPI APIs that I'm using can be seen here:

https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/tree/master/device/ip/designware/spi

https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_osp/tree/master/device/ip/designware/gpio

I have been also studying the other drivers they made available (for WiFi) and I have implemented an u8glib driver for OLED before but I just cannot make heads or tails of what exactly should I write into the registers, and which device should I use : gpio or SPI.

 

The Reset functionality seems to be working fine, therefore I assume that GPIO is properly initialized : writing LOW and HIGH on the RST pin causes the display to reset.

The SPI functionality though is trickier. What I have right now is:

    dev_spi = spi_get_dev(EMSK_MTDS_SPI_ID);
    int32_t ercd = dev_spi->spi_open(DEV_MASTER_MODE,frq); //open device in master mode
    MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
	ercd = dev_spi->spi_control(SPI_CMD_MST_SEL_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE)); // select slave line
	MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
	ercd = dev_spi->spi_control(SPI_CMD_ENA_DEV, CONV2VOID(EMSK_MTDS_0_SPI_LINE)); // enable device
	MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
	ercd = dev_spi->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(SPI_CLK_MODE_0)); //set clock mode 0
	MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
	ercd = dev_spi->spi_control(SPI_CMD_MST_SET_FREQ, CONV2VOID(frq)); // set frequency
	MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
	ercd = dev_spi->spi_control(SPI_CMD_FLUSH_RX, 0); // flush rx
	MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);
	ercd = dev_spi->spi_control(SPI_CMD_FLUSH_TX, 0); // flish tx
	MTDS_DEBUG("MtdsHalInitSpi %d\n",ercd);

 

and put SPI byte:

 

 /*DEV_SPI_TRANSFER pmrf_xfer;
	DEV_SPI_XFER_INIT(&pmrf_xfer);
	DEV_SPI_XFER_SET_TXBUF(&pmrf_xfer, &bSnd, 0, 1);
	DEV_SPI_XFER_SET_RXBUF(&pmrf_xfer, &bRcv, 1, 1);
	DEV_SPI_XFER_SET_NEXT(&pmrf_xfer, NULL);
*/
	uint32_t cpu_status = cpu_lock_save();

	//dev_spi->spi_control(SPI_CMD_TRANSFER_POLLING, CONV2VOID(&pmrf_xfer));

	while(dev_spi->spi_write(&bSnd, 1) == 0);
    while(dev_spi->spi_read(&bRcv, 1) == 0);
   	MTDS_DEBUG("MtdsHalPutSpiByte: %d, rcv: %d\n",bSnd,bRcv);
    cpu_unlock_restore(cpu_status);

as it can be seen I tried with transfer_polling command and with plain spi_write and read APIs. when mtds.cpp is sending the  sync command (3) the response is always 38 (chnStaStartup)

If you have any suggestions on how exactly to map the pins ... it would be very appreciated.

All that im looking for right now is to be able to draw a line on the screen. After that is achieved, the rest would/should be easier.

 

MtdsHal.cpp

MtdsHal.h

Share this post


Link to post
Share on other sites
  • 0

Hi @sgiurgiu,

Unfortunately, we have no experience using Designware or the  ARC  EM SK board. I would suggest to reach out to Synopsys for a way to convert xilinx ip cores to work with their platform.

thank you,

Jon

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now