2020-03-03 06:10 AM
I have a bug in the I2C bus where sometimes a glitch causes the BUSY flag to be set
I found that the only ways to clear it is either by SWRST in I2C->CR1 or by resetting in RCC->ABP1RSTR->I2CxRSTR
My question is, is there any difference I should know about between these 2 types of resets or they're exactly the same?
Thank you
Solved! Go to Solution.
2020-03-03 07:22 AM
In 'F4, I used both interchangeably and found no difference in their effect.
JW
2020-03-03 07:22 AM
In 'F4, I used both interchangeably and found no difference in their effect.
JW
2020-03-03 09:02 PM
Thank you for your response
2021-09-02 01:11 AM
There is one difference from MCU point of view:
The code below does not have any effect. The peripheral *) is not reseat and retain its configured values.
__HAL_RCC_I2C1_CLK_DISABLE();
I2C1->CR1 |= I2C_CR1_SWRST;
I2C1->CR1 &= ~I2C_CR1_SWRST;
__HAL_RCC_I2C1_CLK_ENABLE();
*) Normally the peripheral should not be accessed with clock disabled, I did not get exact answers what is happening "inside", but debugger shows me zeroes during SFR reading.
The code below does have effect. The peripheral is reset to its default values.
__HAL_RCC_I2C1_CLK_DISABLE();
__HAL_RCC_I2C1_FORCE_RESET();
__HAL_RCC_I2C1_RELEASE_RESET();
__HAL_RCC_I2C1_CLK_ENABLE();
There can be another scenarios where using SWRST is needed, e.g. strong access control via MPU. At least for STM32F205/7 there could be explicitely stated that registers are reset too. It was a surprise for me, I did not expect duplication of __HAL_RCC_I2C1_FORCE_RESET(). My understanding was that only I2C internal state machine is reset.