Skip to content
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

Fix Firmata library for STM32 #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions libraries/Firmata/Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,27 +665,23 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p) ((p) - 2)

// Nucleo STM32F429
// STM32 based boards
#elif defined(STM32)
#define TOTAL_ANALOG_PINS MAX_ANALOG_IOS //7
#define TOTAL_PINS MAX_DIGITAL_IOS //22 : All pins can be digital
#define TOTAL_PORTS 3
#define TOTAL_ANALOG_PINS MAX_ANALOG_IOS
#define TOTAL_PINS MAX_DIGITAL_IOS
#define TOTAL_PORTS MAX_NB_PORT
#define VERSION_BLINK_PIN LED_BUILTIN
#define PIN_SERIAL_RX 9
#define PIN_SERIAL_TX 8
#define PIN_SERIAL1_RX 0
#define PIN_SERIAL1_TX 1
#define PIN_SERIAL2_RX 8
#define PIN_SERIAL2_TX 9
#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
#define IS_PIN_ANALOG(p) ((p) >= 16 && (p) < TOTAL_PINS)
#define IS_PIN_PWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
#define IS_PIN_SERVO(p) IS_PIN_DIGITAL((p))
#define IS_PIN_I2C(p) ((p) == 14 || (p) == 15)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1)
// PIN_SERIALY_RX/TX defined in the variant.h
#define IS_PIN_DIGITAL(p) ((p != PIN_SERIAL_RX) && (p != PIN_SERIAL_TX) &&(p < TOTAL_PINS))
#define IS_PIN_ANALOG(p) (pin_in_pinmap(digitalToPinName(p), PinMap_ADC))
#define IS_PIN_PWM(p) (pin_in_pinmap(digitalToPinName(p), PinMap_PWM))
#define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
#define IS_PIN_I2C(p) (pin_in_pinmap(digitalToPinName(p), PinMap_I2C_SDA) || pin_in_pinmap(digitalToPinName(p), PinMap_I2C_SCL))
#define IS_PIN_SPI(p) (pin_in_pinmap(digitalToPinName(p), PinMap_SPI_MOSI) || pin_in_pinmap(digitalToPinName(p), PinMap_SPI_MISO) ||\
pin_in_pinmap(digitalToPinName(p), PinMap_SPI_SCLK) || pin_in_pinmap(digitalToPinName(p), PinMap_SPI_SSEL))
#define IS_PIN_SERIAL(p) (pin_in_pinmap(digitalToPinName(p), PinMap_UART_RX) || pin_in_pinmap(digitalToPinName(p), PinMap_UART_TX))
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 16)
#define PIN_TO_ANALOG(p) (p)
#define PIN_TO_PWM(p) (p)
#define PIN_TO_SERVO(p) (p)

Expand Down
11 changes: 7 additions & 4 deletions variants/DISCO_F407VG/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -143,8 +143,11 @@ uint32_t pinNametoPinNumber(PinName p);
#define UART_EMUL_RX PE9
#define UART_EMUL_TX PE11

//Enable Firmata
#define STM32 1
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 42
#define PIN_SERIAL_TX 3

#ifdef __cplusplus
} // extern "C"
Expand Down
4 changes: 3 additions & 1 deletion variants/DISCO_F746NG/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const PinName digital_arduino[] = {
PF8, //D19/A3
PF7, //D20/A4
PF6, //D21/A5
PI11 //D22 User btn
PI11, //D22 User btn
PB7, //D23 ST-Link Rx
PA9 //D24 ST-Link Tx
};

#ifdef __cplusplus
Expand Down
17 changes: 12 additions & 5 deletions variants/DISCO_F746NG/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern const PinName digital_arduino[];
enum {
D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
D10, D11, D12, D13, D14, D15, D16, D17, D18, D19,
D20, D21, D22,
D20, D21, D22, D23, D24,
DEND
};

Expand All @@ -66,10 +66,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -137,8 +137,15 @@ uint32_t pinNametoPinNumber(PinName p);
//#define UART_EMUL_RX PYxx
//#define UART_EMUL_TX PYxx

//Enable Firmata
#define STM32 1
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 23
#define PIN_SERIAL_TX 24
#define PIN_SERIAL1_RX 0
#define PIN_SERIAL1_TX 1
#define PIN_SERIAL2_RX 21
#define PIN_SERIAL2_TX 20

#ifdef __cplusplus
} // extern "C"
Expand Down
15 changes: 11 additions & 4 deletions variants/NUCLEO_F091RC/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -140,8 +140,15 @@ uint32_t pinNametoPinNumber(PinName p);
#define UART_EMUL_RX PB14
#define UART_EMUL_TX PB13

//Enable Firmata
#define STM32 1
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 0
#define PIN_SERIAL_TX 1
#define PIN_SERIAL1_RX 2
#define PIN_SERIAL1_TX 8
#define PIN_SERIAL2_RX 47
#define PIN_SERIAL2_TX 46

#ifdef __cplusplus
} // extern "C"
Expand Down
15 changes: 11 additions & 4 deletions variants/NUCLEO_F303RE/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -140,8 +140,15 @@ uint32_t pinNametoPinNumber(PinName p);
#define UART_EMUL_RX PC1
#define UART_EMUL_TX PC3

//Enable Firmata
#define STM32 1
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 0
#define PIN_SERIAL_TX 1
#define PIN_SERIAL1_RX 2
#define PIN_SERIAL1_TX 8
#define PIN_SERIAL2_RX 47
#define PIN_SERIAL2_TX 46

#ifdef __cplusplus
} // extern "C"
Expand Down
4 changes: 3 additions & 1 deletion variants/NUCLEO_F429ZI/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ const PinName digital_arduino[] = {
PF10, //D78/A5
PB7, //D79
PB14, //D80
PC13 //D81
PC13, //D81
PD9, //D82
PD8 //D83
};

#ifdef __cplusplus
Expand Down
15 changes: 11 additions & 4 deletions variants/NUCLEO_F429ZI/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum {
D50, D51, D52, D53, D54, D55, D56, D57, D58, D59,
D60, D61, D62, D63, D64, D65, D66, D67, D68, D69,
D70, D71, D72, D73, D74, D75, D76, D77, D78, D79,
D80, D81,
D80, D81, D82, D83,
DEND
};

Expand All @@ -72,10 +72,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -145,8 +145,15 @@ uint32_t pinNametoPinNumber(PinName p);
#define UART_EMUL_RX PF15
#define UART_EMUL_TX PE13

//Enable Firmata
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 82
#define PIN_SERIAL_TX 83
#define PIN_SERIAL1_RX 0
#define PIN_SERIAL1_TX 1
#define PIN_SERIAL2_RX 52
#define PIN_SERIAL2_TX 53

#ifdef __cplusplus
} // extern "C"
Expand Down
13 changes: 9 additions & 4 deletions variants/NUCLEO_L053R8/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -136,8 +136,13 @@ uint32_t pinNametoPinNumber(PinName p);

#define DEBUG_UART ((USART_TypeDef *) USART2)

//Enable Firmata
#define STM32 1
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 0
#define PIN_SERIAL_TX 1
#define PIN_SERIAL1_RX 2
#define PIN_SERIAL1_TX 8

#ifdef __cplusplus
} // extern "C"
Expand Down
13 changes: 9 additions & 4 deletions variants/NUCLEO_L476RG/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ enum {
AEND
};

#define MAX_ANALOG_IOS (sizeof(PinMap_ADC)/sizeof(PinMap))
#define MAX_DIGITAL_IOS DEND
#define NUM_DIGITAL_PINS MAX_DIGITAL_IOS
#define NUM_ANALOG_INPUTS (AEND - A0)
#define MAX_ANALOG_IOS (AEND - A0)
#define NUM_ANALOG_INPUTS MAX_ANALOG_IOS

// Convert a digital pin number Dxx to a PinName Pxy
#define digitalToPinName(p) ((p < NUM_DIGITAL_PINS) ? digital_arduino[p] : (STM_VALID_PINNAME(p))? (PinName)p : NC)
Expand Down Expand Up @@ -140,8 +140,13 @@ uint32_t pinNametoPinNumber(PinName p);
#define UART_EMUL_RX PB13
#define UART_EMUL_TX PB14

//Enable Firmata
#define STM32 1
// Enable Firmata
#define STM32 1
// Serial Pin Firmata
#define PIN_SERIAL_RX 0
#define PIN_SERIAL_TX 1
#define PIN_SERIAL1_RX 2
#define PIN_SERIAL1_TX 8

#ifdef __cplusplus
} // extern "C"
Expand Down