Can't set SPI registers with ESP-IDF V4

IanKibblewhite
Posts: 11
Joined: Mon Feb 08, 2021 4:56 am

Can't set SPI registers with ESP-IDF V4

Postby IanKibblewhite » Mon Feb 08, 2021 6:01 am

Hi All,

I have an ESP32 project using VSPI. It runs great on ESP-IDF V3.0 but the SPI won't run after moving to V4.2. I eventually traced it to a problem setting the VSPI registers.

For example, I read VSPI_CLOCK_REG (0x3ff65018), it's 0x80003043. I set it to 0x00001001 with either direct register write or using WRITE_PERI_REG (VSPI_CLOCK_REG, 0x00001001); When I read it immediately after it appears to be set, but with the second and subsequent reads it's back to it's original value, 0x80003043.

Same problem for all VSPI registers (0x3ff65xxx) and also HSPI registers (0x3ff64xxx), always with V4.n, works fine with V3.0. I thought it may be project code or config related so I tested in the hello_world example running on a DevKitC just adding:

printf("\n HSPI_CLOCK_REG \t\t %08x %08x %08x\n\n", HSPI_CLOCK_REG, 0x3FF64018, *((int*) 0x3FF64018));
WRITE_PERI_REG (HSPI_CLOCK_REG, 0x00001001); // SPI Clock f_SPI = 160MHz/(n+1), 0x00001001 = 40MHz (SYSCLK 40MHZ clock)
printf(" HSPI_CLOCK_REG \t\t %08x %08x %08x\n", HSPI_CLOCK_REG, 0x3FF64018, *((int*) 0x3FF64018));
printf(" HSPI_CLOCK_REG \t\t %08x %08x %08x\n", HSPI_CLOCK_REG, 0x3FF64018, *((int*) 0x3FF64018));
printf(" HSPI_CLOCK_REG \t\t %08x %08x %08x\n\n", HSPI_CLOCK_REG, 0x3FF64018, *((int*) 0x3FF64018));

Get with V4.2
80003043
00001001
80003043
80003043

Get with V3.0
80003043
00001001
00001001
00001001

Anyone got any ideas on what could cause this and a workaround?

Many thanks,

Ian

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: Can't set SPI registers with ESP-IDF V4

Postby ESP_Sprite » Mon Feb 08, 2021 7:35 am

Is it possible the SPI device is still clockgated / kept in reset? 3.0 is a while ago, could be that it didn't disable the SPI peripheral while not in use.

IanKibblewhite
Posts: 11
Joined: Mon Feb 08, 2021 4:56 am

Re: Can't set SPI registers with ESP-IDF V4

Postby IanKibblewhite » Fri Feb 12, 2021 1:52 am

You got it. Fantastic! It appears that v3.0 initializes with SPI's enabled. v4.2 initializes with SPI's disabled. All it took was:

DPORT_SET_PERI_REG_MASK (DPORT_PERIP_CLK_EN_REG, 0x00010000); // Enable VSPI Clock thru' DPORT
DPORT_CLEAR_PERI_REG_MASK (DPORT_PERIP_RST_EN_REG, 0x00010000); // Disable VSPI Reset

at initialization and problem solved. Thanks so much for your help. Really appreciated!
Ian

Who is online

Users browsing this forum: No registered users and 207 guests