2025-06-17 7:00 AM
Hi all,
I've been struggling so much to get wake from uart working on this board.
It looks like it should be simple, I have this code which I am pretty sure should be everything needed, but it just doesn't wake up when I send data to the serial port.
Can anyone see what I might be missing?
#include <Arduino.h>
#include <stm32u5xx_hal.h>
#include <stm32u5xx_ll_usart.h>
#include <stm32u5xx_ll_bus.h>
#include "CustomPinsHub.h"
static constexpr uint32_t LED_PIN = LED1_GRN;
uint8_t aRxBuffer[10];
void SystemClock_Config(); // forward
HardwareSerial stlinkSerial(rx_pin2debug, tx_pin2debug);
void setup()
{
stlinkSerial.begin(115200);
HAL_PWREx_EnableUltraLowPowerMode();
pinMode(LED1_GRN, OUTPUT);
digitalWrite(LED1_GRN, LOW);
stlinkSerial.println("→ Setup complete. LED is ON.");
delay(500);
UART_HandleTypeDef *huart = stlinkSerial.getHandle();
UART_WakeUpTypeDef wudata{};
wudata.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;
HAL_UARTEx_StopModeWakeUpSourceConfig(huart, wudata);
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_UART_ENABLE_IT(huart, UART_IT_WUF);
HAL_UARTEx_EnableStopMode(huart);
HAL_UART_Receive_IT(huart, (uint8_t *)aRxBuffer, 10);
stlinkSerial.println("Entering STOP-1, waiting for any RX data to wake me..");
stlinkSerial.flush();
delay(500);
HAL_SuspendTick();
HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
HAL_ResumeTick();
SystemClock_Config();
delay(500);
stlinkSerial.println("✔ Woke up from STOP-1! Led off");
delay(500);
digitalWrite(LED_PIN, HIGH);
}
void loop()
{
// nothing
}
2025-06-17 7:08 AM
Hello @Alan01252
Please refer to the example below:
2025-06-17 7:28 AM
Thanks for the swift reply, but I amm very confused, I can't see anything I am missing in that example and what the code above.. Other than
EXTI10_Wakeup_Enable
but that doesn't actually seem to have any implementation behind it?
2025-06-17 8:21 AM
Try to make UART receive work before implementing the stop and waking up mode.
2025-06-17 10:19 AM - edited 2025-06-17 10:20 AM
Apologies, just to be clear, receive and transmit do work.
I can do a simple ping/pong when the chip is awake. What I can't do is a get the board to wake up from sleep :(