Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: stm32wb0: Add BLE controller implementation #236

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 3 additions & 65 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_HAS_STM32LIB)
if(CONFIG_BT_STM32_IPM)
zephyr_include_directories(stm32wb/hci)

zephyr_sources(stm32wb/hci/hw_ipcc.c)
zephyr_sources(stm32wb/hci/shci.c)
zephyr_sources(stm32wb/hci/shci_tl.c)
zephyr_sources(stm32wb/hci/shci_tl_if.c)
zephyr_sources(stm32wb/hci/stm_list.c)
zephyr_sources(stm32wb/hci/tl_mbox.c)

endif()

if(CONFIG_BT_STM32WBA)

if(DEFINED CONFIG_BOARD_NUCLEO_WBA52CG)
message(FATAL_ERROR "BLE library is not compatible with nucleo_wba52cg")
endif()

zephyr_compile_definitions( -DBLE )

zephyr_include_directories(stm32wba/hci)
zephyr_include_directories(stm32wba/hci/ll)

zephyr_sources(stm32wba/hci/ll_sys_cs.c)
zephyr_sources(stm32wba/hci/ll_sys_intf.c)
zephyr_sources(stm32wba/hci/ll_sys_dp_slp.c)
zephyr_sources(stm32wba/hci/ll_sys_startup.c)
zephyr_sources(stm32wba/hci/RTDebug.c)
zephyr_sources(stm32wba/hci/hw_pka.c)
zephyr_sources(stm32wba/hci/pka_p256.c)
zephyr_sources(stm32wba/hci/bpka.c)
zephyr_sources(stm32wba/hci/power_table.c)
zephyr_sources(stm32wba/hci/scm.c)
zephyr_sources(stm32wba/hci/log_module.c)
if(CONFIG_FLASH)
zephyr_sources(stm32wba/hci/flash_manager.c)
zephyr_sources(stm32wba/hci/flash_driver.c)
zephyr_sources(stm32wba/hci/stm_list.c)
zephyr_sources(stm32wba/hci/rf_timing_synchro.c)
endif()

set(STM32WBA_BLE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../zephyr/blobs/stm32wba/lib)
set(STM32WBA_BLE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/stm32wba/hci)

add_library(stm32wba_ble_lib STATIC IMPORTED GLOBAL)
add_library(stm32wba_ll_lib STATIC IMPORTED GLOBAL)

add_dependencies(
stm32wba_ble_lib
stm32wba_ll_lib
)
set_target_properties(
stm32wba_ble_lib PROPERTIES IMPORTED_LOCATION ${STM32WBA_BLE_LIB_DIR}/stm32wba_ble_stack_llo.a
)
set_target_properties(
stm32wba_ll_lib PROPERTIES IMPORTED_LOCATION ${STM32WBA_BLE_LIB_DIR}/LinkLayer_BLE_Full_lib.a
)

set_target_properties(stm32wba_ble_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${STM32WBA_BLE_INCLUDE_DIR})
set_target_properties(stm32wba_ll_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${STM32WBA_BLE_INCLUDE_DIR})

target_link_libraries(app PUBLIC stm32wba_ble_lib)
target_link_libraries(app PUBLIC stm32wba_ll_lib)

endif()
add_subdirectory_ifdef(CONFIG_BT_STM32_IPM stm32wb)
add_subdirectory_ifdef(CONFIG_BT_STM32WBA stm32wba)
add_subdirectory_ifdef(CONFIG_BT_STM32WB0 stm32wb0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but we need consistency across vraious libs.
Hence I'd expect the same to be done fro WBA and WB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get this comment well. Should I do something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're adding a sub section to handle WB0 case, which is indeed a good idea.
But in that case, for consistency, it would be nice to do the same on other series (in a dedicated commit).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

endif()
12 changes: 12 additions & 0 deletions lib/stm32wb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2024 STMicroelectronics
#
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(hci)

zephyr_sources(hci/hw_ipcc.c)
zephyr_sources(hci/shci.c)
zephyr_sources(hci/shci_tl.c)
zephyr_sources(hci/shci_tl_if.c)
zephyr_sources(hci/stm_list.c)
zephyr_sources(hci/tl_mbox.c)
130 changes: 130 additions & 0 deletions lib/stm32wb0/BLE_TransparentMode/Core/Inc/app_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file app_common.h
* @author MCD Application Team
* @brief App Common application configuration file for STM32WPAN Middleware.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef APP_COMMON_H
#define APP_COMMON_H

#ifdef __cplusplus
extern "C"{
#endif

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include "app_conf.h"

/* -------------------------------- *
* Basic definitions *
* -------------------------------- */
#undef NULL
#define NULL 0

#undef FALSE
#define FALSE 0

#undef TRUE
#define TRUE (!0)

/* -------------------------------- *
* Critical Section definition *
* -------------------------------- */
#define ATOMIC_SECTION_BEGIN() uint32_t uwPRIMASK_Bit = __get_PRIMASK(); \
__disable_irq();
/* Must be called in the same or in a lower scope of ATOMIC_SECTION_BEGIN */
#define ATOMIC_SECTION_END() __set_PRIMASK(uwPRIMASK_Bit)

/* -------------------------------- *
* Macro delimiters *
* -------------------------------- */
#define M_BEGIN do {

#define M_END } while(0)

/* -------------------------------- *
* Some useful macro definitions *
* -------------------------------- */
#ifndef MAX
#define MAX( x, y ) (((x)>(y))?(x):(y))
#endif

#ifndef MIN
#define MIN( x, y ) (((x)<(y))?(x):(y))
#endif

#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END

#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END

#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END

#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m )

#define PAUSE( t ) M_BEGIN \
__IO int _i; \
for ( _i = t; _i > 0; _i -- ); \
M_END

#define DIVF( x, y ) ((x)/(y))

#define DIVC( x, y ) (((x)+(y)-1)/(y))

#define DIVR( x, y ) (((x)+((y)/2))/(y))

#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1)

#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1)

#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END

#define INT(x) ((int)(x))

#define FRACTIONAL_1DIGIT(x) (x>0)? ((int) (((x) - INT(x)) * 10)) : ((int) ((INT(x) - (x)) * 10))

#define FRACTIONAL_2DIGITS(x) (x>0)? ((int) (((x) - INT(x)) * 100)) : ((int) ((INT(x) - (x)) * 100))

#define FRACTIONAL_3DIGITS(x) (x>0)? ((int) (((x) - INT(x)) * 1000)) : ((int) ((INT(x) - (x)) * 1000))

/** @brief Macro that returns a 16-bit value from a buffer where the value is stored in Little Endian Format */
#define LE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t)*((uint8_t *)(ptr))) | \
((uint16_t)*((uint8_t *)(ptr) + 1) << 8) )

/** @brief Macro that stores a 16-bit value into a buffer in Little Endian Format (2 bytes) */
#define HOST_TO_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \
((buf)[1] = (uint8_t) ((val)>>8) ) )

/** @brief Macro that returns a 32-bit value from a buffer where the value is stored in Little Endian Format */
#define LE_TO_HOST_32(ptr) (uint32_t) ( ((uint32_t)*((uint8_t *)(ptr))) | \
((uint32_t)*((uint8_t *)(ptr) + 1) << 8) | \
((uint32_t)*((uint8_t *)(ptr) + 2) << 16) | \
((uint32_t)*((uint8_t *)(ptr) + 3) << 24) )

/* -------------------------------- *
* Compiler *
* -------------------------------- */
#define PLACE_IN_SECTION( __x__ ) __attribute__((used, section (__x__)))

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*APP_COMMON_H */
Loading
Loading