cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly reset SPI

Kuikui
Associate III
Posted on February 20, 2011 at 19:06

How to properly reset SPI

#spi2-usart3
17 REPLIES 17
Kuikui
Associate III
Posted on May 17, 2011 at 14:25

I tried to add SPI_DeInit(..); followed by SPI_Init(...) , but the result is still the same.

I'm stuck... I can't get why the SCK is clocking where as MOSI stays +3V...

And I don't understand why if I have only 1 partition, everything's fine ....

For debugging, I changed the MOSI pin to GPIO function, and I managed to make it go low and high levels. When configured as AF PP, nothing happens during clocks...

Does anyone has already seen this ?

I'm stuck :\

Posted on May 17, 2011 at 14:25

Well here are a couple of thoughts.

Look carefully at what you initialize in each partition.

Try calling/starting the second partition at earlier times from within the first. Do a binary search to figure out what differs.

Look at enabled interrupts, vector address (0x200 boundary)  and service routines, perhaps you are firing an unhandled interrupt.

Add in debug/diagnostic code to dump out peripheral and clock settings. Start with clock and reset registers.

Dump out large portions of the register maps in hex, compare them between the two partitions, use fc/comp to spot differences.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kuikui
Associate III
Posted on May 17, 2011 at 14:25

Another test..

Only 1 partition now.

First boot => it works.

I reset the board with the RST pin => doesn't work anymore ...

Maybe having a sleep would help ...

Kuikui
Associate III
Posted on May 17, 2011 at 14:25

Here is a few code.

 do

 {

  /* Checkup memory */

    FlashID = sFLASH_ReadID();

           

  table[0] = SPI2->CR1;

  table[1] = SPI2->CR2;

  table[2] = SPI2->SR;

  table[3] = RCC->APB1ENR;

  table[4] = RCC->APB2ENR;

  table[5] = RCC->AHBENR;

  table[6] = GPIOB->ODR;

  } while (FlashID != sFLASH_M25P64_ID );

This is how I proceed :

1° Power-up and flash the code

2° It works ( FlashID == M25P64_ID ) ... Reset with IAR => it works ... Reset, reset reset => it works, it works, it works. Reflash => it works.

3° Jump to partition 2

4° Reboot (with IAR)

5° Code does not work ( FlashID = 0x00, no SPI clock, table is exactly the same as when it was working )

6° Then I reboot (with IAR) again, and again, and again ... still doesn't work..

8° Okay, so let's reflash the code !

9° After a reflash ... doesn't work .... no clock, no SPI

10° Reflash, reflash, and reflash ... doesn't work ....

Finally ... power-off and power-up ... and now it works.

Believe me or not, the ONLY way to make it work is to make a power-reboot ... I've never seen such a situation ...

The ''log'' table is exactly the same when it's working or not.

What other register should I look at ??

What could that much mess-up the SPI ??

Why when I reset the µC with JTAG it still doesn't work ??

Kuikui
Associate III
Posted on May 17, 2011 at 14:25

I've checked the ISR's, and now I'm on only one partition.

I think the issue is how I setup the SPI.

I'll post the code later.

sima2
Associate III
Posted on May 17, 2011 at 14:25

Are you using any interrupts in the bootloader? You must turn off all enabled interrupts in the bootloader before jumping to the application.

Have you forgotten to relocate the interrupt vector table in the application?

For example: NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8200);

Posted on May 17, 2011 at 14:25

Does the SPI Flash device have a reset pin? Are you leaving it in an invalid state?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kuikui
Associate III
Posted on May 17, 2011 at 14:25

I thought about it, but even if the SPI device would mess-up, the SPI host should still send clocks and data on MOSI.

Posted on May 17, 2011 at 14:25

Get some small code example that demonstrates this failure.

If it's not coming out the pins then you need to look at the GPIO settings, and confirm that the SPI2 is not remapped. Perhaps it's clashing with USART3 or TIM1. Check clocks on/off for those, or remap them elsewhere if appropriate. If the SPI clock is not present, consider if it is pending the TX register being loaded by DMA or a write.

The reset for SPI2 (host side) is RCC->APB1RST bit 14

Dump all the RCC, GPIOB, SPI2 and AFIO registers in hex, and paste them in forum.

Does it behave differently if NOT attached to a debugger?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..