cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103CBT using code from Cube doesn't turn led on

gvuyk07
Associate II
Posted on January 22, 2016 at 03:27

Steps:

  1. Create new project on STM32CubeMx (v4.0)
  2. Set PB3 as GPIO_Output
  3. Generate code (for Atollic TrueStudio)
  4. Import the generated files (project)
  5. Use the following code to try blink the led

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3,GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3,GPIO_PIN_RESET);
HAL_Delay(500);

6. Compile and upload Result: nothing happens, led stays off. Note: I'm testing on a custom made board with an STM32F103CBT, and a led correctly connected to PB3. USART works correctly if I add it so chip is ok. I also tested with init code from

https://github.com/rogerclarkmelbourne/Arduino_STM32

(none Cube generated) and the led blinks successfully, so the problem lies in Cube generated init code or I'm missing something? Attached a zip with the files (generated by Cube) and my 4 lines added #stm32f103-gpio-cube
5 REPLIES 5
Posted on January 22, 2016 at 04:39

Can you use a debugger, and step through the code? Examine the peripheral settings, clocks, registers, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gvuyk07
Associate II
Posted on January 23, 2016 at 22:05

Debugger is on its way (shipping)

But found the problem, Debug functions conflicts with PB3 and PB4, and even tho you select those as OUTPUT GPIOs, Cube doesn't disable debugging. It warns you about the conflict (exclamation sign next to SYS) but the dropdown menu next to ''Debug'' auto-selects ''Disabled'' making you think its taken care of

You have to select ''No Debug'' to actually disable it

0690X00000604pwQAA.png

re.wolff9
Senior
Posted on January 24, 2016 at 09:58

I guess that if I was forced to think about it I'd implement it the same way. 

If you have a board (you do!) that you sometimes debug with just the led but sometimes with full debug support, you can share the pin between debugging and the led. Then if you need ''full debugging'' you enable it in the menu and the IDE doesn't allow your code to change the debug pins to ''led mode'' while you're debugging the code. 

(most of the time you'd want to debug everything else than that blinking led....)

gvuyk07
Associate II
Posted on January 24, 2016 at 19:09

Agree.

Just wish it was a little more explicit

924698880
Associate
Posted on January 25, 2016 at 13:05

PB3 is work as JTDO default ,so u need to shutdown the setup.or u can change the GPIO if this method is possible