SAME70: QSPI in SPI mode?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

 

I've been practicing using SAME70-Xplained with I2C and SPI and got something working with those. Next in my "To Learn" list is QSPI in SPI mode.

As you can guess by the fact this post is here, it didn't go so simply as I expected. I can't get any signal out from QSPI. I had same kinds of problems with learning SPI, which ended up being a missing check on enabling clock. I think the problem might be again some missing configs/definitions, which enables a critical part of QSPI.

I found it clearer to work with ASF wizard, getting my hands immediately to the code with documentation in the comments.

 

main.c:

#include "conf_board.h"
#include <asf.h>

 

int main (void)
{
    /* Initializing system clock, hardware, clock for QSPI */
    sysclk_init();
    board_init();
    pmc_enable_periph_clk(ID_QSPI);

 

    /* Get the default config for QSPI(don't know any better yet) */
    struct qspi_config_t qspi_conf;
    qspi_get_config_default(&qspi_conf);

 

    /* Set QSPI speed to 10MHz and init with default configs + this 10MHz speed */
    qspi_conf.baudrate = 10000000;
    status_code_t status = qspi_initialize(QSPI, &qspi_conf);
    if (status != STATUS_OK)
        while (1); // If init fails, the program hangs here
    
    /* Some dummy data for testing */
    uint16_t data = 0xFF00;
    uint16_t ndata = ~data;

 

    while (1)
    {
        /* Write data and flash led to show this loop is running */
        qspi_write(QSPI, &data, 1);
        ioport_toggle_pin_level(LED0_GPIO);
        delay_ms(100);
        qspi_write(QSPI, &ndata, 1);
        ioport_toggle_pin_level(LED0_GPIO);
        delay_ms(100);
    }
}

 

config_board.h:

#ifndef CONF_BOARD_H
#define CONF_BOARD_H

 

/* Enable ICache and DCache */
#define CONF_BOARD_ENABLE_CACHE

 

/* Enable QSPI */
#define CONF_BOARD_QSPI

 

#endif /* CONF_BOARD_H */

 

The rest of the files are unmodified from what the ASF wizard provided.

I also tried the Atmel Start driver example without any modifications, but no QSPI pins (PA11-14) gave any signal, which I could see in my scope.

 

Is there anything obvious I've missed? For example, do I need to make some additional definitions for the clock in conf_clock.h? I've been trying to google a "Hello world!"- like example for QSPI, but I can't seem to find any easy enough for total beginner.

 

EDIT:

I got something out by testing SPI NOR Flash middleware from Atmel START, once again pointing towards my test program missing some configurations/initializations. I think I'll eventually get the workings of the QSPI driver by reading the SPI NOR Flash middleware code. If someone experienced enough still ends up bumping into this, I'd still appreciate an explanation on which definitions and functions I'll need to make in order to start writing stuff into QSPI channel.

This topic has a solution.
Last Edited: Tue. Mar 3, 2020 - 10:12 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!
Look at well working example of the QSPI configuration in SPI mode:

void qspi_get_config_default(struct qspi_config_t * qspi_config)
{
    qspi_config->serial_memory_mode = spi_mode; // QSPI_MR_SMM_SPI
    qspi_config->loopback_en = false;
    qspi_config->wait_data_for_transfer = false;
    qspi_config->csmode = QSPI_NOT_RELOADED;
    qspi_config->bits_per_transfer = QSPI_MR_NBBITS_8_BIT;
    qspi_config->min_delay_qcs = 0;
    qspi_config->delay_between_ct = 1;
    qspi_config->clock_polarity = 0;
    qspi_config->clock_phase = 0;
    qspi_config->baudrate = 50000000;
    qspi_config->transfer_delay = 0;
    qspi_config->scrambling_en = false;
    qspi_config->scrambling_random_value_dis = false;
    qspi_config->scrambling_user_key = 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh. Oh! So the SPI mode is defined as that serial_memory_mode! Now there's something coming out from my own code too! Now it's just figuring out how to apply it to connect to my other hardware...

 

The other difference in the default configs is csmode. In the default, it's QSPI_LASTXFER, while you have it as QSPI_NOT_RELOADED. I'm guessing with "not reloaded" option, you'll have to manually toggle chip select pins, while the other options select them for you(either to where last transfer went or advancing systematically).

 

Thank you!