3

I want to use as little power as possible reading USART1 at 300 baud approx. 40 bytes. There are numerous other peripherals but they don't need to run- all that needs to be running is the RTC in parallel. Peripherals need to be frozen, ram needs to be the same.

The way I see it Low power run mode is the optimal mode (please correct me if I'm wrong here) for this:

void HAL_PWREx_EnableLowPowerRunMode(void)
{
  /* Enters the Low Power Run mode */
  SET_BIT(PWR->CR, PWR_CR_LPSDSR);
  SET_BIT(PWR->CR, PWR_CR_LPRUN);
}

enter image description here

Now the clock configuration at the moment is

  • System Clock source = PLL (HSI)
  • SYSCLK(Hz) = 32000000
  • HCLK(Hz) = 32000000
  • AHB Prescaler = 1
  • APB1 Prescaler = 1
  • APB2 Prescaler = 1
  • HSI Frequency(Hz) = 16000000
  • PLLMUL = 6
  • PLLDIV = 3
  • Flash Latency(WS) = 1
  • Power regulator voltage = SCALE 1

How do I go into this mode and recover from it?

// Init?
HAL_PWREx_EnableLowPowerRunMode();
HAL_PWREx_DisableLowPowerRunMode();
// Deinit?

My attempt at init, what am I missing here?

void init_clock(){


  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;

  /**Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
    /**Configure the main internal regulator output voltage 
    */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

    /**Initializes the CPU, AHB and APB busses clocks 
    */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_DIV4;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = 0;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }

}
  • Deinit = Same as inital init of clock config
Flying Swissman
  • 818
  • 2
  • 14
  • 39
  • You might have better luck asking on electronics.stackexchange. Note that cross posting causes some people to become unreasonably angry and your question is likely to be deleted from both sites, so choose one. – BurnsBA Apr 25 '17 at 12:00
  • @BurnsBA I'm going to try my luck here. Last time it worked out. See my similar question http://stackoverflow.com/questions/34874020/auto-baud-rate-detect-for-stm32l0 – Flying Swissman Apr 25 '17 at 12:05
  • UART1 is not low power. That would be is LPUART1. And just because someone did not notice site-rules does not make the question on-topic. We are not a consulting service. You better try elsewhere. – too honest for this site Apr 25 '17 at 12:07
  • @Olaf yes I know, this question is about UART1 not LPUART1 – Flying Swissman Apr 25 '17 at 12:08
  • @Olaf what site-rules am I violating- please tell me and I will adjust or delete my question – Flying Swissman Apr 25 '17 at 12:11
  • There is no UART1 on the STM32 series. Not all have USART1, but all have LPUART1. So if you are after minimal poweer consumption, start using the correct UART. And read [ask] – too honest for this site Apr 25 '17 at 12:13
  • @Olaf I meant to write USART1 and LPUART is already being used – Flying Swissman Apr 25 '17 at 12:27
  • 1
    In my experience you need to know the right "recommmeded sequence" and it is not necessarily correct or even only mentioned in the manual. You did read the manual thoroughly, didn't you? It might be "hidden". Do you have access to support/coaching by the chip supplier? This is of course only applicable if you have a corresponding contract or are otherwise an important customer. – Yunnosch Apr 25 '17 at 13:23

1 Answers1

0

The USART1 can receive a byte in stop mode and is also able to wake up.

The procedure to achieve low power is to use LSE for USART1 and wake up from stop mode on RXNE.

  UART_WakeUpTypeDef wakeup;
  wakeup.WakeUpEvent=UART_WAKEUP_ON_READDATA_NONEMPTY;
  HAL_UARTEx_StopModeWakeUpSourceConfig(&huart1,wakeup);   
  HAL_UARTEx_EnableStopMode(&huart1);

This is simpler and equal to if not better than BAM with DMA and Low Power Sleep.

Flying Swissman
  • 818
  • 2
  • 14
  • 39