cancel
Showing results for 
Search instead for 
Did you mean: 

Integrated new Bluetooth BLE code, into an existing old project based on IAR5.4 ?

Micha Valach
Associate III
Posted on December 29, 2016 at 07:30

Hello,

I'm newbie in the Bluetooth business, I purchased theSTM32L476RG Nucleo+Nucleo BLE expensionboard (X-Nucleo-IDB05A1withSPBTLE-RF module) .

Then I installed the

IAR 7.5 workbench

,copy the

X-Cube-BLE1directories including the samples code - and everything

works like a charm !!!

As we would like to enhance ourexisting old project (based onSTM32F101CBT6andIAR5.4 workbench) with new Bluetooth BLE capabilities,

Please advise,if the samples code from the new Bluetooth BLE project (X-Cube-BLE1) can be integrated into existing old project which use the following environment, based on

STM32F101CBT6

and

IAR5.4 workbench

)?

If NO, please advise,how can we overcome this obstacle.

Thanks In Advance,

Micha Valach

#st-bluetooth

Note: this post was migrated and contained many threaded conversations, some content may be missing.
11 REPLIES 11
Antonio Vilei
Senior III
Posted on January 17, 2017 at 15:25

Dear

Micha Valach,

from the version of IAR that you are using, I assume that your old project is based on the old Standard Peripheral Libraries (SPL) and not on the new STM32Cube.

Please notice that the Bluetooth Low Energy (BLE) drivers and examples in the X-CUBE-BLE1 package are based on STM32Cube.

There could be two different ways of adding BLE to your project:

1) move everything to STM32Cube and reuse drivers and examples of X-CUBE-BLE1;

2) use drivers and examples from the STSW-BLUENRG-DK package, which includes support for the old SPL libraries:

http://www.st.com/content/st_com/en/products/embedded-software/evaluation-tool-software/stsw-bluenrg-dk.html

If you're happy with your STM32F1 chip, the second option would probably be the fastest for you. However, if in the future you plan to embrace other series of STM32, you could consider moving to STM32Cube as there is no SPL support for the latest MCUs (L4, L0, and so on).

Hope that helps,

Antonio

Posted on September 21, 2017 at 11:43

Hello

Vilei.Antonio

,

I tested the

X-CUBE-BLE1 on SensiBLE board and also STM32L476RG with expansionX-Nucleo-IDB05A1. It works fine for both the boards and can connect with mobile phone BlueNRG android App.

Now we want to integrate the blueTooth module in custom project where we are using

STM32L476ZETx

. Can you tell me is it possible to use theX-Nucleo-IDB05A1? And if Yes, what is the easiest way? Is there any guid availble to easily poritng the Bluetooth module?

Posted on September 21, 2017 at 16:51

Hi Rashedul Islam,

in your case, as the MCU you have chosen is very similar to the one that you have already tested, I'd suggest to start from that same example in the X-CUBE-BLE1 package, and then configure the correct MCU from the project options of your IDE. As the pins configuration is probably different, you will need to update the Drivers\BSP\STM32L4xx_Nucleo\stm32l4xx_nucleo_bluenrg.h

file according to your case.

in general, if you're starting from scratch with any STM32-based custom board, I think that the easiest path is probably using CubeMX to generate the base code for your target MCU and then add the relevant files for Bluetooth Low Energy (BLE).

Since the BlueNRG-MS chip communicates via SPI

, from CubeMX GUI make sure to enable SPI support and configure the pins according to how the BlueNRG-MS chip (the one inside X-Nucleo-IDB05A1) is actually wired to your board.

You can see which pins you need to define by taking a look at the Drivers\BSP\STM32L4xx_Nucleo\stm32l4xx_nucleo_bluenrg.h file of the X-CUBE-BLE1 package.

You need to copy the stm32_bluenrg_ble.c and stm32_bluenrg_ble.h files from the

Drivers\BSP\X-NUCLEO-IDB0xA1 directory, as they implement the interface between the BlueNRG-MS and the STM32 MCU.

You also need to add the BLE specific files from the

Middlewares\ST\STM32_BlueNRG\SimpleBlueNRG_HCI

directory.

Best regards,

Antonio

Posted on September 22, 2017 at 11:39

Thnx for your reply and it was really helpful to me. I have started with CubeMX project and imported all the Bfiles from the 

X-CUBE-BLE1 related to Bluetooth. It compiles perfectly in Keil Compiler.  But it get fails in the line 

ret = aci_gatt_init();

if(ret){

PRINTF('GATT_Init failed.\n');

}

My custom board have the MCU STM32L476ZETx. 

I am using the values  by defualt i get from the XCUBE-BLE1 

i.e : 

 SERVER_BDADDR[5] = 0x02;

/* Vendor specific commands */

&sharpdefine OGF_VENDOR_CMD 0x3f

As I am newbie I am not sure do I need to change the values?  I am putting the changes I have done

/**

* @brief SPI communication details between Nucleo L4 and BlueNRG

* Expansion Board.

*/

// SPI Instance

&sharpdefine BNRG_SPI_INSTANCE SPI3 //SPI1

&sharpdefine BNRG_SPI_CLK_ENABLE() __SPI3_CLK_ENABLE() //__SPI1_CLK_ENABLE()

// SPI Configuration

&sharpdefine BNRG_SPI_MODE SPI_MODE_MASTER

&sharpdefine BNRG_SPI_DIRECTION SPI_DIRECTION_2LINES

&sharpdefine BNRG_SPI_DATASIZE SPI_DATASIZE_8BIT

&sharpdefine BNRG_SPI_CLKPOLARITY SPI_POLARITY_LOW

&sharpdefine BNRG_SPI_CLKPHASE SPI_PHASE_1EDGE

&sharpdefine BNRG_SPI_NSS SPI_NSS_SOFT

&sharpdefine BNRG_SPI_FIRSTBIT SPI_FIRSTBIT_MSB

&sharpdefine BNRG_SPI_TIMODE SPI_TIMODE_DISABLED

&sharpdefine BNRG_SPI_CRCPOLYNOMIAL 7

&sharpdefine BNRG_SPI_BAUDRATEPRESCALER SPI_BAUDRATEPRESCALER_4

&sharpdefine BNRG_SPI_CRCCALCULATION SPI_CRCCALCULATION_DISABLED

// SPI Reset Pin: PA.8

&sharpdefine BNRG_SPI_RESET_PIN BT_RESET_Pin

&sharpdefine BNRG_SPI_RESET_MODE GPIO_MODE_OUTPUT_PP

&sharpdefine BNRG_SPI_RESET_PULL GPIO_PULLUP

&sharpdefine BNRG_SPI_RESET_SPEED GPIO_SPEED_LOW

&sharpdefine BNRG_SPI_RESET_ALTERNATE 0

&sharpdefine BNRG_SPI_RESET_PORT GPIOA

&sharpdefine BNRG_SPI_RESET_CLK_ENABLE() __GPIOA_CLK_ENABLE()

// SCLK: PB.3

&sharpdefine BNRG_SPI_SCLK_PIN GPIO_PIN_10 //GPIO_PIN_3

&sharpdefine BNRG_SPI_SCLK_MODE GPIO_MODE_AF_PP

&sharpdefine BNRG_SPI_SCLK_PULL GPIO_PULLDOWN

&sharpdefine BNRG_SPI_SCLK_SPEED GPIO_SPEED_HIGH

&sharpdefine BNRG_SPI_SCLK_ALTERNATE GPIO_AF6_SPI3 //GPIO_AF5_SPI1

&sharpdefine BNRG_SPI_SCLK_PORT GPIOC //GPIOB

&sharpdefine BNRG_SPI_SCLK_CLK_ENABLE() __GPIOC_CLK_ENABLE() //__GPIOB_CLK_ENABLE()

// MISO (Master Input Slave Output): PA.6

&sharpdefine BNRG_SPI_MISO_PIN GPIO_PIN_11 //GPIO_PIN_6

&sharpdefine BNRG_SPI_MISO_MODE GPIO_MODE_AF_PP

&sharpdefine BNRG_SPI_MISO_PULL GPIO_PULLUP

&sharpdefine BNRG_SPI_MISO_SPEED GPIO_SPEED_HIGH

&sharpdefine BNRG_SPI_MISO_ALTERNATE GPIO_AF6_SPI3 //GPIO_AF5_SPI1

&sharpdefine BNRG_SPI_MISO_PORT GPIOC //GPIOA

&sharpdefine BNRG_SPI_MISO_CLK_ENABLE() __GPIOC_CLK_ENABLE() //__GPIOA_CLK_ENABLE()

// MOSI (Master Output Slave Input): PA.7

&sharpdefine BNRG_SPI_MOSI_PIN GPIO_PIN_12 //GPIO_PIN_7

&sharpdefine BNRG_SPI_MOSI_MODE GPIO_MODE_AF_PP

&sharpdefine BNRG_SPI_MOSI_PULL GPIO_NOPULL

&sharpdefine BNRG_SPI_MOSI_SPEED GPIO_SPEED_HIGH

&sharpdefine BNRG_SPI_MOSI_ALTERNATE GPIO_AF6_SPI3 //GPIO_AF5_SPI1

&sharpdefine BNRG_SPI_MOSI_PORT GPIOC //GPIOA

&sharpdefine BNRG_SPI_MOSI_CLK_ENABLE() __GPIOC_CLK_ENABLE() //__GPIOA_CLK_ENABLE()

// NSS/CSN/CS: PA.1

&sharpdefine BNRG_SPI_CS_PIN GPIO_PIN_4 //GPIO_PIN_1

&sharpdefine BNRG_SPI_CS_MODE GPIO_MODE_OUTPUT_PP

&sharpdefine BNRG_SPI_CS_PULL GPIO_PULLUP

&sharpdefine BNRG_SPI_CS_SPEED GPIO_SPEED_HIGH

&sharpdefine BNRG_SPI_CS_ALTERNATE 0

&sharpdefine BNRG_SPI_CS_PORT GPIOA

&sharpdefine BNRG_SPI_CS_CLK_ENABLE() __GPIOA_CLK_ENABLE()

// IRQ: PA.0

&sharpdefine BNRG_SPI_IRQ_PIN GPIO_PIN_1 //GPIO_PIN_0

&sharpdefine BNRG_SPI_IRQ_MODE GPIO_MODE_IT_RISING

&sharpdefine BNRG_SPI_IRQ_PULL GPIO_NOPULL

&sharpdefine BNRG_SPI_IRQ_SPEED GPIO_SPEED_HIGH

&sharpdefine BNRG_SPI_IRQ_ALTERNATE 0

&sharpdefine BNRG_SPI_IRQ_PORT GPIOE //GPIOA

&sharpdefine BNRG_SPI_IRQ_CLK_ENABLE() __GPIOE_CLK_ENABLE() //__GPIOA_CLK_ENABLE()

// EXTI External Interrupt for SPI

// NOTE: if you change the IRQ pin remember to implement a corresponding handler

// function like EXTI0_IRQHandler() in the user project

&sharpdefine BNRG_SPI_EXTI_IRQn EXTI0_IRQn

&sharpdefine BNRG_SPI_EXTI_IRQHandler EXTI0_IRQHandler

&sharpdefine BNRG_SPI_EXTI_PIN BNRG_SPI_IRQ_PIN

&sharpdefine BNRG_SPI_EXTI_PORT BNRG_SPI_IRQ_PORT

&sharpdefine RTC_WAKEUP_IRQHandler RTC_WKUP_IRQHandler

&sharpdefine BNRG_SPI_FORCE_RESET() __SPI1_FORCE_RESET()

&sharpdefine BNRG_SPI_RELEASE_RESET() __SPI1_RELEASE_RESET()

//&sharpdefine BNRG_DMA_CLK_ENABLE() __DMA1_CLK_ENABLE()

/* Definition for SPIx's DMA */

//&sharpdefine BNRG_SPI_TX_DMA_CHANNEL DMA1_Channel3

//&sharpdefine BNRG_SPI_TX_DMA_REQUEST DMA_REQUEST_1

//&sharpdefine BNRG_SPI_TX_DMA_TC_FLAG DMA_FLAG_TC3

//&sharpdefine BNRG_SPI_RX_DMA_CHANNEL DMA1_Channel2

//&sharpdefine BNRG_SPI_RX_DMA_REQUEST DMA_REQUEST_1

//&sharpdefine BNRG_SPI_RX_DMA_TC_FLAG DMA_FLAG_TC2

/* Definition for SPIx's NVIC */

//&sharpdefine BNRG_SPI_DMA_TX_IRQn DMA1_Channel3_IRQn

//&sharpdefine BNRG_SPI_DMA_RX_IRQn DMA1_Channel2_IRQn

//EXTI External Interrupt for user button

&sharpdefine PUSH_BUTTON_EXTI_IRQHandler EXTI15_10_IRQHandler

/**

Posted on September 22, 2017 at 17:33

Current status:

In the debug mode I checked it always returning TIMEOUT statut status for the below code snap:

  

tBleStatus

aci_gatt_init

(void)

{

struct hci_request rq;

uint8_t status;

Osal_MemSet(&rq, 0, sizeof(rq));

rq.ogf = OGF_VENDOR_CMD;

rq.ocf = OCF_GATT_INIT;

rq.rparam = &status;

rq.rlen = 1;

if (hci_send_req(&rq, FALSE) < 0)

return BLE_STATUS_TIMEOUT;

return status;

}
Posted on September 25, 2017 at 11:32

in your case, TIMEOUT means that the SPI communication is not working properly.

Please notice that the values that you changed in that file can be set by using CubeMX GUI, so you need to make sure that you are not defining twice the same thing. For example, CubeMX takes care of the SPI3 initialization by itself, so you don't need to specify the SPI parameters again with those &sharpdefine directives. I mentioned the stm32l4xx_nucleo_bluenrg.h file as a reference to see which pins are actually needed by the BlueNRG-MS chip (to give an idea of what needs to be adapted based on the wiring of your board).

If you want to, you may try the other approach that I proposed in my previous post, i.e. trying to adapt an existing project for NUCLEO-L476RG in the X-CUBE-BLE1 package. In this case, you could modify use the

Drivers\BSP\STM32L4xx_Nucleo\stm32l4xx_nucleo_bluenrg.h file

as you have already done in you previous post.

In both cases, if you have a scope, you could try to see what's actually happening and check that everything looks like specified in section &sharp3 'SPI interface' of

http://www.st.com/content/ccc/resource/technical/document/application_note/46/0a/77/7b/04/f5/4c/b7/DM00116738.pdf/files/DM00116738.pdf/jcr:content/translations/en.DM00116738.pdf

 document 'Bringing up the BlueNRG and BlueNRG-MS devices'.
Posted on September 25, 2017 at 14:12

Hello Thank you once again for your valuable comments. Actually I have tried in both way. The one where I am getting the timeout, is the one I started with CuveMX. So spi3 pin configuration is handled already. I just imported the BlueNRG files from the example project to my project. It also not getting success staus for the following method: 

uint8_t getBlueNRGVersion(uint8_t *hwVersion, uint16_t *fwVersion)

{

uint8_t status;

uint8_t hci_version, lmp_pal_version;

uint16_t hci_revision, manufacturer_name, lmp_pal_subversion;

status = hci_le_read_local_version(&hci_version, &hci_revision, &lmp_pal_version,

&manufacturer_name, &lmp_pal_subversion);

if (status == BLE_STATUS_SUCCESS) {

*hwVersion = hci_revision >> 8;

*fwVersion = (hci_revision & 0xFF) << 8; // Major Version Number

*fwVersion |= ((lmp_pal_subversion >> 4) & 0xF) << 4; // Minor Version Number

*fwVersion |= lmp_pal_subversion & 0xF; // Patch Version Number

}

HCI_Process(); // To receive the BlueNRG EVT

return status;

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I am pretty purplexed at this stage now. Dont know how to find my fault.

Posted on September 26, 2017 at 17:04

What board are you using?

Did you design it yourself or is it commercially available?

If you have the schematics, I can take a lookto check if the code is configured according to the wiring of the BlueNRG-MS chip.

Antonio Vilei
Senior III
Posted on September 29, 2017 at 16:05

You're welcome!