Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 4:2afaac57dc82
- Parent:
- 2:aa4afe9a928c
--- a/main.cpp Thu Aug 03 06:19:33 2017 -0600
+++ b/main.cpp Mon Sep 25 17:33:00 2017 -0600
@@ -1,45 +1,134 @@
#include "mbed.h"
-#define USER_BUTTON PA_0
-InterruptIn event(USER_BUTTON);
-DigitalOut myled(LED2);
+bool sleepyTime = false;
+
+void interrupter()
+{
+ sleepyTime = true;
+};
-int go_to_sleep = 0;
-
-void pressed() {
- printf("Button pressed\n");
- go_to_sleep = go_to_sleep + 1;
- if (go_to_sleep > 3) go_to_sleep = 0;
+int main()
+{
+ /* (#)Initialize the LPTIM low level resources by implementing the */
+ DigitalOut led( PB_3 );
+ InterruptIn inter( PA_12 );
+ inter.fall( &interrupter );
+ led = 0;
+ RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
+ __HAL_RCC_MSI_RANGE_CONFIG( RCC_MSIRANGE_5 );
+ wait_ms( 2000 );
+ RCC_ClkInitStruct.ClockType = ( RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 );
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI; // 80 MHz
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 80 MHz
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; // 80 MHz
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 80 MHz
+ HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_4 );
+ HAL_PWREx_ControlVoltageScaling( PWR_REGULATOR_VOLTAGE_SCALE2 );
+ HAL_PWREx_EnableLowPowerRunMode();
+ SystemCoreClockUpdate();
+ HAL_PWREx_EnterSTOP0Mode( PWR_STOPENTRY_WFI );
-}
-
-int main() {
- int i = 0;
+ if( HAL_RCC_GetSysClockFreq() < 3000000 ) { led = 1; }
- printf("\nPress Button to enter/exit sleep & deepsleep\n");
-
- event.fall(&pressed);
-
- while (1) {
+ wait_ms( 1 );
+ led = 0;
+ wait_ms( 1000 );
+ led = 1;
+ wait_ms( 10 );
+ led = 0;
+ /* HAL_MPU_Disable(); */
+ /* __HAL_RCC_MSI_STANDBY_RANGE_CONFIG(RCC_MSIRANGE_5); */
+ /* __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI); */
+ /* GPIO_InitTypeDef GPIO_InitStructure = {0}; */
+ /* GPIO_InitStructure.Pin = GPIO_PIN_All; */
+ /* GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; */
+ /* GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; */
+ /* GPIO_InitStructure.Pull = GPIO_NOPULL; */
+ /* HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); */
+ /* HAL_GPIO_Init(GPIOH, &GPIO_InitStructure); */
+ /* __HAL_RCC_GPIOC_CLK_DISABLE(); */
+ /* __HAL_RCC_GPIOH_CLK_DISABLE(); */
+ /* __HAL_RCC_USB_CLK_DISABLE(); */
+ /* __HAL_RCC_ADC_CLK_DISABLE(); */
+ /* __HAL_RCC_USART1_CLK_DISABLE(); */
+ /* __HAL_RCC_USART2_CLK_DISABLE(); */
+ /* __HAL_RCC_LPUART1_CLK_DISABLE(); */
+ wait_ms( 2000 );
+ /* wait_ms(3000); */
+ /* HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN5); */
+ /* //pc.printf("1\r\n"); */
- if ((go_to_sleep == 0) || (go_to_sleep == 2)) {
- printf("%d: Running\n", i);
- myled = !myled;
- wait(1.0);
- }
+ /* /1* Enable the fast wake up from Ultra low power mode *1/ */
+ /* /1* HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); *1/ */
+ /* /1* HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); *1/ */
+ /* /1* __HAL_RCC_GPIOA_CLK_DISABLE(); *1/ */
+ /* /1* __HAL_RCC_GPIOB_CLK_DISABLE(); *1/ */
+ /* for(int i = 0; i < 13; ++i){ */
+ /* Thread::wait(1); */
+ /* HAL_GPIO_DeInit(GPIOA,i); */
+ /* HAL_GPIO_DeInit(GPIOB,i); */
+ /* HAL_GPIO_DeInit(GPIOC,i); */
+ /* HAL_GPIO_DeInit(GPIOH,i); */
+ /* } */
+ /* int j = 0; */
+ /* HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); */
+ /* HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); */
+ /* Thread::wait(5000); */
+ /* GPIO_InitStructure.Pin = GPIO_PIN_All; */
+ /* GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; */
+ /* GPIO_InitStructure.Pull = GPIO_NOPULL; */
+ /* HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); */
+ /* HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); */
+
+ /* Timer t; */
+ while( 1 ) {
+ if( sleepyTime ) {
+ led = 0;
+ /* HAL_PWR_EnterSTANDBYMode(); */
+ HAL_PWREx_EnterSTOP0Mode( PWR_STOPENTRY_WFI );
+ HAL_RCC_GetSysClockFreq();
+ wait_ms( 50 );
+ sleepyTime = false;
+ };
+
+ wait_ms( 1000 );
- if (go_to_sleep == 1) {
- myled = 0;
- printf("%d: Entering sleep (press user button to resume)\n", i);
- sleep();
- }
+ /* event.rise(&pressed); */
+ /* if ((go_to_sleep == 0) || (go_to_sleep == 2)) { */
+ /* printf("%d: Running\n", i); */
+ /* myled = !myled; */
+ /* wait(1.0); */
+ /* } */
+ led = 1;
+
+ wait_ms( 100 );
+
+ led = 0;
- if (go_to_sleep == 3) {
- myled = 0;
- printf("%d: Entering deepsleep (press user button to resume)\n", i);
- deepsleep();
- }
-
- i++;
- }
+ /* deepsleep(); */
+ /* if (go_to_sleep == 1) { */
+ /* myled = 0; */
+ /* printf("%d: Entering sleep (press user button to resume)\n", i); */
+ /* sleep(); */
+ /* } */
+ /* if (go_to_sleep == 3) { */
+ /* myled = 0; */
+ /* printf("%d: Entering deepsleep (press user button to resume)\n", i); */
+ /* deepsleep(); */
+ /* } */
+ /* t.reset(); */
+ /* t.start(); */
+ /* led = !led; */
+ /* j=0; */
+ /* while(j < 100000) { */
+ /* j = j + 1; */
+ /* } */
+ /* t.stop(); */
+ /* led = !led; */
+ /* led = !led; */
+ /* HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); */
+ /* HAL_GPIO_Init(GPIOD, &GPIO_InitStructure); */
+ /* HAL_GPIO_Init(GPIOH, &GPIO_InitStructure); */
+ /* Thread::wait(500); */
+ }
}