5 years, 1 month 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

2 Answers

5 years, 1 month ago.

Hello,

Just to make sure, are you plugging the usb wire on the plug that is located near the USER button ?

I have tested the suggested code and modification on the NUCLEO_F446ZE, you are right, it compiles but does not work.

Take care there is a GPIO (PG_6) that can handle the power on on the Nucleo_144 pins board. Depending on the use case you may need it.

USB registers are different between STM32F446 and STM32F429. The file USBDevice/USBDevice/USBHAL_STM32F4.cpp directly writes into registers. There is probably one or several wrong.

ST team will support usb within a few months, but in the meanwhile, you could check what is done in the Cube firmware http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

You can see the example for USB keyboard on NUCLEO_F446ZE in the directory : Projects\STM32F446ZE-Nucleo\Applications\USB_Host\HID_Standalone\Src

The source file that you could look into within mbed library is the mbed/hal/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_ll_usb.c https://github.com/ARMmbed/mbed-os/blob/master/hal/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_ll_usb.c

I hope it will help you to wait until ST supports the USB feature on its boards.

Cheers

Accepted Answer

Hello, Yes, I used a connector near the blue button Ok, thanks

posted by Private Private 22 Aug 2016

Is there any progress on this issue?

I have the same problem on the same board (NUCLEO_F446ZE) and we will also have to deal with it for the stm32f303cb microcontroller.

I took a look at the pointed files but I will need some time to figure out what is going on before even trying to fix it.

Thanks in advance for any Info/help.

posted by Angel Merino 23 Jan 2017
5 years, 1 month 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