chprintf STM32F4-Discovery with Expansion Board

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
chiVelle
Posts: 21
Joined: Sun Aug 25, 2013 4:16 pm

chprintf STM32F4-Discovery with Expansion Board

Post by chiVelle »

Hi everyone. I am new to Chibios and Cortex programming, but I have a frustrating issue getting debugging working out of the Discovery expansion board's COM1 Serial output. If anyone isn't familiar with the expansion board, it is this -> http://www.st.com/web/catalog/tools/FM1 ... 2/PF255417

The expansion board comes with some software examples, and one is a USART example that contains a readme that states:

This example shows how to retarget the C library printf function to the USART.
This implementation output the printf message on the Hyperterminal using USART6.
Connect a null-modem female/female RS232 cable between the DB9 connector COM1 (USART6) and PC serial port

Therefore based on this, I have written this source code and tested with minicom and cutecom configured to 38400 baud with /dev/ttyUSB0 open and I get no output whatsoever from the board. I see in my ubuntu box through dmesg that the USB->Serial adapter I have connected to my computer is detected and connected to /dev/ttyUSB0 so I'm confident it isn't my box setup:

1941.427237] usb 2-2.3: New USB device found, idVendor=0557, idProduct=2008
[ 1941.427241] usb 2-2.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1941.427251] usb 2-2.3: Product: USB-Serial Controller D
[ 1941.427252] usb 2-2.3: Manufacturer: Prolific Technology Inc.
[ 1941.449659] pl2303 2-2.3:1.0: pl2303 converter detected
[ 1941.463221] usb 2-2.3: pl2303 converter now attached to ttyUSB0

Here is the code I am flashing to the board:

Code: Select all

#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <chstreams.h>
#include <string.h>
#include <stdio.h>

int main(void)
{
   halInit();
   chSysInit();
   
   sdStart( &SD6 , NULL );
   
   while(TRUE)
   {
      chprintf((BaseSequentialStream*)&SD6, "TEST");
      chThdSleepMilliseconds(1000);
   }

   return 0;
}


Here are my settings for UART and Serial in the config:

Code: Select all

/*
 * SERIAL driver system settings.
 */
#define STM32_SERIAL_USE_USART1             FALSE
#define STM32_SERIAL_USE_USART2             FALSE
#define STM32_SERIAL_USE_USART3             FALSE
#define STM32_SERIAL_USE_UART4              FALSE
#define STM32_SERIAL_USE_UART5              FALSE
#define STM32_SERIAL_USE_USART6             TRUE

/*
 * UART driver system settings.
 */
#define STM32_UART_USE_USART1               FALSE
#define STM32_UART_USE_USART2               FALSE
#define STM32_UART_USE_USART3               FALSE
#define STM32_UART_USE_USART6               FALSE



I hope someone can help me. I know that USART6 is connected to pins 6 and 7 on the board, and most of the examples for serial show additional configuration with pins 2 and 3, do I need to do anything extra to get TX and RX working for chprintf?

Thank you.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf STM32F4-Discovery with Expansion Board

Post by Giovanni »

hi,

You need to program those pins for use with USART, this means setting up an alternate mode using palSetPadMode() and consulting the pin settings table in the data sheet.

In the various F4 demos you will find various examples of this, probably not for USART6.

Giovanni
chiVelle
Posts: 21
Joined: Sun Aug 25, 2013 4:16 pm

Re: chprintf STM32F4-Discovery with Expansion Board

Post by chiVelle »

I tried this code as well, and still nothing. The datasheet shows that USART6 is in portC and on pins 6 and 7. I don't quite understand the input to PAL_MODE_ALTERNATE, so based on the testhal code I am just giving the alternative function as 7.

Code: Select all

#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <chstreams.h>
#include <string.h>
#include <stdio.h>

int main(void)
{
   halInit();
   chSysInit();
   
   sdStart( &SD6 , NULL );
   palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(7));
    palSetPadMode(GPIOC, 7, PAL_MODE_ALTERNATE(7));
   
   while(TRUE)
   {
      chprintf((BaseSequentialStream*)&SD6, "TEST");
      chThdSleepMilliseconds(1000);
   }

   return 0;
}
chiVelle
Posts: 21
Joined: Sun Aug 25, 2013 4:16 pm

Re: chprintf STM32F4-Discovery with Expansion Board

Post by chiVelle »

I see the forum post regarding PAL_MODE_ALTERNATE here -> viewtopic.php?f=2&t=452, you mention a data sheet with table 7 listing the alternative functions. Where can I find this data sheet? I see the reference manuals, but can't find this document. Thank you.
chiVelle
Posts: 21
Joined: Sun Aug 25, 2013 4:16 pm

Re: chprintf STM32F4-Discovery with Expansion Board

Post by chiVelle »

Nevermind regarding where to find the document for the alternate function mapping. I found it in the official STM32F4xx datasheet in table 9 of Section 3 in this PDF if anyone else needs to know. -> http://www.st.com/web/en/resource/techn ... 037051.pdf
chiVelle
Posts: 21
Joined: Sun Aug 25, 2013 4:16 pm

Re: chprintf STM32F4-Discovery with Expansion Board

Post by chiVelle »

Alright, based on table, I see USART6 TX and RX falls under alternate function AF8, so the code that works is below. Thanks for the help, this thread is solved.

Code: Select all

#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <chstreams.h>
#include <string.h>
#include <stdio.h>

int main(void)
{
   halInit();
   chSysInit();
   
   sdStart( &SD6 , NULL );
   palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(8));
    palSetPadMode(GPIOC, 7, PAL_MODE_ALTERNATE(8));
   
   while(TRUE)
   {
      chprintf((BaseSequentialStream*)&SD6, "TEST");
      chThdSleepMilliseconds(1000);
   }

   return 0;
}
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf STM32F4-Discovery with Expansion Board

Post by Giovanni »

You are welcome, the data sheet I was referring to is exactly that one.

Giovanni
Post Reply