STM3240G_EVAL and USB Serial

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

Moderator: RoccoMarco

Post Reply
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

STM3240G_EVAL and USB Serial

Post by ogi »

Hi all,
I have a STM3240G_EVAL board, I think it's a nice board but it seems to be a bit uncommon so there is no much as demos or examples on the net. I'm new to Chibios, but what I have seen is great, congrats to all for that.

The board has a STM32F407 and a bunch of peripherals includig 2 USB ports, OTG1, a FS with internal phy on the micro and OTG2 HS with external phy.

I'm running Chibios 2.6.6 on it using USART 3 for debugging and I'm trying to setup a usb serial port as I can't use the USART3 if I want to use the SD card (the pins are used by both peripherals).

I started to build a new board.h and board.c from the 407Discovery board and I'm trying to adapt the code from the STM32F4xx-USB_CDC to run in the board.

The code for the discovery used OTG2 and I wanted to use OTG1 (I need to make a small design, so I try to use the microcontroler peripherals ), I changed this (I took me a long while to figure it out) in this line :

Code: Select all

static const SerialUSBConfig serusbcfg = {&USBD1, USBD2_DATA_REQUEST_EP,
                                          USBD2_DATA_AVAILABLE_EP,
                                          USBD2_INTERRUPT_REQUEST_EP};


Keeping the value of the constants USBD2_DATA_REQUEST_EP and so.

After this I see a new device in the usb tree in my Windows 7 64 machine, but it only says "unknown device", there are no hardware ids (USB\UNKNOWN) .

I've searched all over the code, the forum and the internet, I've seen that the constants values are the same when you use OTG1 (other examples including the OTG1 port use them) but I've been unable to make it work,

I'm attaching a zip file with the code and board.h just in case somebody can try it or read it.

I'm using Chibistudio and it's tools (GCC).

Thanks a lot

Olgierd
Attachments
ARMCM4-STM3240G_EVAL-USB_CDC-UART3.zip
(16.23 KiB) Downloaded 392 times
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

Re: STM3240G_EVAL and USB Serial

Post by ogi »

It seems the board.h wasn't uploaded, anyway, here it is.

Code: Select all

/*
    ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#ifndef _BOARD_H_
#define _BOARD_H_

/*
 * Setup for STMicroelectronics STM3220G-EVAL board.
 * SWD programming mode
 */

/*
 * Board identifier.
 */
#define BOARD_ST_STM3240G_EVAL
#define BOARD_NAME              "ST STM3240G-EVAL"

/*
 * Board frequencies.
 * NOTE: The HSE crystal is not fitted by default on the board.
 */
#define STM32_LSECLK            32768
#define STM32_HSECLK            25000000



/*
 * Ethernet PHY type.
 */
#define BOARD_PHY_ID            MII_DP83848I_ID
//#define BOARD_PHY_RMII


/*
 * Board voltages.
 * Required for performance limits calculation.
 */
#define STM32_VDD                   330


/*
 * MCU type as defined in the ST header file stm32f2xx.h.
 */
#define STM32F40_41xxx

//#define STM32_USB_USE_USB1  TRUE
//#define rccDisableOTG1(lp) rccDisableAHB2(RCC_AHB2ENR_OTGFSEN, lp)


/*
 * IO pins assignments.
 */

#define GPIOA_WAKEUP_BUTTON     0
#define GPIOC_TAMPER_BUTTON     0
#define GPIOG_USER_BUTTON       15

#define GPIOG_LED1              6
#define GPIOG_LED2              8
#define GPIOI_LED3              9
#define GPIOC_LED4              7

#define GPIOF_POT               9

#define GPIOH_SD_DETECT         13




/*
 * I/O ports initial setup, this configuration is established soon after reset
 * in the initialization code.
 * Please refer to the STM32 Reference Manual for details.
 */
#define PIN_MODE_INPUT(n)           (0 << ((n) * 2))
#define PIN_MODE_OUTPUT(n)          (1 << ((n) * 2))
#define PIN_MODE_ALTERNATE(n)       (2 << ((n) * 2))
#define PIN_MODE_ANALOG(n)          (3 << ((n) * 2))
#define PIN_OTYPE_PUSHPULL(n)       (0 << (n))
#define PIN_OTYPE_OPENDRAIN(n)      (1 << (n))
#define PIN_OSPEED_2M(n)            (0 << ((n) * 2))
#define PIN_OSPEED_25M(n)           (1 << ((n) * 2))
#define PIN_OSPEED_50M(n)           (2 << ((n) * 2))
#define PIN_OSPEED_100M(n)          (3 << ((n) * 2))
#define PIN_ODR_LOW(n)              (0U << (n))
#define PIN_ODR_HIGH(n)             (1U << (n))
#define PIN_PUDR_FLOATING(n)        (0 << ((n) * 2))
#define PIN_PUDR_PULLUP(n)          (1 << ((n) * 2))
#define PIN_PUDR_PULLDOWN(n)        (2 << ((n) * 2))
#define PIN_AFIO_AF(n, v)           ((v##U) << ((n % 8) * 4))

/*
 * Port A setup.
 * All input floating except:
 *
 * PA0----------------WAKEUP button I   (af 0)      Float
 *
 *
 * PA8----------------MCO           O   (af 0)      Push Pull
 *
 * PA9----------------USB Vbus sens I               input pulldown
 * PA10---------------USB FS ID     I   (af10)      Float
 * PA11---------------USB FS DM     IO  (af10)      Float
 * PA12---------------USB FS DP     IO  (af10)      Float
 *
 * PA13---------------SWDAT         I   (af 0)      Float
 * PA14---------------SWCLK         I   (af 0)      Float
 *
 */
#define VAL_GPIOA_MODER             (PIN_MODE_ALTERNATE(8)    | \
                                     PIN_MODE_INPUT(9)    | \
                                     PIN_MODE_ALTERNATE(10)    | \
                                     PIN_MODE_ALTERNATE(11)    | \
                                     PIN_MODE_ALTERNATE(12)    | \
                                     PIN_MODE_ALTERNATE(13)   | \
                                     PIN_MODE_ALTERNATE(14) )
#define VAL_GPIOA_OTYPER            (PIN_OTYPE_PUSHPULL(8)  | \
                                     PIN_OTYPE_PUSHPULL(9)  | \
                                     PIN_OTYPE_PUSHPULL(10) | \
                                     PIN_OTYPE_PUSHPULL(11) | \
                                     PIN_OTYPE_PUSHPULL(12) )
#define VAL_GPIOA_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOA_PUPDR             (PIN_PUDR_FLOATING(0)  | \
                                     PIN_PUDR_PULLDOWN(9)  | \
                                     PIN_PUDR_FLOATING(10)  | \
                                     PIN_PUDR_FLOATING(11)  | \
                                     PIN_PUDR_FLOATING(12)  | \
                                     PIN_PUDR_FLOATING(13) | \
                                     PIN_PUDR_FLOATING(14)     )
#define VAL_GPIOA_ODR               0x00000000
#define VAL_GPIOA_AFRL            0x00000000
#define VAL_GPIOA_AFRH            (PIN_AFIO_AF(8,0)   | \
                                   PIN_AFIO_AF(10, 10) | \
                                   PIN_AFIO_AF(11, 10) | \
                                   PIN_AFIO_AF(12, 10) | \
                                     PIN_AFIO_AF(13, 0) | \
                                     PIN_AFIO_AF(14, 0) )

/*
 * Port B setup.
 * All input with pull-up except:
 * PB3----------------SWO           O   (af 0)
 *
 *
 */
#define VAL_GPIOB_MODER             PIN_MODE_ALTERNATE(3)
#define VAL_GPIOB_OTYPER            0x00000000
#define VAL_GPIOB_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOB_PUPDR             0x00000000
#define VAL_GPIOB_ODR               0x00000000
#define VAL_GPIOB_AFRL            PIN_AFIO_AF(3, 0)
#define VAL_GPIOB_AFRH            0x00000000

/*
 * Port C setup.  with SD
 * All input with pull-up except:
 *
 *
 *
 * PC7----------------Led4          O               Push Pull HS
 *
 * PC8----------------SD D0         IO  (af12)      Float
 * PC9----------------SD D1         IO  (af12)      Float
 * PC10---------------SD D2         IO  (af12)      Float
 * PC11---------------SD D3         IO  (af12)      Float
 * PC12---------------SD CLK        O   (af12)      Push Pull HS
 *
 * PC14---------------OSC32_INT     I               Float
 * PC15---------------OSC32_OUT     I               Float
 *
 *
 *---------------------------------------------------------------
 *
 *
 *  With UART3
 *
 * PC7----------------Led4          O               Push Pull HS
 *
 * PC10---------------USART3 TX     O   (af7)
 * PC11---------------USART3 RX     I   (af7)
 *
 * PC14---------------OSC32_INT     I               Float
 * PC15---------------OSC32_OUT     I               Float
 *
 *
 *
 */
#define VAL_GPIOC_MODER            (PIN_MODE_OUTPUT(7)        | \
                                    PIN_MODE_ALTERNATE(10)    | \
                                    PIN_MODE_ALTERNATE(11)    )
#define VAL_GPIOC_OTYPER          ( PIN_OTYPE_PUSHPULL(7)  | \
                                    PIN_OTYPE_PUSHPULL(10) | \
                                    PIN_OTYPE_PUSHPULL(11) )
#define VAL_GPIOC_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOC_PUPDR            (PIN_PUDR_FLOATING(10)  | \
                                    PIN_PUDR_FLOATING(11) )
#define VAL_GPIOC_ODR               0xFFFFFFFF
#define VAL_GPIOC_AFRL            0x00000000
#define VAL_GPIOC_AFRH            (PIN_AFIO_AF(10, 7)    | \
                                    PIN_AFIO_AF(11, 7) )

/*
 * Port D setup.
 * All input with pull-up except.
 *
 * PD2-------------SD CMD       O   (af12)      Push Pull HS
 *
 *
 *
#define VAL_GPIOD_MODER             PIN_MODE_ALTERNATE(2)
#define VAL_GPIOD_OTYPER            PIN_OTYPE_PUSHPULL(2)
#define VAL_GPIOD_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOD_PUPDR             0x00000000
#define VAL_GPIOD_ODR               0x00000000
#define VAL_GPIOD_AFRL            PIN_AFIO_AF(12, 2)
#define VAL_GPIOD_AFRH            0x00000000
*/

#define VAL_GPIOD_MODER             0x00000000
#define VAL_GPIOD_OTYPER            0x00000000
#define VAL_GPIOD_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOD_PUPDR             0x00000000
#define VAL_GPIOD_ODR               0x00000000
#define VAL_GPIOD_AFRL              0x00000000
#define VAL_GPIOD_AFRH              0x00000000



/*
 * Port E setup.
 * All input with pull-up.
 */
#define VAL_GPIOE_MODER             0x00000000
#define VAL_GPIOE_OTYPER            0x00000000
#define VAL_GPIOE_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOE_PUPDR             0x00000000
#define VAL_GPIOE_ODR               0x00000000
#define VAL_GPIOE_AFRL            0x00000000
#define VAL_GPIOE_AFRH            0x00000000

/*
 * Port F setup.
 * All input with pull-up.
 */
#define VAL_GPIOF_MODER             0x00000000
#define VAL_GPIOF_OTYPER            0x00000000
#define VAL_GPIOF_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOF_PUPDR             0x00000000
#define VAL_GPIOF_ODR               0x00000000
#define VAL_GPIOF_AFRL            0x00000000
#define VAL_GPIOF_AFRH            0x00000000

/*
 * Port G setup.
 * All input with pull-up. Except:
 * PG6----------------LED1          O               Push Pull HS
 * PG8----------------LED2          O               Push Pull HS
 */
#define VAL_GPIOG_MODER             ( PIN_MODE_OUTPUT(GPIOG_LED1) | \
                                      PIN_MODE_OUTPUT(GPIOG_LED2) )
#define VAL_GPIOG_OTYPER            ( PIN_OTYPE_PUSHPULL(GPIOG_LED1) | \
                                      PIN_OTYPE_PUSHPULL(GPIOG_LED2) )
#define VAL_GPIOG_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOG_PUPDR             0x00000000
#define VAL_GPIOG_ODR               0x00000000
#define VAL_GPIOG_AFRL            0x00000000
#define VAL_GPIOG_AFRH            0x00000000

/*
 * Port H setup.
 * All input with pull-up except
 *
 *
 * PH13---------------SD Detect     I   (af12)      Pull Up
 */
#define VAL_GPIOH_MODER             0x00000000
#define VAL_GPIOH_OTYPER            0x00000000
#define VAL_GPIOH_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOH_PUPDR             0x00000000
#define VAL_GPIOH_ODR               0x00000000
#define VAL_GPIOH_AFRL              0x00000000
#define VAL_GPIOH_AFRH              0x00000000


/*
 * Port I setup.
 * All input with pull-up.
 *
 *
 *
 */
#define VAL_GPIOI_MODER             0x00000000
#define VAL_GPIOI_OTYPER            0x00000000
#define VAL_GPIOI_OSPEEDR           0xFFFFFFFF
#define VAL_GPIOI_PUPDR             0x00000000
#define VAL_GPIOI_ODR               0x00000000
#define VAL_GPIOI_AFRL              0x00000000
#define VAL_GPIOI_AFRH              0x00000000





#if !defined(_FROM_ASM_)
#ifdef __cplusplus
extern "C" {
#endif
  void boardInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _FROM_ASM_ */

#endif /* _BOARD_H_ */

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

Re: STM3240G_EVAL and USB Serial

Post by Giovanni »

Hi,

The demo ARMCM4-STM32F407-DISCOVERY-MEMS uses USBD1, you may look at that however I am pretty sure that the problem is in the board file, you should verify that carefully.

Another note, the board file is usually generated not written, the board description is into an XML file with extension .chcfg, once opened you see a button for generation in the ChibiStudio toolbar.

Giovanni
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

Re: STM3240G_EVAL and USB Serial

Post by ogi »

Thank a lot Giovanni,
I realized already that the board files are quite important and I've worked on them a lot, I'll try now the board generation tool and I'll post the results.

Thanks again

Olgierd
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

Re: STM3240G_EVAL and USB Serial

Post by ogi »

Dear Giovanni, it seems this was a board problem because under oscilloscope, the PA11 pin moves perfectly well (3.3 V swing) and the PA12 pin swings only 0.33 V under any confuiguration (even open drain with pullup). So I suspect a design flaw or a burned pin (I bought that board in ebay, seemed new, but may be it was not).

Now I tried the usb code with a tiny LC Studio STM32F103 board, copying and adapting the code from the 103_NEMO_DISCOVERY example. This time both USB pins swings correctly (I noticed a pullup resistor on the USB DP pin (PA12) that the 3240G_EVAL didn't have), but I still get the same error, "unknown device".

I installed the last (v. 1.3.1) ST virtual com port driver in two computers and tried the board, but I get the same error.

I'm really a bit lost on this, any idea ?

Thanks in advance

Olgierd
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM3240G_EVAL and USB Serial

Post by Giovanni »

No idea, I never saw that error.

I suggest you get one of the supported boards, a cheap discovery kit for example, and start gaining experience with the system before attempt ports. ChibiOS is well organized but quite complex for new users.

A good board for playing with USB is the Olimex STM32-E407, it has both OTG1 and OTG2 connectors so it is perfect for experimenting.

Giovanni
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

Re: STM3240G_EVAL and USB Serial

Post by ogi »

Dear Giovanni, thanks a lot for the support, I already bought a discovery f4 board because of the same reason :) , I discovered Chibios a couple of weeks ago and I love it already, but yes, it's quite complex at the beginnig.

My kindest regards and congratulations again.

Olgierd
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

Re: STM3240G_EVAL and USB Serial

Post by ogi »

I found it :D :D :D ! this board is usb powered, there is no VBUS signal, so I tied the VBUS pin to 3.3V and it worked, there is no USB disconnect neither so I have to unplug it on each programming)

I have another question :?: , I have a sdcard-spi adapter that has no signals for card insertion or write protection, they are tied to ground, ¿ do I have to modify the examples code for MMC-SPI ?, or I just declared TRUE in the mmc_lld_is_card_inserted funciton in board.c ?

Thanks for all the support,

Olgierd
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM3240G_EVAL and USB Serial

Post by Giovanni »

Hi,

Depending on how the SD connector is wired it could be possible to detect cards even without a dedicated detect line, see board.c of the STM32-E407 board, it uses a pull-upinternal to the card on D3 that can be detected.

Alternatively you can return TRUE but this disables the card detection.

Giovanni
ogi
Posts: 8
Joined: Tue Nov 04, 2014 6:54 pm

Re: STM3240G_EVAL and USB Serial

Post by ogi »

Thanks !! I'll try it now.

Olgierd
Post Reply