This document outlines the software architecture of the WB09_Blinky project, highlighting the core functions responsible for system initialization, BLE management, and application logic.
The Core/ directory contains the main entry point and hardware configuration.
main(): The absolute entry point.- Initializes the HAL (Hardware Abstraction Layer).
- Configures the System Clock (
SystemClock_Config). - Initializes peripherals (GPIO, UART, etc.).
- Calls
MX_APPE_Initto start the BLE application. - Enters the main infinite loop calling
MX_APPE_Process.
MX_APPE_Init(): Initializes the Application Environment.- Sets up the Random Number Generator (
HW_RNG_Init) and Security (HW_AES_Init,HW_PKA_Init). - Calls
APP_BLE_Init()to start the BLE stack. - Initializes Low Power Manager (
UTIL_LPM_Init). - Initializes Buttons (
Button_Init) and UART for debug/control (RxUART_Init).
- Sets up the Random Number Generator (
MX_APPE_Process(): The main background task runner.- Calls
UTIL_SEQ_Run()which executes scheduled tasks (fromstm32_seq.c).
- Calls
APPE_ButtonXAction(): Weak functions called when buttons are pressed, intended to be overridden or used to trigger sequencer tasks.
The STM32_BLE/ directory handles the Bluetooth Low Energy stack and custom services.
APP_BLE_Init(): Initializes the BLE Stack.- Calls
BleStack_Init(). - Configures the device address (Public or Static Random).
- Calls
P2P_SERVER_APP_Init()to start the custom service. - Starts Advertising (
Adv_Request).
- Calls
BLEEVT_App_Notification(): Global BLE Event Handler.- Receives events from the stack (Connection Complete, Disconnection, etc.).
- Manages Advertising state (restarting on disconnection).
This file implements the logic for the P2P Server (Peer-to-Peer) custom service.
P2P_SERVER_APP_Init(): Registers the P2P service tasks.- Registers
P2P_SERVER_Switch_c_SendNotificationtask to send button press updates.
- Registers
P2P_SERVER_Notification(): Handles events specific to the P2P Service.P2P_SERVER_LED_C_WRITE_NO_RESP_EVT: Called when a client writes to the LED Characteristic.- Turns the Blue LED ON (
0x01) or OFF (0x00).
- Turns the Blue LED ON (
P2P_SERVER_SWITCH_C_NOTIFY_ENABLED_EVT: Called when a client subscribes to Button notifications.
P2P_SERVER_Switch_c_SendNotification():- Updates the Button Characteristic value.
- Sends a notification to the connected client if subscribed.
This file defines the GATT Service and Characteristics (UUIDs, Properties).
P2P_SERVER_Init():- Adds the P2P Service (
0000FE40-CC7A-482A-984A-7F2ED5B3E58F) to the GATT database. - Adds LED Characteristic (Write w/o Response).
- Adds Button Characteristic (Notify).
- Adds the P2P Service (
P2P_SERVER_NotifyValue(): Helper to send notifications to the stack.
- System Start:
main()->MX_APPE_Init()->APP_BLE_Init()->P2P_SERVER_Init(). - Advertising:
APP_BLE_Init()starts advertising. The device becomes visible as "STM32". - Connection: When a client connects,
BLEEVT_App_NotificationhandlesHCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE. - LED Control:
- Client writes to LED Characteristic.
- Stack ->
P2P_SERVER_Notification()->P2P_SERVER_LED_C_WRITE_NO_RESP_EVT->BSP_LED_On/Off.
- Button Press:
- User presses Button 1.
- Interrupt ->
BSP_PB_Callback->Button_TriggerActions. UTIL_SEQ_SetTask(TASK_BUTTON_1)schedules the task.APPE_Button1Action(inapp_entry.c) callsP2P_SERVER_Switch_c_SendNotification.P2P_SERVER_Switch_c_SendNotificationsends the new value to the client.