Core rules, mapping table, pitfalls, recipes index, and execution workflow are all in
SKILL.md. This file covers only conventions and tooling guidance not present inSKILL.md. Do not duplicate content.
Language: C · Target: WCH CH57x RISC-V BLE SoC(CH573/CH571) · Toolchain: MounRiver Studio (GCC RISC-V)
- Source files:
*.c, headers:*.h - BLE application files:
<role>_main.c(e.g.,peripheral_main.c,central_main.c) - BLE service profiles:
<service_name>.cinProfile/directory - Configuration:
config.hin projectHAL/include/
// Non-BLE projects
#include "CH57x_common.h" // pulls in all peripheral headers
// BLE projects
#include "CONFIG.h"
#include "HAL.h"
#include "CH57xBLE_LIB.h"
#include "peripheral.h" // or central.h, etc.
#include "devinfoservice.h"
#include "gattprofile.h"MyBLEProject/
├── APP/
│ ├── include/
│ │ ├── config.h # BLE stack configuration
│ │ └── peripheral.h # Application header
│ ├── peripheral_main.c # main() and init
│ └── peripheral.c # Application logic, callbacks
├── Profile/
│ ├── include/
│ │ ├── devinfoservice.h
│ │ └── gattprofile.h
│ ├── devinfoservice.c # Device Information Service
│ └── gattprofile.c # Custom GATT profile
├── HAL/ # Linked from resources/EXAM/BLE/HAL/
├── Ld/Link.ld # Linked from resources/EXAM/SRC/Ld/
├── RVMSIS/ # Linked from resources/EXAM/SRC/RVMSIS/
├── Startup/ # Linked from resources/EXAM/SRC/Startup/
├── StdPeriphDriver/ # Linked from resources/EXAM/SRC/StdPeriphDriver/
├── .project # MounRiver Studio project file
└── *.wvproj # MounRiver Studio workspace project
int main(void) {
SetSysClock(CLK_SOURCE_PLL_60MHz);
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
PWR_DCDCCfg(ENABLE);
#endif
#ifdef DEBUG
UART1_DefInit();
PRINT("CH57x BLE init...\n");
#endif
CH57X_BLEInit();
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
Main_Circulation(); // never returns
return 0; // unreachable
}__attribute__((interrupt("WCH-Interrupt-fast")))
__attribute__((section(".highcode")))
void UART1_IRQHandler(void) {
uint8_t flag = UART1_GetITFlag();
if ((flag & UART_II_MASK) == UART_II_RECV_RDY) {
// Handle received data
while (UART1_RecvByte(&data) == SUCCESS) {
// process data
}
}
}#ifdef DEBUG
#define PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define PRINT(fmt, ...)
#endifDebug UART: UART1 at 115200 baud, 8N1. PA8 (RX), PA9 (TX).
- Open
.wvprojin MounRiver Studio - Build: Project → Build Project (or Ctrl+B)
- Flash: Run → Debug (WCH-LinkE) or use WCH ISP tool via USB
- Debug: UART1 serial output at 115200 baud
-
config.hhas correctBLE_MEMHEAP_SIZE,BLE_BUFF_MAX_LEN, connection limits -
CH57X_BLEInit()called with properly filledbleConfig_t - GAP/GATT services added before custom services
- Application callbacks registered after service init
-
Main_Circulation()called at end of main (never returns) - Connection handle stored from
GAP_LINK_ESTABLISHED_EVENT - Advertising data ≤ 31 bytes (
B_MAX_ADV_LEN) - Custom UUIDs are 128-bit for custom services
-
config.hHAL_SLEEPset correctly for power requirements - Interrupt handlers use
.highcodesection
resources/— API documentation sourceSKILL.mdfront matter — Skill metadata