STM32F407VG SPI DMA failure

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

HonzaNbk
Posts: 2
Joined: Tue Dec 01, 2020 10:34 am

STM32F407VG SPI DMA failure

Postby HonzaNbk » Tue Dec 01, 2020 1:00 pm

Hi,

I am newbie in ChibiOS, I would like learn it. I have own board with MCU STM32F407VG, I tried write some functions for communication with AT25SF128ASHBT throught SPI.

When I tried comunicate with memory with lib from STM32Cube the memory comunicate well, when I try write similar code for Chibi, I get system halt with reason DMA failure code. How can I fix it?

My code looks like this

Code: Select all

  SPIConfig config;

  config.circular=false;
  config.ssport=GPIOA;
  config.sspad=SPI3NSS;
  config.end_cb=NULL;
  config.cr1 =SPI_CR1_BR_0|SPI_CR1_BR_1;   // memory comunicate in SPI mode 0 or 3
  config.cr2 =0;



in while i call:

Code: Select all

uint8_t UID[8];
   AT25SF128ASHBT_ReadUniqueID(&SPID3,&config,UID);
         chThdSleepMilliseconds(1000);



I have similar functions for works with memory.

Code: Select all

void AT25SF128ASHBT_ReadUniqueID(SPIDriver *spip,SPIConfig *config,uint8_t *id)
{
    uint8_t dataTx[5];

   memset(dataTx,0,sizeof(dataTx));

   dataTx[0]=MEM_READ_UNIQUE_ID;

    spiAcquireBus(spip);
    spiStart(spip,config);
    spiSelect(spip);
    spiStartSend(spip,5,dataTx);
    spiStartReceive(spip,8,id);
    spiUnselect(spip);
    spiStop(spip); 
    spiReleaseBus(spip);
}

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F407VG SPI DMA failure

Postby Giovanni » Tue Dec 01, 2020 1:22 pm

Note, your configuration structure needs to be "static const", it must exists while the driver is running so no auto variables.

A DMA usually can fail when you make it access non-mapped memory so check your pointers.

Giovanni

HonzaNbk
Posts: 2
Joined: Tue Dec 01, 2020 10:34 am

Re: STM32F407VG SPI DMA failure

Postby HonzaNbk » Wed Dec 02, 2020 3:48 pm

Giovanni wrote:Note, your configuration structure needs to be "static const", it must exists while the driver is running so no auto variables.
Giovanni
I am thinking that my configuration exists, when I call spi functions.

Giovanni wrote:A DMA usually can fail when you make it access non-mapped memory so check your pointers.

I change declaration UID to out of while cycle, but i had same situations.

After that i change my function to:

Code: Select all

void AT25SF128ASHBT_ReadUniqueID(SPIDriver *spip,SPIConfig *config,uint8_t *id){
    uint8_t dataTx[13];
    uint8_t dataRx[13];
    memset(dataTx,0,sizeof(dataTx));
    memset(dataRx,0,sizeof(dataRx));
    dataTx[0]=MEM_READ_UNIQUE_ID;

    spiAcquireBus(spip);
    spiStart(spip,config);
    spiSelect(spip);
    spiStartExchange(spip,13,dataTx,dataRx);
    spiUnselect(spip);
    spiStop(spip); 
    spiReleaseBus(spip);

    memcpy(id,&dataRx[5],8);
}


SPI send and receive data only twice.
spi.PNG
spi.PNG (8.11 KiB) Viewed 1879 times
It is also interesting, the time of second exchange, because i call chThdSleepMilliseconds(1000) after this function.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F407VG SPI DMA failure

Postby Giovanni » Wed Dec 02, 2020 4:29 pm

You set the callback to NULL, how do you know when SPI has finished a transfer? you cannot begin another one until it is over. Perhaps you need spiExchange() not spiStartExchange().

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 8 guests