cancel
Showing results for 
Search instead for 
Did you mean: 

use of RCC_APB2PeriphResetCmd()

kolodko1
Associate II
Posted on March 08, 2010 at 15:04

use of RCC_APB2PeriphResetCmd()

9 REPLIES 9
John F.
Senior
Posted on May 17, 2011 at 13:42

Look at the Clock Tree diagram (fig 8) and the System Architecture (figs 1 / 2 ) and you will see how the peripherals are connected to APB2. You can map / re-map them to STM32 pins but you will also want to enable or disable them. That's when you need ''RCC_APB2PeriphResetCmd( )''. You can enable / disable any of the pre-defined functions listed below.

RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB, RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE, RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1, RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1, RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3

kolodko1
Associate II
Posted on May 17, 2011 at 13:42

Hi

Thanks for reply.

But I still do not understand what you mean.

What means enable/disable since name of function contain ''reset'':  RCC_APB2PeriphResetCmd() and body:

void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)

{

(...)

  if (NewState != DISABLE)

  {

    RCC->APB2RSTR |= RCC_APB2Periph;

  }

  else

  {

    RCC->APB2RSTR &= ~RCC_APB2Periph;

  }

}

operate on APB2RSTR register, in RM0008this register is described:

APB2 peripheral reset register.

You claiming is disable/enable but for disable/enable is RCC_APB2PeriphClockCmd() what operate on RCC_APB2ENR what is enable register. So I still do not understand reason of RCC_APB2PeriphResetCmd() function.

Could some one clarify?

Best Regards

John F.
Senior
Posted on May 17, 2011 at 13:42

Hi,

Sorry if my reply confused you.

RCC_APB2PeriphResetCmd is used to RESET a peripheral.

RCC_APB2PeriphClockCmd is used to enable or disable the CLOCK to a peripheral.

lowpowermcu
Associate II
Posted on May 17, 2011 at 13:42

Hi,

In the reference manual it is explained in ''APB2 peripheral reset register'' subsection of RCC section:

bit 0: No effect

bit 1: Reset peripheral

Regards,

lowpower

Posted on May 17, 2011 at 13:42

>>So I still do not understand reason of RCC_APB2PeriphResetCmd() function. Could some one clarify?

To get it into a KNOWN/VALID state instead of some RANDOM/INVALID/ARBITRARY one, once the clocks are running.

-Clive

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

This is a pretty curious function. It would seem that you can get the peripheral in a known state simply by enabling and disabling the clock (this is called ''DeInit'' in the STM32 library). What is the difference between toggling the enable bit and toggling the reset bit? Do you really need to reset the peripheral after you enable to put it into a know state?

I suspect the answer is no. The reset function was put into the device by the designers as a hedge in case something didn't work right with the enable sequence or something else for device testing.

damh
Associate II
Posted on May 17, 2011 at 13:42

RCC_APB2PeriphResetCmd(xxx, ENABLE); is like pressing the reset button

RCC_APB2PeriphResetCmd(xxx, DISABLE); is like releasing it again.

You have to call both functions in this order to do a correct reset of the peripheral.

Enabling or disabling the clocks does change the current consumption. It is like power on/off of your monitor. The state isn't changed by doing this. You can't only see the function in off-mode. Some peripheral have side effects on CLK enable/disable! So please check it in your case.

kolodko1
Associate II
Posted on May 17, 2011 at 13:42

Thanks for replay for everyone. Now is much more clear.

But it is really shame that such function and functionality is not documented at all, or maybe I can not find out(?)

Regards
Tomas DRESLER
Senior II
Posted on May 17, 2011 at 13:42

Not deep enough search :)

In Reference Manual, chapter 7 RCC, look for the registers (esp. RCC_APB2RSTR, RCC_APB1RSTR).

In fact, Whatever_DeInit doesn't toggle clock, but the reset line. The peripheral is reset properly at power-on, but you may want to initialize it again without any side-effects if you changed the clock, if you want to change the mode of operation, if the peripheral got stuck for whatever reason...