Skip to content

Make Serialx instance generic #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 6, 2017
Merged

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Oct 4, 2017

Previously Serialx instance was defined by the variant.
It was not enough generic and flexible.

With this patch, all available Serialx instance are handled dynamically.
Where 'x' is the U(S)ART number.
Currently, STM32 MCU could have up to 10 U(S)ART.

Serial is the generic name used in Arduino sketches.
Serial is now mapped to the Serialx instance linked to the com port in the variant.h (mainly one linked to ST-Link).
To define the generic Serial, define this in variant.h:

// Define here Serial instance number to map on Serial generic name
#define SERIAL_UART_INSTANCE    x //ex: 2 for Serial2 (USART2)

Moreover this will simplify USB integration to map the SerialUSB as Serial.

Menu has been review, 4 options:
Generic Serial (default): only the Serialx instance linked to the com port is available.
No Serial: Serial is disabled (useful for sketch which not use Serial)
Fisrt third: Instanciate the first third Serial instance (USART1 to 3)
All: Instantiate all available U(S)ART (up to 10)

SerialxEvent() are weak and could be redefined by the user at sketch level.

Depends of #121
Fixed #113

@fpistm fpistm added the enhancement New feature or request label Oct 4, 2017
@fpistm fpistm self-assigned this Oct 4, 2017
@fpistm fpistm requested review from VVESTM and a user October 4, 2017 07:55
@fpistm fpistm added this to the Next release milestone Oct 4, 2017
@fpistm fpistm force-pushed the genericSerial branch 2 times, most recently from e32c2c4 to f04a44e Compare October 4, 2017 12:33
fpistm added 8 commits October 6, 2017 10:29
Usage example:
  PinNamepin_rx = pinmap_pin(USART1, PinMap_UART_RX);
  PinNamepin_tx = pinmap_pin(USART1, PinMap_UART_TX);

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Previously Serialx instance was defined by the variant.
It was not enough generic and flexible.

With this patch, all available Serialx instance are handled dynamically.
Where 'x' is the U(S)ART number.
Currently, STM32 MCU could have 9 U(S)ART.

Serial is the generic name used in Arduino sketches.
Serial is now mapped to the Serialx instance linked
to the com port in the variant.h (mainly one linked to ST-Link)
Moreover this will simplify USB integration to map the SerialUSB.

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
When Serialx instanciation, check if it is the generic 'Serial'
then set Rx/Tx pins if defined else get the pins of the first
peripheral occurence in PinMap

Anyway, Rx/Tx pins could be changed later using Serialx.setRx/setTx
methods before call the Serialx.begin()

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
By default, UART_DEBUG is linked to Serial generic instance.
So it is not required to define it.
It could be redefined in the variant.h to print on another
instance than Serial

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
As HardwareSerial is no more used in variant, use pins_arduino.h instead of Arduino.h

Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on some boards and that seems to be OK.

@fpistm fpistm merged commit 0f002a3 into stm32duino:master Oct 6, 2017
@fpistm fpistm deleted the genericSerial branch October 6, 2017 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant