Serial Port for USB on the MAPLE-Mini ?

Post here first, or if you can't find a relevant section!
ranseyer
Posts: 5
Joined: Tue Feb 06, 2018 7:15 pm

Serial Port for USB on the MAPLE-Mini ?

Post by ranseyer » Tue Feb 06, 2018 7:29 pm

Hi,

i am playing with the MAPLE and i need a sketch that opens a serial communication via USB.
I thougt "Serial" will communicate via USB, and Serial1 to Serial3 communcates via RX1/TX1 to RX3/TX3...

So the question is, which port is used for USB ? I researched longer time an didnt find it...


PS: My Reference was: http://docs.leaflabs.com/static.leaflab ... -usart-map

Thanks for any help and i hope my question is not to stupid.



Part of the Sketch:

Code: Select all

// Enable debug prints to serial monitor
#define MY_DEBUG
//#define MY_DEBUG_HWSERIAL Serial // = Serial0 / Rx0 & Tx0 to programming & debug 


// Enable RS485 transport layer
#define MY_RS485
// Define this to enables DE-pin management on defined pin
#define MY_RS485_DE_PIN 11
// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 38400

// Enable this if RS485 is connected to a hardware serial port
#define MY_RS485_HWSERIAL Serial1



// Enable serial gateway
#define MY_GATEWAY_SERIAL
#define MY_SERIALDEVICE Serial // Rx* & Tx* to Gateway

User avatar
mrburnette
Posts: 2193
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Serial Port for USB on the MAPLE-Mini ?

Post by mrburnette » Tue Feb 06, 2018 8:09 pm

Serial is mapped to USB on the Maple Mini (board profile.) See below explanation.
The bootloader only provides the DFU protocol.
The Serial Protocol+USB is provided by an attachment made automatically to the sketch.
Look for the Example: https://github.com/rogerclarkmelbourne/ ... linkNcount

And try that.
More on the Maple Mini: http://wiki.stm32duino.com/index.php?ti ... onal_notes

From the Wiki: http://wiki.stm32duino.com/index.php?title=API
Serial & USB Serial
Serial USB is enabled for all F103 boards when uploading using the bootloader, it is also available when uploading by ST-Link (SWD) In these cases:

Serial.print("Hello world"); will print via Serial USB (CDC).
Serial1 prints to hardware USART 1
Serial2 prints to hardware USART 2
etc
When uploading via "Serial" (external USB to Serial adaptor connected to PA9 and PA10 (USART1) on the STM32):

Serial.print("Hello world"); will print to hardware USART1 (the one the code was uploaded using)
Serial1 prints to hardware USART 2
etc
Note. Some boards, e.g. Nucleo F103RB have special serial mapping, because these boards need to have hardware modification to make Serial usable.

The Serial <-> USART mapping is defined in file "variants/<board_name>/board.cpp".
Ray

ranseyer
Posts: 5
Joined: Tue Feb 06, 2018 7:15 pm

Re: Serial Port for USB on the MAPLE-Mini ?

Post by ranseyer » Tue Feb 06, 2018 9:20 pm

Thanks, i think it works. But my sketch is a little bit silent when there is no traffic on the gateway.

Next step is some soldering and testing. I will give more feedback after the final test...

User avatar
RogerClark
Posts: 7680
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Serial Port for USB on the MAPLE-Mini ?

Post by RogerClark » Wed Feb 07, 2018 12:08 am

Whats a "gateway"

USB Serial requires DTR to be set.

ag123
Posts: 854
Joined: Thu Jul 21, 2016 4:24 pm

Re: Serial Port for USB on the MAPLE-Mini ?

Post by ag123 » Wed Feb 07, 2018 5:35 am

i've got this sketch for a simple minded usb-serial dongle,
viewtopic.php?f=18&t=2752
i don't really implement the RS232 signals, rather i simply hard coded the interface at the uart end of it
on the usb side, the signals actually won't matter

ranseyer
Posts: 5
Joined: Tue Feb 06, 2018 7:15 pm

Re: Serial Port for USB on the MAPLE-Mini ?

Post by ranseyer » Fri Feb 09, 2018 3:28 pm

Thanks for your hints.
RogerClark wrote:
Wed Feb 07, 2018 12:08 am
Whats a "gateway"
USB Serial requires DTR to be set.

Hi,

a gateway is in my case a solution for connecting a PC or so to an RS485-Bus ((or RFM69 radio transceivers ))
https://github.com/ranseyer/MySensors-H ... ematic.png

Not the best Idea was to connect the receive und transmit Pins to 16/16 at the MAPLE.
I would be happy if there is a easy way to redifine UART 1 to this pins. Is this possible ?
-If not i would change the hardware...

User avatar
mrburnette
Posts: 2193
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Serial Port for USB on the MAPLE-Mini ?

Post by mrburnette » Fri Feb 09, 2018 5:38 pm

ranseyer wrote:
Fri Feb 09, 2018 3:28 pm
...
Not the best Idea was to connect the receive und transmit Pins to 16/16 at the MAPLE.
I would be happy if there is a easy way to redifine UART 1 to this pins. Is this possible ?
-If not i would change the hardware...

16/16 ... er, half-duplex?

Image

The default pin mapping with the current core for Maple Mini is above. We prefer in this forum to NOT reference pins ... they have mixed meaning, so talk about ports, PA2 and PA3 would be port A,2 (Tx2) and port A,3 (Rx2) ... these are the signals specified on the uC itself.

This .h file explains how the UARTS are mapped to resource pins:
https://github.com/rogerclarkmelbourne/ ... reSerial.h

In summary:

Code: Select all

#define DEFINE_HWSERIAL(name, n)                                   \
	HardwareSerial name(USART##n,                                  \
						BOARD_USART##n##_TX_PIN,                   \
						BOARD_USART##n##_RX_PIN)

#define DEFINE_HWSERIAL_UART(name, n)                             \
	HardwareSerial name(UART##n,                                  \
						BOARD_USART##n##_TX_PIN,                   \
						BOARD_USART##n##_RX_PIN)				


/* Roger clark. Changed class inheritance from Print to Stream.
 * Also added new functions for peek() and availableForWrite()
 * Note. AvailableForWrite is only a stub function in the cpp
 */
class HardwareSerial : public Stream {

public:
    HardwareSerial(struct usart_dev *usart_device,
                   uint8 tx_pin,
                   uint8 rx_pin);

    /* Set up/tear down */
    void begin(uint32 baud);
    void begin(uint32 baud,uint8_t config);
    void end();
This page shows how Leaflabs originally mapped USARTS for the Maple products.

Code: Select all

USART (serial port) related constants:

BOARD_USART1_TX_PIN, BOARD_USART2_TX_PIN, BOARD_USART3_TX_PIN: TX pins for the 3 USARTS.
BOARD_USART1_RX_PIN, BOARD_USART2_RX_PIN, BOARD_USART3_RX_PIN: RX pins for the 3 USARTS.
BOARD_UART4_TX_PIN, BOARD_UART5_TX_PIN: TX pins for UARTs 4 and 5 (high-density boards like Maple Native only).
BOARD_UART4_RX_PIN, BOARD_UART5_RX_PIN: RX pins for UARTs 4 and 5 (high-density boards like Maple Native only).
BOARD_NR_USARTS: Number of serial ports on the board. This number includes UARTs 4 and 5 if they are available.
and
reference this link: http://docs.leaflabs.com/static.leaflab ... ang-serial

Hacking:
If you are competent to dig into the core serial code, go for it but the forum almost always recommends to keep yourself out of the core code because you will break stuff on the next core update (unless extensive measures are taken to prevent code overwrite.) It's your choice but do not come crying here as I certainly will have little sympathy for your situation.

This statement on Leaflabs is no longer accurate for the STMduino core:
Unlike the Arduino, none of the Maple’s serial ports is connected to the USB port on the Maple board. If you want to communicate using the built-in USB port, use SerialUSB instead. You will need an additional USB-to-serial adapter to communicate between a USART and your computer.
Current STM32duino USB-Serial mapping:
The original Maple IDE used some non-standard API calls, including SerialUSB and also the requirement to instantiate HardwareSPI in the sketch.

SerialUSB on Maple builds has now been changed to Serial. Serial1 is Hardware serial 1, Serial2 is Hardware serial 2 etc (all 4 hardware serial channels are available)
Ray

ranseyer
Posts: 5
Joined: Tue Feb 06, 2018 7:15 pm

Re: Serial Port for USB on the MAPLE-Mini ?

Post by ranseyer » Sat Feb 10, 2018 9:55 am

Aehh, sorry thias was a typo. Pin15+16 (PB6+PB7)is connected to an MAX487 (to RS485 Interface), USB (="Serial") goes to the host.

My Question should be: is it eas possible to change the mapping ?
- via the boatloader
- via a headerfile

Result: No ! (i believe)

Fazit: I have not 10.000 PCBs, i have may only 5 left, so i change it via Hardware an fix the next version...

Thanks for the Infos.

User avatar
RogerClark
Posts: 7680
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Serial Port for USB on the MAPLE-Mini ?

Post by RogerClark » Sat Feb 10, 2018 10:08 am

PB6 and PB7 are not by default used as a Serial port

See

http://www.st.com/content/ccc/resource/ ... 161566.pdf

See page 32

You either need to use different pins or use the afio_remap function

I recall someone posted how to remap those pins

User avatar
mrburnette
Posts: 2193
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Serial Port for USB on the MAPLE-Mini ?

Post by mrburnette » Sat Feb 10, 2018 1:21 pm

RogerClark wrote:
Sat Feb 10, 2018 10:08 am
...
I recall someone posted how to remap those pins
Aargh! :o
  • In one case, the procedure failed
  • In another case, the remapping worked but 3rd party libraries failed with initialization issues
Remapping of internal fabric comes with many caveats, too many to support IMO as a forum solution.
The hardware being used is not like the PSoC where pin remapping is a graphical drag&drop operation.
Even with PSoC, some pins refuse to remap.

So, I cannot recommend remapping as a solution within the confines of this Forum. There is simply not sufficient time to work with the user's sketch, the libraries, and a frustrated user in hopes that voodoo mapping will solve an issue.


Ray

Post Reply