2025-12-08 4:12 AM - last edited on 2025-12-08 4:32 AM by Andrew Neil
Hi everyone,
I’m working with the STM32WB05KZ using the BLE RC Peripheral example from STM32CubeMX.
I added a push button on PA1 and an LED on PA0.
My goal:
Read PA1 button state
Turn ON LED on PA0 when button is pressed
Send BLE notification to the central device
Continuously print PA1 state every 1 second on the serial monitor
Here is the code snippet:
APP_DBG_MSG("SW1 OK\n");
uint32_t lastPrint = 0; // Print every 1 second
if ((HAL_GetTick() - lastPrint) >= 1000)
{
lastPrint = HAL_GetTick();
uint8_t state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1);
APP_DBG_MSG("PA1 State = %d\n", state);
}
while (1) { // Needed for BLE MX_APPE_Process(); }The output I get is:
aci_gap_configure_filter_accept_and_resolving_list command
==>> End BLE_Init function
Services and Characteristics creation
Success: aci_gatt_srv_add_service command:
RC_LR_Periph
End of Services and Characteristics creation
Success: aci_hal_set_radio_activity_mask command
==>> Success: aci_gap_set_advertising_configuration
==>> Success: aci_gap_set_advertising_data
==>> Success: aci_gap_set_advertising_enable
SW1 OKAfter that, I never see “PA1 State = …”.
No further serial output.
I tried placing the print inside the while loop and outside the loop, but still no data in the serial monitor.
Why APP_DBG_MSG prints only once?
Where is the correct place to add periodic debug logs in the BLE WB05 project?
Do I need to enable any UART / trace settings for continuous debug output?
Is MX_APPE_Process() blocking the CPU?
Any suggestions or example code would be appreciated.
Thank you!
Edited to apply source code formatting - please see How to insert source code for future reference.
See also posting preformatted text other than source code.
Solved! Go to Solution.
2025-12-09 3:14 AM
Hello @pradeepaan
The code does not enter the if condition, which is why the pin state is not printed.
2025-12-08 4:18 AM - last edited on 2025-12-08 4:32 AM by Andrew Neil
my code
output
2025-12-09 3:14 AM
Hello @pradeepaan
The code does not enter the if condition, which is why the pin state is not printed.
2025-12-10 8:14 PM
Hello @Saket_Om
Thanks for the response.
I understand why the if() is not entering, but my question is:
How can I run this function (LED toggle logic) without using while() or if() inside the main loop?
I want the LED toggle to work automatically when the button callback sets led_toggle_active = 1, but the BLE example uses:
Since everything must run inside the BLE scheduler, I am not sure what is the correct method to schedule or run my LED toggle function without adding blocking code or polling inside the while(1) loop.
Should this be implemented using:
UTIL_SEQ_SetTask() or
a timer callback
or some other recommended method?
Please advise on the proper way to execute such logic in STM32WB without adding if() checks inside the main loop.
Thank you!
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.