py32l020-low-power-wakeup-2.ino

M5Stamp Timer Power 2 (PY32L020) · File : py32l020-low-power-wakeup-2.ino · Language : C · Use case : Mettre le microcontrôleur en mode arrêt profond avec réveil par interruption externe sur une GPIO.

Prepares a pin for external wakeup and puts the system into deep sleep to minimize consumption to ~6.72uA.

Ce code démontre la logique de mise en veille profonde sur le PY32L020. Il configure une GPIO en entrée avec pull-up pour détecter une impulsion (réveil). La partie critique 'Sleep' utilise des appels bas niveau spécifiques à l'architecture ARM Cortex-M0+ du PY32 (LL_PWR/LL_EXTI) qui ne sont pas standard dans l'Arduino core générique. Il faut utiliser le SDK PY32 officiel pour l'implémentation exacte des registres de puissance.

py32l020-low-power-wakeup-2.ino

#include <Arduino.h>

// Define pins based on M5Stamp Timer Power 2 schematic
// Assuming PY32L020 supports deep sleep via specific registers or HAL
// Note: Standard Arduino deepSleep() may not map directly to PY32 without specific core.
// This example illustrates the logic for RTC/External Wakeup flow.

#define WAKEUP_PIN 23 // Example GPIO connected to a physical button

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("Enter Low Power Mode in 3s...");
  delay(3000);

  // Configure Wakeup Pin
  pinMode(WAKEUP_PIN, INPUT_PULLUP);

  Serial.println("Going to Sleep (RTC/ExtWakeup)...");
  Serial.flush();

  // Placeholder for PY32L020 Low Level Low-Power entry
  // In a real PY32 SDK, one would call: LL_PWR_EnterSTOPMode() or similar
  // With EXTI configuration for WAKEUP_PIN on Falling Edge
  
  /* 
   * Pseudo-code for PY32 HAL:
   * LL_PWR_Unlock();
   * LL_PWR_SetWakeUpSource(LL_PWR_WAKEUP_SOURCE_EXTI);
   * LL_EXTI_ConfigLine(WAKEUP_PIN, LL_EXTI_TRIGGER_FALLING);
   * LL_EXTI_DisableAllITs(); 
   * LL_EXTI_EnableIT(WAKEUP_PIN);
   * LL_PWR_EnterStopMode(LL_PWR_STOP_MODE);
   */
   
  // For simulation/compilation without specific HAL:
  // __disable_irq();
  // __WFI(); // Wait For Interrupt
  
  // When waking up:
  Serial.println("Woke up!");
  
  // Clear wakeup source flag if needed
  // LL_PWR_ClearWakeUpFlag();
  
  delay(5000);
}

void loop() {
  // Do nothing, main loop is inside setup before sleep
  while(1);
}

← Back to the board