Can I safely use 2 sets of pinouts for singe SPI bus? error:"addApbChangeCallback(): duplicate func"

smarq8
Posts: 7
Joined: Sat Mar 06, 2021 5:33 pm

Can I safely use 2 sets of pinouts for singe SPI bus? error:"addApbChangeCallback(): duplicate func"

Postby smarq8 » Sat Mar 06, 2021 6:00 pm

Can I map 2nd sets of pintouts for VSPI bus sefely? Generally everythink work fine as long as I use TFT and SD in single task loop, or tasks at the same priority and core, in any other configuration wtd trigger and/or SD return crc errors etc. I'm just not sure can I ignore "addApbChangeCallback(): duplicate func" warning and keep going.

My board: TTGO T-Display
Framework: Arduino
IDE: platformio

here is sample how I initialize SD:

Code: Select all

static SPIClass SD_SPI(VSPI);
void SDINIT(){
  pinMode(SD_CS_PIN,OUTPUT); digitalWrite(SD_CS_PIN,1);
  SD_SPI.begin(SD_SCK_PIN,SD_MISO_PIN,SD_MOSI_PIN,-1); // ESP32
  if(!SD.begin(SD_CS_PIN,SD_SPI)){
    LOG("Card Mount Failed\n");
    SD_MOUNT = 0;
    return;
  }
  // other initialize stuff here
}
some SPI.cpp library modyfication:

Code: Select all

#include <esp32-hal-log.h>
void SPIClass::begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
{
    log_i("SPI.begin( %i,%i,%i,%i )",sck,miso,mosi,ss); // <-- I just added here some logs
    if(_spi) {
        return;
    }
    ...
monitor result:

Code: Select all

[I][SPI.cpp:33] begin(): SPI.begin( 18,19,19,-1 ) <--- tft VSPI (tft_eSPI library)
[I][SPI.cpp:33] begin(): SPI.begin( 25,26,27,-1 ) <--- other SPI device HSPI (its time critical so I need to use separate SPI bus)
[I][SPI.cpp:33] begin(): SPI.begin( 33,32,15,-1 ) <--- SD VSPI
[E][esp32-hal-cpu.c:93] addApbChangeCallback(): duplicate func=400D7964 arg=3FFBDCAC
[I][SPI.cpp:33] begin(): SPI.begin( -1,-1,-1,-1 ) <--- its because SD.begin(SD_CS_PIN,SD_SPI)->spi.begin()

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

Re: Can I safely use 2 sets of pinouts for singe SPI bus? error:"addApbChangeCallback(): duplicate func"

Postby ESP_Sprite » Sun Mar 07, 2021 5:48 am

You can't have hardware have one SPI peripheral on multiple sets of pins...

smarq8
Posts: 7
Joined: Sat Mar 06, 2021 5:33 pm

Re: Can I safely use 2 sets of pinouts for singe SPI bus? error:"addApbChangeCallback(): duplicate func"

Postby smarq8 » Sun Mar 07, 2021 10:30 am

Then why this work? Ofcourse this example use 2 instances of SPI class and I'm aware about that I can not use both device at the same time. I do that only beacause of I do not have easy acces to TFTs SPI pins and also unpredictable nature of SD data writing and time critical sensor disqualify them from occupy same SPI bus.

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

Re: Can I safely use 2 sets of pinouts for singe SPI bus? error:"addApbChangeCallback(): duplicate func"

Postby ESP_Sprite » Mon Mar 08, 2021 2:14 am

I'm not too knowledgable about the Arduino SPI implementation, but an ESP32 has two user-accessible SPI peripherals. That may be the reason having two SPI.begin calls work. I don't think you can add a 3rd SPI.begin call as the hardware will have run out of SPI peripherals.

Who is online

Users browsing this forum: No registered users and 110 guests