Olimex STM32-E407 OTG1 is normally blocking USB port

Started by pculverhouse@gmail.com, December 01, 2021, 05:41:48 PM

Previous topic - Next topic

pculverhouse@gmail.com

Hi,

I set up my OTG1 port using USBserial as a USB port to my host. I need it to be non-blocking, since if I restart the STM32 without having the USB cable connected to my host, the board will not run the code I supply.

Once I connect the host, my code runs. My first section of code is just a LED blinky for additional LEDs on the Arduino digital pins.

How can I set the USB to be non-blocking?

My code is long but here are the crucial bits:

edit mbed_app.json in mbed folder to set UART as below, for UEXT connector to USB-RS232 board
 {
 "target_overrides": {
 "OLIMEX_STM32E407_F407ZG": {
 "target.stdio_uart_tx": "PC_6",
 "target.stdio_uart_rx": "PC_7",
 "platform.stdio-baud-rate": 115200,
 "platform.default-serial-baud-rate": 115200
 }
 }
 }

//********************** CODE START ********************************

#include "mbed.h"
#include "../../../HostSerialStream.h" //PFC the host serial stream data format
#include "USBSerial.h" // PFC Sept 1st 2020 new way of using existing ports!
#include <map>
#include <cstdlib>


// Declare  serial uand pc that uses UEXT interface with the isolated USB design
Serial pc(USBTX,USBRX,115200);  //This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used, or ttyUSB in Linux OSX

int main()
{

    pc.baud(115200); // setup PC comms
    pc.printf(HostSerialStreamPRINT_HEADER); // separate header to allow JBT to use in his code
while(1){
    pc.printf(HostSerialStreamFORMAT); 
    }
   
}

I've tried using the /dev/cuUSB also, but that also blocks on my MAC

LubOlimex

I think this may be unrelated to the code.

Maybe when you attach the UEXT cable after power up there is some power influence that hinders either the STM board or the attachment. This is especially true if your attached board has own power supply.

How are the two boards connected? Is it full UEXT cable that also connects 3.3V and GND?

How are the two boards powered? Does each of them have own power supply?
Technical support and documentation manager at Olimex

pculverhouse@gmail.com

Hi Lub,

The  host and the STM32 are optically isolated on the USB link when running, although I may have had the USB cable plugged directly into the MAC laptop for testing. So I guess that may have done something?

But I am puzzled that when there are no cables connecting the STM32 to the host that the STM32 code does not start, yet when I plug it into the host (certainly via an optically isolated USB2 link) that it then starts the code that does blinky.

So, I wonder what is happening? I assumed it was something in my code that was blocking on the serial port waiting for a host connection?

regards

Phil

pculverhouse@gmail.com

I forgot to make clear that the code below is at the start of the main(), before the infinite WHILE main loop. This is the powerup blinky to test the LEDS are working.

for (unsigned int i=0;i<20 ; i++) { // 10 seconds of flashing at powerup
        FP_D0_RED_ALERT=LED_TOGGLE;
        FP_D1_POWER =LED_TOGGLE; //MUST be D7--D1 is USART 1 D1 was (D0);
        FP_D2_CAMERA =LED_TOGGLE; //D2 was (D1);
        FP_D3_LED_LOW =LED_TOGGLE; // D3 was (D2);
        FP_D4_LED_HIGH =LED_TOGGLE; //D4 was (D3);
        FP_D5_FLOWMETER =LED_TOGGLE; //D6 was (D4);
        FP_D6_DEHUMIDIFIER =LED_TOGGLE; //D7 was (D5);
        FP_D8_RED_ALERT=LED_TOGGLE;
        FP_D9_GREEN_ALERT=LED_TOGGLE;
        green = LED_TOGGLE;
        wait_us(250000); // 250ms wait
        LED_TOGGLE= not(LED_TOGGLE);
    }