need to be able to explicitly indicate Vddusb is valid in order to use the OTFS block in this chip; done via PWR CR2 bit USV.

This commit is contained in:
ziggurat29 2016-06-09 11:26:36 -05:00
parent 3970c98daf
commit d2b78eddec
2 changed files with 65 additions and 1 deletions

View File

@ -138,7 +138,7 @@ bool stm32l4_pwr_enablebkp(bool writable)
uint16_t regval;
bool waswritable;
/* Get the current state of the STM32 PWR control register */
/* Get the current state of the STM32L4 PWR control register 1 */
regval = stm32l4_pwr_getreg(STM32L4_PWR_CR1_OFFSET);
waswritable = ((regval & PWR_CR1_DBP) != 0);
@ -166,3 +166,49 @@ bool stm32l4_pwr_enablebkp(bool writable)
return waswritable;
}
/************************************************************************************
* Name: stm32l4_pwr_enableusv
*
* Description:
* Enables or disables the USB Supply Valid monitoring. Setting this bit is
* mandatory to use the USB OTG FS peripheral.
*
* Input Parameters:
* set - True: Vddusb is valid; False: Vddusb is not present. Logical and electrical
* isolation is applied to ignore this supply.
*
* Returned Value:
* True: The bit was previously set.
*
************************************************************************************/
bool stm32l4_pwr_enableusv(bool set)
{
uint16_t regval;
bool wasset;
/* Get the current state of the STM32L4 PWR control register 2 */
regval = stm32l4_pwr_getreg(STM32L4_PWR_CR2_OFFSET);
wasset = ((regval & PWR_CR2_USV) != 0);
/* Enable or disable the ability to write */
if (wasset && !set)
{
/* Disable the Vddusb monitoring */
regval &= ~PWR_CR2_USV;
stm32l4_pwr_putreg(STM32L4_PWR_CR2_OFFSET, regval);
}
else if (!wasset && set)
{
/* Enable the Vddusb monitoring */
regval |= PWR_CR2_USV;
stm32l4_pwr_putreg(STM32L4_PWR_CR2_OFFSET, regval);
}
return wasset;
}

View File

@ -101,6 +101,24 @@ bool stm32l4_pwr_enableclk(bool enable);
bool stm32l4_pwr_enablebkp(bool writable);
/************************************************************************************
* Name: stm32l4_pwr_enableusv
*
* Description:
* Enables or disables the USB Supply Valid monitoring. Setting this bit is
* mandatory to use the USB OTG FS peripheral.
*
* Input Parameters:
* set - True: Vddusb is valid; False: Vddusb is not present. Logical and electrical
* isolation is applied to ignore this supply.
*
* Returned Value:
* True: The bit was previously set.
*
************************************************************************************/
bool stm32l4_pwr_enableusv(bool set);
#undef EXTERN
#if defined(__cplusplus)
}