cancel
Showing results for 
Search instead for 
Did you mean: 

Issue using BlueNRG with CubeMX

Ricardo Hassan
Associate III
Posted on May 02, 2018 at 23:19

Hi,

    I am using a BlueNRG-MS connected to an STM32L4 MCU over an SPI bus.  I was able to make it work using code from the BlueNRG development kit, but I could not make it work if I generated code using CubeMX.  After a lot of trial and error, I realized that the CubeMX code was configuring all 4 SPI pins as alternate function (AF5_SPI2), but the BlueNRG example was configuring the slave select pin as an output push pull, which was working.  My question is, which is supposed to be correct?  As it is, when I enable the SPI2 peripheral in CubeMX, it automatically configures all 4 SPI pins as alternate function, with no other options.  I don't know if this is a bug in CubeMX, or if I have some other conflicting configuration that is breaking my setup.  

Ricardo

6 REPLIES 6
Amel NASRI
ST Employee
Posted on May 08, 2018 at 12:02

Hi

Hassan.Ricardo

‌,

Please precise the CubeMX version you are using.

To more understand your request: is your aim touse BlueNRG staring from a project you generate by your self with CubeMX?

-Amel

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.

Posted on May 08, 2018 at 18:07

Hi Amel,

I’m using STM32CubeMX 4.25.0, with STM32L4 firmware package 1.11.0. Yes, I’m generating my project using CubeMx for a system with a BlueNRG chip.

Regards,

Ricardo

Posted on May 10, 2018 at 10:52

Hi

Hassan.Ricardo

Could you please give me a link to the dev kit you are using

Posted on May 11, 2018 at 11:17

Hi

Hassan.Ricardo

,

on this example the SPI CS is also configured as AF

GPIO_InitStruct.Pin = BNRG_SPI_CS_PIN;

GPIO_InitStruct.Mode = BNRG_SPI_CS_MODE;

GPIO_InitStruct.Pull = BNRG_SPI_CS_PULL;

GPIO_InitStruct.Speed = BNRG_SPI_CS_SPEED;

GPIO_InitStruct.Alternate = BNRG_SPI_CS_ALTERNATE;

HAL_GPIO_Init(BNRG_SPI_CS_PORT, &GPIO_InitStruct);

/* BlueNRG SPI CS define values */

#define SDK_EVAL_V3_SPI_PERIPH_CS_PIN GPIO_PIN_12 /* PB.12 */

#define SDK_EVAL_V3_SPI_PERIPH_CS_MODE GPIO_MODE_OUTPUT_PP

#define SDK_EVAL_V3_SPI_PERIPH_CS_PULL GPIO_NOPULL

#define SDK_EVAL_V3_SPI_PERIPH_CS_SPEED GPIO_SPEED_HIGH

#define SDK_EVAL_V3_SPI_PERIPH_CS_ALTERNATE 0

#define SDK_EVAL_V3_SPI_PERIPH_CS_PORT GPIOB /* GPIOB */

#define SDK_EVAL_V3_SPI_PERIPH_CS_CLK_ENABLE() __GPIOB_CLK_ENABLE()

The only difference is that MX doesn't set the state pin when it is an AF like done in this project

HAL_GPIO_WritePin(BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_SET);

Could you add this line and test please ?

Posted on May 14, 2018 at 19:35

It looks to me that in your example the CS pin mode is configured as output push pull, as you wrote:

&sharpdefine SDK_EVAL_V3_SPI_PERIPH_CS_MODE GPIO_MODE_OUTPUT_PP

The other 3 spi pin modes are configured as alternate function, namely GPIO_MODE_AF_PP.  I would have thought that the chip select should also be GPIO_MODE_AF_PP.  I'm just trying to confirm that it should be as you wrote above, where the chip select is 

GPIO_MODE_OUTPUT_PP.

Ricardo