cancel
Showing results for 
Search instead for 
Did you mean: 

Stop mode: no entry

DUrbano
Associate III
Posted on October 17, 2014 at 16:04

Hi at all,

I'm working on an stm32401ccu, but I can't send it in stop mode; my code is quite simple, in fact I use the UART1 to send a command that realize the entry in stop mode, and a button linked to PB0 pin (configured as EXTI0), to exit from stop mode. There are 2 external oscillator, 16MHz and 768KHz, and the first one is selected as primary source clock. This is my very simple code:


/* Includes ------------------------------------------------------------------*/

#include ''stm32f4xx_hal.h''

#include ''usart.h''

#include ''gpio.h''

#include ''stdbool.h''

/* Private variables ---------------------------------------------------------*/


/* USER CODE BEGIN 0 */

bool
f_EnterStopMode = 
false
;

bool
f_reset = 
false
;

bool
swt = 
false
;


uint8_t RxBuffer1[3];

/* USER CODE END 0 */


/* Private function prototypes -----------------------------------------------*/

void
SystemClock_Config(
void
);


int
main(
void
)

{


/* USER CODE BEGIN 1 */

uint32_t temp;

/* USER CODE END 1 */


/* MCU Configuration----------------------------------------------------------*/


/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();


/* Configure the system clock */

SystemClock_Config();


/* System interrupt init*/

/* Sets the priority grouping field */

HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);


/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_USART1_UART_Init();


/* USER CODE BEGIN 2 */

HAL_UART_Transmit(&huart1, (uint8_t *) &
''$''
, 1, 5);

HAL_Delay(300);

HAL_UART_Transmit(&huart1, (uint8_t *) &
''Device ready ''
, 15, 5);

HAL_UART_Receive_IT(&huart1, (uint8_t*)RxBuffer1, 1);


HAL_GPIO_WritePin(GPIOB, 5, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, 5, GPIO_PIN_RESET);

/* USER CODE END 2 */


/* USER CODE BEGIN 3 */

/* Infinite loop */

while
(1)

{

HAL_Delay(1000);

if
(swt) HAL_UART_Transmit(&huart1, (uint8_t *) &
''.''
, 1, 15);

else
HAL_UART_Transmit(&huart1, (uint8_t *) &
''|''
, 1, 15); 

swt = !swt;


if
(f_reset) HAL_NVIC_SystemReset(); 


if
(f_EnterStopMode)

{

HAL_UART_Transmit(&huart1, (uint8_t *) &
''\r\nDevice is going to enter in stop mode''
, 39, 15);

f_EnterStopMode = 
false
;

temp = PWR->CR;

temp |= (uint32_t) 0x00000200;
//FPDS[bit 9] = 1

temp &= (uint32_t) 0xFFFFFBFF;
//LPLVDS[bit 10] = 0

PWR->CR = temp;


__HAL_RCC_HSI_ENABLE();
//enable HSI RC oscillator

while
((RCC->CR & (uint32_t)0x00000002)==0);
//wait until HSI is stable

// Switch to HSI oscillator before enter stop mode

temp = RCC->CFGR;

temp &= (uint32_t) 0xFFFFFFFC;

RCC->CFGR = temp;


HAL_NVIC_ClearPendingIRQ(USART1_IRQn);

HAL_NVIC_ClearPendingIRQ(EXTI0_IRQn);

HAL_NVIC_ClearPendingIRQ(SysTick_IRQn);

temp = EXTI->PR;

temp|= (uint32_t) 0x0067FFFF;

EXTI->PR = temp;


HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
//<- qui il codice si ferma 

/* L'istruzione agisce sul power control register resettando il bit 1, PDDS,

e settando il bit 0, LPDS, in base al valore di 'Regulator' */


SystemClock_Config();
//<- qui il codice riprende la sua esecuzione 

HAL_UART_Transmit(&huart1, (uint8_t *) &
''\r\nDevice is now in run mode''
, 35, 15);

}

}

/* USER CODE END 3 */


}


/** System Clock Configuration

*/

void
SystemClock_Config(
void
)

{


RCC_ClkInitTypeDef RCC_ClkInitStruct;

RCC_OscInitTypeDef RCC_OscInitStruct;


__PWR_CLK_ENABLE();


__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);


RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

HAL_RCC_OscConfig(&RCC_OscInitStruct);


RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);


}


/* USER CODE BEGIN 4 */


/**

* @brief EXTI line detection callbacks

* @param GPIO_Pin: Specifies the pins connected EXTI line

* @retval None

*/

void
HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{


}

/**

* @brief Rx Transfer completed callback

* @param UartHandle: UART handle

* @note 

* @retval None

*/

void
HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)

{

if
(UartHandle == &huart1)

{

HAL_GPIO_WritePin(GPIOB, 5, GPIO_PIN_SET);

if
(RxBuffer1[0]==
'P'
) f_EnterStopMode = 
true
; 

else
if
(RxBuffer1[0]==
'R'
) f_reset = 
true
; 


/* Re-enable UART1 (external) receiver interrupt and initialize RxBuffer1 as reception buffer */

if
(HAL_UART_Receive_IT(&huart1, (uint8_t*)RxBuffer1, 1) != HAL_OK)

{

//Error_Handler();

} 

HAL_GPIO_WritePin(GPIOB, 5, GPIO_PIN_RESET); 

}


}

/* USER CODE END 4 */


#ifdef USE_FULL_ASSERT


/**

* @brief Reports the name of the source file and the source line number

* where the assert_param error has occurred.

* @param file: pointer to the source file name

* @param line: assert_param error line source number

* @retval None

*/

void
assert_failed(uint8_t* file, uint32_t line)

{

/* USER CODE BEGIN 6 */

/* User can add his own implementation to report the file name and line number,

ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

/* USER CODE END 6 */


}


#endif

It seems all is what the reference manual says about stop mode, but it does not work and I' like to know why; please, could anyone help me ? Regards
2 REPLIES 2
chen
Associate II
Posted on October 17, 2014 at 16:21

Hi

I do not have the solution for you.

However, are you sure you have got the low power modes right?

Stop mode :

does not reboot the processor.

The reference manual is not explicit about it but I think it just carries on from where it got paused but with a longer wake up timer than Sleep mode exit.

The manual says that Stop mode disables the Flash controller but it does not say what that means in terms of where execution re-starts.

DUrbano
Associate III
Posted on October 17, 2014 at 17:27

Hi,

I have not any doubt about what you told me, but my problem is that I can enter in stop mode and I don't understand why...