Skip to main content
Graduate
December 8, 2025
Solved

Cannot Read PA1 Button State or Print Debug Logs in STM32WB05KZ BLE RC Peripheral Project

  • December 8, 2025
  • 2 replies
  • 148 views

 

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 OK

After 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.


Does anyone know:

  1. Why APP_DBG_MSG prints only once?

  2. Where is the correct place to add periodic debug logs in the BLE WB05 project?

  3. Do I need to enable any UART / trace settings for continuous debug output?

  4. 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.

    This topic has been closed for replies.
    Best answer by Saket_Om

    Hello @pradeepaan 

    The code does not enter the if condition, which is why the pin state is not printed.

    2 replies

    Graduate
    December 8, 2025

    my code

    pradeepaan_0-1765196226136.png

    output

    pradeepaan_1-1765196268593.png

    Saket_OmAnswer
    Technical Moderator
    December 9, 2025

    Hello @pradeepaan 

    The code does not enter the if condition, which is why the pin state is not printed.

    Graduate
    December 11, 2025

    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:

    pradeepaan_0-1765426418152.png

    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!