Skip to content

Commit 136f49a

Browse files
authored
Merge pull request #8 from xoviat/build
add ble
2 parents 6d9597a + 2bceba4 commit 136f49a

File tree

6 files changed

+243
-11
lines changed

6 files changed

+243
-11
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//"rust-analyzer.cargo.target": "thumbv7m-none-eabi",
1818
// "rust-analyzer.cargo.target": "thumbv7em-none-eabi",
1919
//"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
20-
// "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
20+
"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
2121
"rust-analyzer.cargo.features": [],
2222
"rust-analyzer.linkedProjects": [
2323
"stm32-bindings-gen/Cargo.toml",
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#define __PACKED_STRUCT struct __attribute__((packed))
2+
#define __PACKED_UNION union __attribute__((packed))
3+
#define __STATIC_INLINE static
4+
#define __ALIGNED(x) __attribute__((aligned(x)))
5+
6+
/* USER CODE BEGIN Header */
7+
/**
8+
******************************************************************************
9+
* @file app_ble.h
10+
* @author MCD Application Team
11+
* @brief Header for ble application
12+
******************************************************************************
13+
* @attention
14+
*
15+
* Copyright (c) 2022 STMicroelectronics.
16+
* All rights reserved.
17+
*
18+
* This software is licensed under terms that can be found in the LICENSE file
19+
* in the root directory of this software component.
20+
* If no LICENSE file comes with this software, it is provided AS-IS.
21+
*
22+
******************************************************************************
23+
*/
24+
/* USER CODE END Header */
25+
26+
/* Define to prevent recursive inclusion -------------------------------------*/
27+
#ifndef APP_BLE_H
28+
#define APP_BLE_H
29+
30+
#ifdef __cplusplus
31+
extern "C"
32+
{
33+
#endif
34+
35+
/* Includes ------------------------------------------------------------------*/
36+
37+
/* Private includes ----------------------------------------------------------*/
38+
#include "ble_types.h"
39+
/* USER CODE BEGIN Includes */
40+
41+
/* USER CODE END Includes */
42+
43+
/* Exported types ------------------------------------------------------------*/
44+
45+
typedef enum
46+
{
47+
APP_BLE_IDLE,
48+
APP_BLE_LP_CONNECTING,
49+
APP_BLE_CONNECTED_SERVER,
50+
APP_BLE_CONNECTED_CLIENT,
51+
APP_BLE_ADV_FAST,
52+
APP_BLE_ADV_LP,
53+
APP_BLE_ADV_NON_CONN_FAST,
54+
APP_BLE_ADV_NON_CONN_LP,
55+
/* USER CODE BEGIN APP_BLE_ConnStatus_t */
56+
57+
/* USER CODE END APP_BLE_ConnStatus_t */
58+
} APP_BLE_ConnStatus_t;
59+
60+
/**
61+
* HCI Event Packet Types
62+
*/
63+
typedef __PACKED_STRUCT
64+
{
65+
uint32_t *next;
66+
uint32_t *prev;
67+
}
68+
BleEvtPacketHeader_t;
69+
70+
typedef __PACKED_STRUCT
71+
{
72+
uint8_t evtcode;
73+
uint8_t plen;
74+
uint8_t payload[1];
75+
}
76+
BleEvt_t;
77+
78+
typedef __PACKED_STRUCT
79+
{
80+
uint8_t type;
81+
BleEvt_t evt;
82+
}
83+
BleEvtSerial_t;
84+
85+
typedef __PACKED_STRUCT __ALIGNED(4)
86+
{
87+
BleEvtPacketHeader_t header;
88+
BleEvtSerial_t evtserial;
89+
}
90+
BleEvtPacket_t;
91+
92+
typedef enum
93+
{
94+
PROC_GAP_GEN_PHY_TOGGLE,
95+
PROC_GAP_GEN_CONN_TERMINATE,
96+
PROC_GATT_EXCHANGE_CONFIG,
97+
/* USER CODE BEGIN ProcGapGeneralId_t */
98+
99+
/* USER CODE END ProcGapGeneralId_t */
100+
} ProcGapGeneralId_t;
101+
102+
typedef enum
103+
{
104+
PROC_GAP_PERIPH_ADVERTISE_START_LP,
105+
PROC_GAP_PERIPH_ADVERTISE_START_FAST,
106+
PROC_GAP_PERIPH_ADVERTISE_NON_CONN_START_LP,
107+
PROC_GAP_PERIPH_ADVERTISE_NON_CONN_START_FAST,
108+
PROC_GAP_PERIPH_ADVERTISE_STOP,
109+
PROC_GAP_PERIPH_ADVERTISE_DATA_UPDATE,
110+
PROC_GAP_PERIPH_CONN_PARAM_UPDATE,
111+
/* USER CODE BEGIN ProcGapPeripheralId_t */
112+
113+
/* USER CODE END ProcGapPeripheralId_t */
114+
} ProcGapPeripheralId_t;
115+
116+
typedef enum
117+
{
118+
PROC_GAP_CENTRAL_SCAN_START,
119+
PROC_GAP_CENTRAL_SCAN_TERMINATE,
120+
/* USER CODE BEGIN ProcGapCentralId_t */
121+
122+
/* USER CODE END ProcGapCentralId_t */
123+
} ProcGapCentralId_t;
124+
125+
/* USER CODE BEGIN ET */
126+
127+
/* USER CODE END ET */
128+
129+
/* Exported constants --------------------------------------------------------*/
130+
/* USER CODE BEGIN EC */
131+
/* ST Manufacturer ID */
132+
#define ST_MANUF_ID 0x30
133+
134+
/* BlueSTSDK Version */
135+
enum
136+
{
137+
BLUESTSDK_V1 = 0x01,
138+
BLUESTSDK_V2 = 0x02
139+
};
140+
141+
/* BOARD ID */
142+
enum
143+
{
144+
BOARD_ID_NUCLEO_WBA5X = 0x8B,
145+
BOARD_ID_DK_WBA5X = 0x91,
146+
BOARD_ID_B_WBA5M_WPAN = 0x8D,
147+
BOARD_ID_NUCLEO_WBA6X = 0x8E,
148+
BOARD_ID_DK_WBA6X = 0x92,
149+
BOARD_ID_B_WBA6M_WPAN = 0x93
150+
};
151+
152+
/* FIRMWARE ID */
153+
enum
154+
{
155+
FW_ID_P2P_SERVER = 0x83,
156+
FW_ID_P2P_ROUTER = 0x85,
157+
FW_ID_DT_SERVER = 0x88,
158+
FW_ID_COC_PERIPH = 0x87,
159+
FW_ID_HEART_RATE = 0x89,
160+
FW_ID_HEALTH_THERMO = 0x8A,
161+
FW_ID_HID = 0x8B,
162+
FW_ID_SENSOR = 0x9C,
163+
FW_ID_GENERIC_HEALTH_SENSOR = 0x9D
164+
};
165+
166+
/* USER CODE END EC */
167+
168+
/* External variables --------------------------------------------------------*/
169+
/* USER CODE BEGIN EV */
170+
171+
/* USER CODE END EV */
172+
173+
/* Exported macro ------------------------------------------------------------*/
174+
#define ADV_INT_MS(x) ((uint16_t)((x) / 0.625f))
175+
#define SCAN_WIN_MS(x) ((uint16_t)((x) / 0.625f))
176+
#define SCAN_INT_MS(x) ((uint16_t)((x) / 0.625f))
177+
#define CONN_INT_MS(x) ((uint16_t)((x) / 1.25f))
178+
#define CONN_SUP_TIMEOUT_MS(x) ((uint16_t)((x) / 10.0f))
179+
#define CONN_CE_LENGTH_MS(x) ((uint16_t)((x) / 0.625f))
180+
181+
#define HCI_LE_ADVERTISING_REPORT_RSSI(p) \
182+
(*(int8_t *)((&((hci_le_advertising_report_event_rp0 *)(p))->Advertising_Report[0].Length_Data) + 1 + \
183+
((hci_le_advertising_report_event_rp0 *)(p))->Advertising_Report[0].Length_Data))
184+
/* USER CODE BEGIN EM */
185+
186+
/* USER CODE END EM */
187+
188+
/* Exported functions prototypes ---------------------------------------------*/
189+
void APP_BLE_Init(void);
190+
void BleStack_Process_BG(void);
191+
APP_BLE_ConnStatus_t APP_BLE_Get_Server_Connection_Status(void);
192+
void APP_BLE_Procedure_Gap_General(ProcGapGeneralId_t ProcGapGeneralId);
193+
void APP_BLE_Procedure_Gap_Peripheral(ProcGapPeripheralId_t ProcGapPeripheralId);
194+
const uint8_t *BleGetBdAddress(void);
195+
tBleStatus SetGapAppearance(uint16_t appearance);
196+
tBleStatus SetGapDeviceName(uint8_t *devicename, uint8_t devicename_len);
197+
void Ble_UserEvtRx(void);
198+
void APP_BLE_HostNvmStore(void);
199+
/* USER CODE BEGIN EFP */
200+
201+
/* USER CODE END EFP */
202+
203+
#ifdef __cplusplus
204+
}
205+
#endif
206+
207+
#endif /*APP_BLE_H */
208+
209+
#include "ble_core.h"
210+
#include "blestack.h"

stm32-bindings-gen/res/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ cortex-m-rt = { version = ">=0.6.15,<0.8", optional = true }
5151
defmt = { version = "0.3.0", optional = true }
5252

5353
[features]
54-
default = ["pac"]
54+
default = ["pac", "wba_wpan_mac", "wba_wpan_ble"]
5555

5656
wba_wpan_mac = []
5757
wba_wpan_ble = []
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#[cfg(feature = "wba_wpan_ble")]
2+
mod wba_wpan_ble;
13
#[cfg(feature = "wba_wpan_mac")]
24
mod wba_wpan_mac;

stm32-bindings-gen/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bindgen::callbacks::{ItemInfo, ItemKind, ParseCallbacks};
22
use std::io::Write;
33
use std::{fs, path::PathBuf};
4-
use tempfile::NamedTempFile;
4+
use tempfile::{NamedTempFile, TempDir};
55

66
#[derive(Debug)]
77
struct UppercaseCallbacks;
@@ -45,6 +45,10 @@ impl Gen {
4545
fs::create_dir_all(self.opts.out_dir.join("src/bindings")).unwrap();
4646
fs::create_dir_all(self.opts.out_dir.join("src/lib")).unwrap();
4747

48+
let tmpdir = TempDir::new().unwrap();
49+
fs::write(tmpdir.path().join("string.h"), "").unwrap();
50+
// fs::write(tmpdir.path().join("stdint.h"), "").unwrap();
51+
4852
for lib in &self.libs {
4953
let sources_dir = self.opts.sources_dir.join(&lib.sources_dir);
5054

@@ -71,6 +75,8 @@ impl Gen {
7175
));
7276
}
7377

78+
builder = builder.clang_arg(&format!("-I{}", tmpdir.path().to_str().unwrap()));
79+
7480
if lib.target_triple.to_ascii_lowercase().starts_with("thumb") {
7581
builder = builder.clang_arg("-mthumb");
7682
}
@@ -96,6 +102,7 @@ impl Gen {
96102

97103
let mut file_contents = fs::read_to_string(&out_path).unwrap();
98104
file_contents = file_contents
105+
.replace(":: std :: mem ::", ":: core :: mem ::")
99106
.replace("::std::mem::", "::core::mem::")
100107
.replace("::std::os::raw::", "::core::ffi::")
101108
.replace("::std::option::", "::core::option::");

stm32-bindings-gen/src/main.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@ fn main() {
1111
sources_dir,
1212
};
1313

14-
let libs = Vec::from([Library {
15-
target_triple: String::from("thumbv8m.main-none-eabihf"),
16-
sources_dir: "STM32CubeWBA".into(),
17-
header: include_bytes!("../inc/wba_wpan_mac.h"),
18-
module: "wba_wpan_mac",
19-
includes: Vec::from(["Middlewares/ST/STM32_WPAN/mac_802_15_4/core/inc".into()]),
20-
library: "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib/wba_mac_lib.a".into(),
21-
}]);
14+
let libs = Vec::from([
15+
Library {
16+
target_triple: String::from("thumbv8m.main-none-eabihf"),
17+
sources_dir: "STM32CubeWBA".into(),
18+
header: include_bytes!("../inc/wba_wpan_mac.h"),
19+
module: "wba_wpan_mac",
20+
includes: Vec::from(["Middlewares/ST/STM32_WPAN/mac_802_15_4/core/inc".into()]),
21+
library: "Middlewares/ST/STM32_WPAN/mac_802_15_4/lib/wba_mac_lib.a".into(),
22+
},
23+
Library {
24+
target_triple: String::from("thumbv8m.main-none-eabihf"),
25+
sources_dir: "STM32CubeWBA".into(),
26+
header: include_bytes!("../inc/wba_wpan_ble.h"),
27+
module: "wba_wpan_ble",
28+
includes: Vec::from([
29+
"Middlewares/ST/STM32_WPAN/ble/stack/include".into(),
30+
"Middlewares/ST/STM32_WPAN/ble/stack/include/auto".into(),
31+
]),
32+
library: "Middlewares/ST/STM32_WPAN/ble/stack/lib/stm32wba_ble_stack_full.a".into(),
33+
},
34+
]);
2235

2336
Gen::new(opts, libs).run_gen();
2437
}

0 commit comments

Comments
 (0)