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
Posted on February 13, 2017 at 00:40

Thanks, it's good to know someone is reading it.

Yeah, yeah, if you read back a few more dozen entries, I go into (I think it's in the intro to C posts) the various compilers that play well with Cube and give my rationalization as to why I chose SW4STM32 for teaching my Embedded Wednesdays class at the local hacker space. For my blog I tend to use SW4STM32 for the examples because going from Cube to running is a 2 minute proposition.

In my Supeman life I use RTEMS and GCC. The RTEMS people have put together a really sweet version of the newlib system including all of the UNIX 'canonical' terminal I/O (read cooked mode) that does all of the backspace handling and stuff and it works SOOOOOO well.

In my Clark Kent life, teaching at the Edmonton New Technology Society, I needed something to get people up and running for zero cost that runs on Macs, Linux, and unfortunately, Windows, and SW4STM32 won.

I'd consider using it at work when I'm putting together a little system that runs bare metal and doesn't require an RTOS.

Posted on February 13, 2017 at 00:42

Thanks for the pinter, I'm listening to that track right now. I'm finishing up a blog post on DMA (targeted at intermediate/advanced embedded people) and I don't have a soundtrack yet.

Posted on February 13, 2017 at 00:54

Hmm, vocals at 22 minutes. Unfortunately that is how you break someone's flow. I'll keep listening though.

Posted on February 13, 2017 at 00:58

this one grows on you... must have listened to it 100 times...

Posted on April 10, 2017 at 18:53

Does this semihosting feature works the same way as using printf with ITM/SWO?

Mark Shoe
Senior
Posted on May 29, 2017 at 19:41

Your printf goes nowhere. You have to redirect it to UART1:

// redirection of printf

void _write(int file, char *ptr, int len)

{

int i;

for (i = 0; i < len; i++)

{

HAL_UART_Transmit(&huart1, (uint8_t*) &ptr[i], 1, 10);

}

}

The printf has to be closed with a \n

Search youtube for getting started with CubeMX