Can't set SPI registers with ESP-IDF V4
Posted: 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
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