# Hello RTC Timer Example Demonstrates BM8563 RTC timer and alarm functionality for testing system auto power-on. Since BM8563's INT pin is connected to AXP2101's IRQ, the RTC can wake the system from powered-off state. ## Features - **RTC Timer** - Countdown timer with interrupt (1-255 seconds or minutes) - **RTC Alarm** - Multiple alarm modes: - Minute alarm (every hour at specified minute) - Hour+Minute alarm (daily at specified time) - Date+Hour+Minute alarm (monthly on specified day) - Weekday+Hour+Minute alarm (weekly on specified day) - **Console Interface** - Full control via serial commands - **LVGL Display** - Dark theme UI showing: - Current date and time in configured local timezone - Timer value, status, and expired flag - Alarm value, status, and triggered flag - Power off button - **Auto Power-On Test** - Timer/Alarm can wake system from AXP2101 power-off - **State Persistence** - Shows timer/alarm state after restart ## Hardware Requirements - CUBE32 board with: - ST7789 display - BM8563 RTC chip (INT connected to AXP2101 IRQ) - AXP2101 PMU chip - Touch panel (optional, for power-off button) ## Configuration ### 1. Enable Required Components In `idf.py menuconfig`: **CUBE32 Board Configuration → RTC Configuration:** - ✅ Enable RTC (BM8563) - Set Local Time Zone (default: Asia/Singapore) **CUBE32 Board Configuration → PMU Configuration:** - ✅ Enable PMU (AXP2101) **CUBE32 Board Configuration → Display Configuration:** - ✅ Enable Display - ✅ Enable LVGL **CUBE32 Board Configuration → Touch Configuration:** - ☑️ Enable Touch (optional, for UI button) **Component config → LVGL → Font usage:** - ✅ Enable Montserrat 14 - ✅ Enable Montserrat 24 ### 2. Select Application **CUBE32 Application Selection:** - Select "Hello RTC Timer Example" ### 3. Timezone Configuration The timezone is configured in menuconfig: **CUBE32 Board Configuration → RTC Configuration → Local Time Zone** Common timezone values: - `Asia/Singapore` - Singapore/Malaysia Time (GMT+8, default) - `Asia/Hong_Kong` - Hong Kong Time (GMT+8) - `Asia/Shanghai` - China Standard Time (GMT+8) - `Asia/Tokyo` - Japan Standard Time (GMT+9) - `UTC` - UTC - `America/Los_Angeles` - US Pacific Time (with DST) - `America/New_York` - US Eastern Time (with DST) Or use POSIX timezone format (set via console command `tz`): - `CST-8` - China/Hong Kong/Singapore (no DST) - `PST8PDT,M3.2.0,M11.1.0` - US Pacific (with DST) - `EST5EDT,M3.2.0,M11.1.0` - US Eastern (with DST) ## Build and Flash ```bash idf.py build idf.py -p PORT flash monitor ``` ## Console Commands ### Timer Commands | Command | Description | Example | |---------|-------------|---------| | `ts <seconds>` | Set timer countdown (1-255 sec or 1-255 min) | `ts 60` | | `te` | Enable timer | `te` | | `td` | Disable timer | `td` | | `tc` | Clear timer expired flag | `tc` | | `tr` | Read and display timer status | `tr` | ### Alarm Commands | Command | Description | Example | |---------|-------------|---------| | `am <minute>` | Set minute alarm (0-59) | `am 30` | | `ah <hour> <minute>` | Set hour+minute alarm | `ah 14 30` | | `ad <day> <hour> <min>` | Set date+hour+minute alarm | `ad 15 8 0` | | `aw <wday> <hour> <min>` | Set weekday+hour+minute alarm (0=Sun, 6=Sat) | `aw 1 9 0` | | `ae` | Enable alarm | `ae` | | `ax` | Disable alarm | `ax` | | `ac` | Clear alarm triggered flag | `ac` | | `ar` | Read and display alarm status | `ar` | ### System Commands | Command | Description | Example | |---------|-------------|---------| | `p` | Power off system via AXP2101 | `p` | | `tz <timezone>` | Set timezone (runtime only, use menuconfig for permanent) | `tz JST-9` | | `help` | Show command help | `help` | ## Usage Examples ### Test Timer Auto Power-On ```bash # Set timer for 60 seconds > ts 60 # Power off the system > p # System powers off... # After 60 seconds, system automatically powers on! # Check console output - it will show "TIMER FLAG SET" ``` ### Test Alarm Auto Power-On (Daily at 14:30) ```bash # Set alarm for 14:30 > ah 14 30 # Enable alarm > ae # Power off the system > p # System powers off... # At 14:30, system automatically powers on! # Check console output - it will show "ALARM FLAG SET" ``` ### Test Alarm Auto Power-On (Every Monday at 9:00 AM) ```bash # Set alarm for Monday at 9:00 (0=Sun, 1=Mon, ..., 6=Sat) > aw 1 9 0 # Enable alarm > ae # Power off the system > p # Every Monday at 9:00 AM, system will power on! ``` ## Display Layout ``` ┌────────────────────────┐ │ RTC Timer Demo │ │ │ │ 14:30:25 │ ← Current time │ Jan 9, 2024 │ ← Date │ Thursday │ ← Weekday ├────────────────────────┤ │ 🔔 TIMER │ │ Value: 60 Enabled │ │ Not expired │ ├────────────────────────┤ │ 🔔 ALARM │ │ Mon 09:00 Enabled │ │ Not triggered │ ├────────────────────────┤ │ [⚡ Power Off] │ ← Button └────────────────────────┘ ``` ## Expected Behavior 1. On startup, displays current RTC time and timezone 2. Shows timer/alarm state from previous session 3. If timer flag or alarm flag is set, logs indicate system woke from RTC event 4. Console accepts commands for timer/alarm configuration 5. Power-off button or command shuts down via AXP2101 6. RTC timer/alarm can wake system from power-off state ## Testing Auto Power-On ### Method 1: Using Timer 1. Set timer: `ts 30` (30 seconds) 2. Power off: `p` or press button 3. Wait 30 seconds 4. System should automatically power on 5. Check log: `*** TIMER FLAG SET - System may have woken from timer ***` ### Method 2: Using Alarm 1. Set alarm 2 minutes in the future: `ah <hour> <minute>` 2. Enable alarm: `ae` 3. Power off: `p` or press button 4. Wait until alarm time 5. System should automatically power on 6. Check log: `*** ALARM FLAG SET - System may have woken from alarm ***` ## Runtime Timezone Change You can temporarily change the timezone at runtime using the console command: ```bash > tz JST-9 # Japan Standard Time (until reboot) > tz UTC0 # UTC (until reboot) > tz CST-8 # China/Hong Kong Standard Time (until reboot) ``` **Note:** Runtime timezone changes are temporary and reset on reboot. To permanently change the timezone, use menuconfig: - `CUBE32 Board Configuration → RTC Configuration → Local Time Zone` ## Troubleshooting **Timer doesn't trigger:** - Verify timer is enabled: `tr` - Check timer value is non-zero - Ensure timer flag was cleared: `tc` **Alarm doesn't trigger:** - Verify alarm is enabled: `ae` then `ar` - Check RTC time is correct - Ensure alarm matches current time pattern (minute/hour/day/weekday) **System won't power on automatically:** - Verify BM8563 INT is connected to AXP2101 IRQ (hardware) - Check PMU is enabled in menuconfig - Ensure timer/alarm interrupt is enabled (software does this automatically) **Power-off doesn't work:** - Verify PMU is enabled and initialized - Check AXP2101 is communicating (I2C) - Try console command `p` instead of button **Console not responding:** - Check serial monitor is connected at correct baud rate (115200) - Type `help` to see available commands - Ensure UART is not being used by another application
To create a project from this example, run:
idf.py create-project-from-example "cube32esp/cube32_bsp=0.0.17:hello_rtc_timer"