cancel
Showing results for 
Search instead for 
Did you mean: 

Keil µVision5 - NUCLEO STM32F334R8 - Running the GPIO Toggle code

antoine
Associate II
Posted on June 21, 2016 at 15:03

Hi,

still completely stuck with my waveform generation on my NUCLEO-F334R8, I thought it could be a food thing to start from the beginning, with a more simple code. So I tried GPIO Toggle example from the standard libraries. I understand that I'm supposed to observe a signal on the scope, then nothing, then signal again, etc. There is no GPIOE on F334R8, so I changed it to GPIOC. This is the only change I made.


#include ''stm32f30x.h''


/* Private define ------------------------------------------------------------*/

#define BSRR_VAL 0xC000

/* Private variables ---------------------------------------------------------*/

GPIO_InitTypeDef GPIO_InitStructure;


int
main(
void
)

{


/* GPIOC Periph clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);


/* Configure PC14 and PC15 in output pushpull mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOC, &GPIO_InitStructure);



while
(1)

{

/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15*/

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC0 and PC1 */

GPIOC->BRR = BSRR_VAL;


/* Set PC14 and PC15 */

GPIOC->BSRR = BSRR_VAL;

/* Reset PC14 and PC15 */

GPIOC->BRR = BSRR_VAL;

}

}

And i still have the orange LED1 that indicates the running has failed. I think the problem is deeper than just related to the code I'm trying to execute, it might have something to do with the manner I'm trying to execute it, I don't know, but I think if I could run this code (or a blinky, which I don't have as example), I could progress. Thank you.
5 REPLIES 5
Amel NASRI
ST Employee
Posted on June 21, 2016 at 15:44

Hi Antoine.PM,

Please try to use other pins than PC14 and PC15.

In

http://www.st.com/content/ccc/resource/technical/document/datasheet/d1/cd/3d/18/a2/2c/4e/d0/DM00097745.pdf/files/DM00097745.pdf/jcr:content/translations/en.DM00097745.pdf

, you find following note:

PC13, PC14 and PC15 are supplied through the power switch. Since the switch sinks only a limited amount of current (3 mA), the use of

 

GPIO PC13 to PC15 in output mode is limited:

 

- The speed should not exceed 2 MHz with a maximum load of 30 pF

 

- These GPIOs must not be used as current sources (e.g. to drive an LED)

I recommend you start with dedicated examples for Nucleo STM32F334R8 available in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef3.html

(Ex: STM32Cube_FW_F3_V1.5.0\Projects\STM32F334R8-Nucleo\Examples\GPIO\GPIO_IOToggle).

-Mayla-

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.

antoine
Associate II
Posted on June 21, 2016 at 16:01

Hi Mayla, thank you for your answer.

Are there pins that would suit best for this simple example? Or can I try more or less anything else?

Thank you for providing me a source for example, however since I already spent way too much time on learning how to use Keil, and I'm running of time, I'm very afraid of starting to use another IDE especially if it turns out to be a dead end.

So, do you think I really should toggle from Keil to CubeF3?

Waiting for your answer, I'll consider the other pins on Keil. Thank you. 🙂

antoine
Associate II
Posted on June 21, 2016 at 17:43

I finally managed to have it working.

For anyone interested (who knows), this is my code for STM32F334R8:


#include ''stm32f30x.h''

#include ''stm32f30x_gpio.h''


#define BSRR_VAL 0x00C0 //corresponding to hex for pins 6 and 7 in BSRR register



GPIO_InitTypeDef GPIO_InitStructure;


int
main(
void
)

{


/* GPIOA Periph clock enable */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);


/* Configure PA6 and PA7 in output pushpull mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; 
//50MHz originally, but GPIO supports 36MHz max

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_InitStructure);


/* To achieve GPIO toggling maximum frequency, the following sequence is mandatory. 

You can monitor PA6 and PA7 on the scope to measure the output signal. 

If you need to fine tune this frequency, you can add more GPIO set/reset 

cycles to minimize more the infinite loop timing.

This code needs to be compiled with high speed optimization option. */

while
(1)

{

/* Set PA6 and PA7 */

GPIOA->BSRR = BSRR_VAL;

/* Reset PA6 and PA7 */

GPIOA->BRR = BSRR_VAL;


/* Set PA6 and PA7 */

GPIOA->BSRR = BSRR_VAL;

/* Reset PA6 and PA7 */

GPIOA->BRR = BSRR_VAL;


/* Set PA6 and PA7 */

GPIOA->BSRR = BSRR_VAL;

/* Reset PA6 and PA7 */

GPIOA->BRR = BSRR_VAL;


//Just comment/uncomment to change the shape of the signal on the scope

// /* Set PA6 and PA7 */

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PA6 and PA7 */

// GPIOA->BRR = BSRR_VAL;

// 

// /* Set PA6 and PA7 */

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PA6 and PA7 */

// GPIOA->BRR = BSRR_VAL;

// 

// /* Set PA6 and PA7 */

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PA6 and PA7 */

// GPIOA->BRR = BSRR_VAL;

// 

// /* Set PA6 and PA7*/

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PA6 and PA7 */

// GPIOA->BRR = BSRR_VAL;

// 

// /* Set PA6 and PA7 */

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PA6 and PA7 */

// GPIOA->BRR = BSRR_VAL;

// 

// /* Set PA6 and PA7 */

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PC0 and PC1 */

// GPIOA->BRR = BSRR_VAL;

// 

// /* Set PA6 and PA7 */

// GPIOA->BSRR = BSRR_VAL;

// /* Reset PA6 and PA7 */

// GPIOA->BRR = BSRR_VAL;

}

}

Let's have fun with a triangle, now, and finally, maybe, sinewave.
Amel NASRI
ST Employee
Posted on June 23, 2016 at 10:10

Hi Antoine.PM,

Cube is a library package, not an IDE.

In the suggested example, you find a pre-configured project for Keil (and other IDEs).

-Mayla-

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.

antoine
Associate II
Posted on June 23, 2016 at 13:48

Oh, ok, I get it hehe ^^''

I'll give it a try 🙂