cancel
Showing results for 
Search instead for 
Did you mean: 

sw4stm32 basic function and printf not working

g. lewis
Associate II
Posted on February 09, 2017 at 12:12

Hi, I'm beginner and I started by a blink project using SW4STM32 along with STMCubeMx libraries set up for my board which is the STM411RE board.

It  works well using the following lines in the main while loop:

      HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);

      for(int i=0;i<14200000;i++);

but It doen't work when I tried to replace the for statment: for(int i=0;i<14200000;i++); by a function declared above the main{}

like:

void tempo(void){

    for(int i=0;i<14200000;i++);

}

This is really simple but I'm stuck here.

I got another problem with the printf statemenent that doesn't do anything. Don't know if this is correlated to it but it seems that there is something wrong on the configuration of Eclipse or missing I guess.

ps: I have include stdio.h on top of the program.

Thanks for your help

#sw4stm32-eclipse
25 REPLIES 25
parsec
Associate III
Posted on February 09, 2017 at 12:48

Can you perhaps post your entire code that doesn't work?

Not sure about your printf problem as I am using a different dev environment. FWIW for printf to work there one has to make sure the correct library is linked, otherwise the underlying functions are just stubs and any calls to printf will result in a big fat nothing. Either that or the redirection of the printf output is wrong.

T J
Lead
Posted on February 09, 2017 at 13:04

I guess the  'for loop' is being compiled out... since it doesn't do anything.

put the 'int i' declaration before the 'for loop'.

and use 'i' after the 'for loop'

maybe you can use

sprintf(string,' i %d\n\r',i);

puts(string);

thats how I got around the printf hardfault issue.

I point my 'puts' to the Usart port...

but I am not an expert, just trying to help...

Olivier GALLIEN
ST Employee
Posted on February 09, 2017 at 15:26

For compiled out of your 'for loop' you can try to remove optimization. 

For printf you need to either redirect it to an UART or, what I suggest as a first step, use the semihosting feature which will direct your printf to SW4STM32 Console window

For semihosting a tutorial is available in latest version in

Help >> Help Contents >> SystemWorkbench for STM32 User Guide >> Advanced >> Semihosting

Hope it help 

Olivier

Olivier GALLIEN
In order 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.
Sirma Siang
ST Employee
Posted on February 09, 2017 at 16:23

Hello Kim,

Your code is working on my F769 Discovery board....

The tempo is about 8s.

Are you sure about your GPIO config ?

To drive a led, it should be something like pushpull, with a pull up and high t level.

Kind regards

Sirma

Sirma Siang
ST Employee
Posted on February 09, 2017 at 16:28

Hello Kim,

Instead of writting HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);

could you try HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); ?

This blink LED2 on my NUCLEO-F411RE board.

Kind regards

Sirma

g. lewis
Associate II
Posted on February 09, 2017 at 16:51

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6rV&d=%2Fa%2F0X0000000bws%2FI7HIzpQ3dNw3pAKdvG7mQMv0ijNdeuP3rF4xg8Kv8S0&asPdf=false
Posted on February 09, 2017 at 16:17

Hello

Instead of using a loop, you can use HAL_Delay(time in ms);

i.e.: HAL_Delay(100), wait for 100ms

Kind regards

Sirma

Posted on February 09, 2017 at 17:18

Thanks Olivier,

It seems that I don't have the same kind of help contents.

For me it runs like this:

Help >> Help Contents >>Workbench User Guide >> no Advanced ??

This could be the clue of my problem since in the help nothing refer to stm32 !

Eclipse version:

0690X00000606HMQAY.png
Posted on February 09, 2017 at 17:22

The version which is required here is the one for STM32 plugin ( blue butterfly ) 

This specific help have come along 1.12.1 version. 

If you upgrade on latest 1.13.1 for sure you will get it

Olivier 

Olivier GALLIEN
In order 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.