2024-02-01 07:40 AM
Hi,
I am looking for the BLE AT server example created using a recent STM32CubeIDE release (1.14.0+) for the STM32WB5MM module. I can't find it.
The most similar project I found was to open in STM32CubeIDE 1.14.1 the AT server example provided for the P-NUCLEO-WB55.
Nonetheless, there are some inconveniences working with this project:
- The project folder structure is different than the projects created using STM32CubeIDE. Search into file does not take into account the .h files because they are apart from the project structure. I need to search in .h files using other editors' tools.
- There is no CubeMX .ioc file
- The _RAM.ld file is not in the project.
- The _FLASH.ld file is also different from a _FLASH.ld file being created for a new project for STM32WB5MM module.
It would be great to have a brand new project on the following STM32CubeWB package that can be directly opened and modified in current STM32CubeIDE versions.
Modifications I did to adapt the BLE AT server example from P-NUCLEO-WB55 to STM32WB5MM-DK are:
main.h:
/* USER CODE BEGIN Private defines */
// LPUART on STM32WB5MM-DK to interface using AT commands
#define LPUART1_RX_MCU_GPIO_Port GPIOC
#define LPUART1_RX_MCU_Pin GPIO_PIN_0
#define LPUART1_TX_MCU_GPIO_Port GPIOB
#define LPUART1_TX_MCU_Pin GPIO_PIN_5
// UART debug on STM32WB5MM-DK (VCP created over ST-Link USB cable)
#define USART1_GPIO_Port GPIOB
#define USART1_RX_Pin GPIO_PIN_7
#define USART1_TX_Pin GPIO_PIN_6
/* USER CODE END Private defines */
stm32wbxx_hal_msp.c:
/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example
* @PAram huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(huart->Instance==LPUART1)
{
/* USER CODE BEGIN LPUART1_MspInit 0 */
/* USER CODE END LPUART1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_LPUART1_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**LPUART1 GPIO Configuration
PC0 ------> LPUART1_RX
PB5 ------> LPUART1_TX
*/
GPIO_InitStruct.Pin = LPUART1_RX_MCU_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
HAL_GPIO_Init(LPUART1_RX_MCU_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LPUART1_TX_MCU_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
HAL_GPIO_Init(LPUART1_TX_MCU_GPIO_Port, &GPIO_InitStruct);
/* LPUART1 DMA Init */
/* LPUART1_TX Init */
hdma_lpuart1_tx.Instance = DMA1_Channel4;
hdma_lpuart1_tx.Init.Request = DMA_REQUEST_LPUART1_TX;
hdma_lpuart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_lpuart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_lpuart1_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_lpuart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_lpuart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_lpuart1_tx.Init.Mode = DMA_NORMAL;
hdma_lpuart1_tx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_lpuart1_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(huart,hdmatx,hdma_lpuart1_tx);
/* LPUART1 interrupt Init */
HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(LPUART1_IRQn);
/* USER CODE BEGIN LPUART1_MspInit 1 */
/* USER CODE END LPUART1_MspInit 1 */
}
else if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART1 GPIO Configuration
PB7 ------> USART1_RX
PB6 ------> USART1_TX
*/
GPIO_InitStruct.Pin = USART1_RX_Pin|USART1_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(USART1_GPIO_Port, &GPIO_InitStruct);
/* USART1 DMA Init */
/* USART1_TX Init */
hdma_usart1_tx.Instance = DMA2_Channel4;
hdma_usart1_tx.Init.Request = DMA_REQUEST_USART1_TX;
hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart1_tx.Init.Mode = DMA_NORMAL;
hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx);
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
}
}
/**
* @brief UART MSP De-Initialization
* This function freeze the hardware resources used in this example
* @PAram huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==LPUART1)
{
/* USER CODE BEGIN LPUART1_MspDeInit 0 */
/* USER CODE END LPUART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_LPUART1_CLK_DISABLE();
/**LPUART1 GPIO Configuration
PC0 ------> LPUART1_RX
PB5 ------> LPUART1_TX
*/
HAL_GPIO_DeInit(LPUART1_RX_MCU_GPIO_Port, LPUART1_RX_MCU_Pin);
HAL_GPIO_DeInit(LPUART1_TX_MCU_GPIO_Port, LPUART1_TX_MCU_Pin);
/* LPUART1 DMA DeInit */
HAL_DMA_DeInit(huart->hdmatx);
/* LPUART1 interrupt DeInit */
HAL_NVIC_DisableIRQ(LPUART1_IRQn);
/* USER CODE BEGIN LPUART1_MspDeInit 1 */
/* USER CODE END LPUART1_MspDeInit 1 */
}
else if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspDeInit 0 */
/* USER CODE END USART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART1_CLK_DISABLE();
/**USART1 GPIO Configuration
PB7 ------> USART1_RX
PB6 ------> USART1_TX
*/
HAL_GPIO_DeInit(USART1_GPIO_Port, USART1_RX_Pin|USART1_TX_Pin);
/* USART1 DMA DeInit */
HAL_DMA_DeInit(huart->hdmatx);
/* USART1 interrupt DeInit */
HAL_NVIC_DisableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspDeInit 1 */
/* USER CODE END USART1_MspDeInit 1 */
}
}
2024-02-01 09:37 AM
Hello @JMarq.1
Thank you for your contribution on our community and happy to see the work you've done to adapt our example to your need. We always try to make the maximum of examples compatible with CubeMX. Our examples may be tested using a specific board, but they are always easy to convert to other MCUs of the same family.
Thanks again for sharing your changes :smiling_face_with_smiling_eyes:.
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-02-01 11:22 AM
Hello @STTwo-32 ,
Thanks for your answer, but it is by no way easy to mantain the resulting code example. As I said, the resulting project structure once created the example is very different than the structure that STM32CubeIDE creates for a new project, and there is no refrence access to .h files. Code is not found and no .ioc file is created to be able to examine easily using the CubeMX all the example configuration and example documentation.
I do suggest that examples should be updated to recent versions of STM32CubeIDE. I found other examples specifically indicated to be used on the STM32WB5MM-DK (i.e. BLE Transparent mode) that crashes. You open the .ioc of this project on CubeMX to change any value, regenerate the code, and you are not able to build the project any more.
make: *** No rule to make target 'C:/ST/wrk/BLE_TransparentMode/Middlewares/ST/STM32_WPAN/ble/svc/Src/svc_ctl.c', needed by 'Middlewares/STM32_WPAN/svc_ctl.o'. Stop.
make: *** Waiting for unfinished jobs....