8 years, 4 months ago.

Working USB example

Is there an working example for the NUCLEO-F446ZE board?

Question relating to:

STM32 Nucleo-144 development board with STM32F446ZE MCU, supports Arduino, ST Zio and morpho connectivity

Hi,

Thanks for your question let me try and help you.

What USB application are you hoping to achieve with the F446ZE then i can point you in the right direction?

Regards,

-Andrea, team mbed

posted by Andrea Corrado 15 Aug 2016

Right now I am trying to check what the USB connector on the PCB works. Could you suggest any example which can be runned on the NUCLEO-F446ZE?

posted by Private Private 15 Aug 2016

Hi, somewhy cannot answer on your post below, so answering here. Yes I have tried this yesterday, the code compiles but does not work (device is not appears in the system). Also, as I remeber the USB registers for the STM32F407 and STM32F446 a little bit differ but code in the USBHAL_STM32F4.cpp do not pay attention on this...

posted by Private Private 16 Aug 2016

1 Answer

8 years, 4 months ago.

Hi,

So if you just wish to test if the USB connection is working on the F446ZE there are a number of possible programs you could use to test this.

On the right hand side of this page "https://developer.mbed.org/platforms/ST-Nucleo-F446ZE/" You will see a number of examples you can import to test the F446ZE to program with, just import the program and set your target to the F446ZE.

If you wish to test the communications of USB then again you can find a number of programs written by the community that are not only applicable to just one platform but all of them using the mbed libraries.

Therefore a good starting point would be to test sending some characters between your PC and the F446ZE using USB/UART.

A guide to do this can be found here:

https://developer.mbed.org/handbook/SerialPC

The first example will send back what you type to the F446ZE

Remember you will have to install the necessary drivers at the bottom of the page, install a terminal application such as TerraTerm and set the terminal to the correct COM port.

If you need anything else please let me know :).

Regards,

Andrea, team mbed

Hello, I had tried several examples (USBMouse, USBKeyboard_Mouse), but it seems what the USB mbed library currently does not support the STM32F446ZE as target :(

posted by Private Private 15 Aug 2016

What issues are you specifically having, is it compiling the examples for the target? Are you getting build errors? Or is it just not functioning?

Andrea

posted by Andrea Corrado 15 Aug 2016

Hi, I get following errors: Error: Too few arguments in invocation of macro "STM_PIN_DATA" in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 58, Col: 43 Error: Expected an expression in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 58, Col: 25 Error: Too few arguments in invocation of macro "STM_PIN_DATA" in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 59, Col: 42 Error: Expected an expression in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 59, Col: 25 Error: Too few arguments in invocation of macro "STM_PIN_DATA" in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 60, Col: 44 Error: Expected an expression in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 60, Col: 26 Error: Too few arguments in invocation of macro "STM_PIN_DATA" in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 61, Col: 44 Error: Expected an expression in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 61, Col: 26 Error: Too few arguments in invocation of macro "STM_PIN_DATA" in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 62, Col: 44 Error: Expected an expression in "USBDevice/USBDevice/USBHAL_STM32F4.cpp", Line: 62, Col: 26

posted by Private Private 15 Aug 2016

Hi,

So ok. Looking in the USB device library in the program "USBKeyboard"

https://developer.mbed.org/handbook/USBKeyboard

It seems that when compiling the target is not yet supported in the USBdevice.

It is possible you could add the target yourself following the steps:

Navigate to USBDevice/USBDevice/USBHAL_STM32F4.cpp;

Go to line 51 (line 33 in my example) and add at the very end " || defined(TARGET_STM32F446ZE) "

This adds the target to list of defined platforms in the USBdevice.

Your code should therefore look like this

USBHAL_STM32F4.cpp

#if defined(TARGET_STM32F4)

#include "USBHAL.h"
#include "USBRegs_STM32.h"
#include "pinmap.h"

USBHAL * USBHAL::instance;

static volatile int epComplete = 0;

static uint32_t bufferEnd = 0;
static const uint32_t rxFifoSize = 512;
static uint32_t rxFifoCount = 0;

static uint32_t setupBuffer[MAX_PACKET_SIZE_EP0 >> 2];

uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {
    return 0;
}

USBHAL::USBHAL(void) {
    NVIC_DisableIRQ(OTG_FS_IRQn);
    epCallback[0] = &USBHAL::EP1_OUT_callback;
    epCallback[1] = &USBHAL::EP1_IN_callback;
    epCallback[2] = &USBHAL::EP2_OUT_callback;
    epCallback[3] = &USBHAL::EP2_IN_callback;
    epCallback[4] = &USBHAL::EP3_OUT_callback;
    epCallback[5] = &USBHAL::EP3_IN_callback;

    // Enable power and clocking
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

#if defined(TARGET_STM32F407VG) || defined(TARGET_STM32F401RE) || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F429ZI) || defined(TARGET_STM32F446ZE) //New added definition
    pin_function(PA_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
    pin_function(PA_9, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, GPIO_AF10_OTG_FS));
    pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS));
    pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
    pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
#else
    pin_function(PA_8, STM_PIN_DATA(2, 10));
    pin_function(PA_9, STM_PIN_DATA(0, 0));
    pin_function(PA_10, STM_PIN_DATA(2, 10));
    pin_function(PA_11, STM_PIN_DATA(2, 10));
    pin_function(PA_12, STM_PIN_DATA(2, 10));

I have no board to test this with but i now also get no compiler errors so it's worth a shot.

Let me know how you get on!

All the best.

Andrea, team mbed

posted by Andrea Corrado 16 Aug 2016

Yes I have tried this yesterday, the code compiles but does not work (device is not appears in the system). Also, as I remember the USB registers for the STM32F407 and STM32F429 a little bit differ but code in the USBHAL_STM32F4.cpp do not pay attention on this...

posted by Private Private 16 Aug 2016