Skip to content

Commit 28d7818

Browse files
2 parents 6561310 + f8e8a7b commit 28d7818

File tree

10 files changed

+1819
-1721
lines changed

10 files changed

+1819
-1721
lines changed

boards.txt

Lines changed: 1699 additions & 1699 deletions
Large diffs are not rendered by default.

cores/rp2040/SerialUART.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,39 @@ bool SerialUART::setTX(pin_size_t pin) {
6565
return false;
6666
}
6767

68+
bool SerialUART::setRTS(pin_size_t pin) {
69+
constexpr uint32_t valid[2] = { __bitset({3, 15, 19}) /* UART0 */,
70+
__bitset({7, 11, 23, 27}) /* UART1 */
71+
};
72+
if ((!_running) && ((1 << pin) & valid[uart_get_index(_uart)])) {
73+
_rts = pin;
74+
return true;
75+
}
76+
77+
if (_running) {
78+
panic("FATAL: Attempting to set Serial%d.RTS while running", uart_get_index(_uart) + 1);
79+
} else {
80+
panic("FATAL: Attempting to set Serial%d.RTS to illegal pin %d", uart_get_index(_uart) + 1, pin);
81+
}
82+
return false;
83+
}
84+
85+
bool SerialUART::setCTS(pin_size_t pin) {
86+
constexpr uint32_t valid[2] = { __bitset({2, 14, 18}) /* UART0 */,
87+
__bitset({6, 10, 22, 26}) /* UART1 */
88+
};
89+
if ((!_running) && ((1 << pin) & valid[uart_get_index(_uart)])) {
90+
_cts = pin;
91+
return true;
92+
}
93+
94+
if (_running) {
95+
panic("FATAL: Attempting to set Serial%d.CTS while running", uart_get_index(_uart) + 1);
96+
} else {
97+
panic("FATAL: Attempting to set Serial%d.CTS to illegal pin %d", uart_get_index(_uart) + 1, pin);
98+
}
99+
return false;
100+
}
68101
bool SerialUART::setPollingMode(bool mode) {
69102
if (_running) {
70103
return false;
@@ -85,6 +118,8 @@ SerialUART::SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx) {
85118
_uart = uart;
86119
_tx = tx;
87120
_rx = rx;
121+
_rts = UART_PIN_NOT_DEFINED;
122+
_cts = UART_PIN_NOT_DEFINED;
88123
mutex_init(&_mutex);
89124
}
90125

@@ -133,6 +168,13 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
133168
uart_set_format(_uart, bits, stop, parity);
134169
gpio_set_function(_tx, GPIO_FUNC_UART);
135170
gpio_set_function(_rx, GPIO_FUNC_UART);
171+
if (_rts != UART_PIN_NOT_DEFINED) {
172+
gpio_set_function(_rts, GPIO_FUNC_UART);
173+
}
174+
if (_cts != UART_PIN_NOT_DEFINED) {
175+
gpio_set_function(_cts, GPIO_FUNC_UART);
176+
}
177+
uart_set_hw_flow(_uart, _rts != UART_PIN_NOT_DEFINED, _cts != UART_PIN_NOT_DEFINED);
136178
_writer = 0;
137179
_reader = 0;
138180

cores/rp2040/SerialUART.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828

2929
extern "C" typedef struct uart_inst uart_inst_t;
3030

31+
#define UART_PIN_NOT_DEFINED (255u)
3132
class SerialUART : public HardwareSerial {
3233
public:
3334
SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx);
3435

3536
// Select the pinout. Call before .begin()
3637
bool setRX(pin_size_t pin);
3738
bool setTX(pin_size_t pin);
39+
bool setRTS(pin_size_t pin);
40+
bool setCTS(pin_size_t pin);
3841
bool setPinout(pin_size_t tx, pin_size_t rx) {
3942
bool ret = setRX(rx);
4043
ret &= setTX(tx);
@@ -66,6 +69,7 @@ class SerialUART : public HardwareSerial {
6669
bool _running = false;
6770
uart_inst_t *_uart;
6871
pin_size_t _tx, _rx;
72+
pin_size_t _rts, _cts;
6973
int _baud;
7074
mutex_t _mutex;
7175
bool _polling = false;

docs/pins.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Serial1 (UART0), Serial2 (UART1)
2626
2727
::setRX(pin)
2828
::setTX(pin)
29+
::setRTS(pin)
30+
::setCTS(pin)
2931
3032
SPI (SPI0), SPI1 (SPI1)
3133
-----------------------
@@ -58,4 +60,3 @@ it use a non-default pinout with a simple call
5860
SPI.setCS(5);
5961
SD.begin(5);
6062
}
61-

libraries/PDM/src/PDM.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class PDMClass
5858
int _gain;
5959
int _init;
6060

61+
// Hardware peripherals used
62+
uint _dmaChannel;
63+
PIO _pio;
64+
int _smIdx;
65+
int _pgmOffset;
66+
6167
PDMDoubleBuffer _doubleBuffer;
6268

6369
void (*_onReceive)(void);

libraries/PDM/src/rp2040/PDM.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ extern "C" {
1111
}
1212
#include "hardware/sync.h"
1313
#include "pdm.pio.h"
14-
15-
// Hardware peripherals used
16-
uint dmaChannel = 0;
17-
PIO pio = pio0;
18-
uint sm = 0;
14+
static PIOProgram _pdmPgm(&pdm_pio_program);
1915

2016
// raw buffers contain PDM data
2117
#define RAW_BUFFER_SIZE 512 // should be a multiple of (decimation / 8)
@@ -49,7 +45,11 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
4945
_gain(-1),
5046
_channels(-1),
5147
_samplerate(-1),
52-
_init(-1)
48+
_init(-1),
49+
_dmaChannel(0),
50+
_pio(nullptr),
51+
_smIdx(-1),
52+
_pgmOffset(-1)
5353
{
5454
}
5555

@@ -89,29 +89,35 @@ int PDMClass::begin(int channels, int sampleRate)
8989

9090
// Configure PIO state machine
9191
float clkDiv = (float)clock_get_hz(clk_sys) / sampleRate / decimation / 2;
92-
uint offset = pio_add_program(pio, &pdm_pio_program);
93-
pdm_pio_program_init(pio, sm, offset, _clkPin, _dinPin, clkDiv);
92+
93+
if (!_pdmPgm.prepare(&_pio, &_smIdx, &_pgmOffset)) {
94+
// ERROR, no free slots
95+
return -1;
96+
}
97+
pdm_pio_program_init(_pio, _smIdx, _pgmOffset, _clkPin, _dinPin, clkDiv);
9498

9599
// Wait for microphone
96100
delay(100);
97101

98102
// Configure DMA for transferring PIO rx buffer to raw buffers
99-
dma_channel_config c = dma_channel_get_default_config(dmaChannel);
103+
_dmaChannel = dma_claim_unused_channel(false);
104+
dma_channel_config c = dma_channel_get_default_config(_dmaChannel);
100105
channel_config_set_read_increment(&c, false);
101106
channel_config_set_write_increment(&c, true);
102-
channel_config_set_dreq(&c, pio_get_dreq(pio, sm, false));
107+
channel_config_set_dreq(&c, pio_get_dreq(_pio, _smIdx, false));
103108
channel_config_set_transfer_data_size(&c, DMA_SIZE_8);
104109

105110
// Clear DMA interrupts
106-
dma_hw->ints0 = 1u << dmaChannel;
111+
dma_hw->ints0 = 1u << _dmaChannel;
107112
// Enable DMA interrupts
108-
dma_channel_set_irq0_enabled(dmaChannel, true);
109-
irq_set_exclusive_handler(DMA_IRQ_0, dmaHandler);
113+
dma_channel_set_irq0_enabled(_dmaChannel, true);
114+
// Share but allocate a high priority to the interrupt
115+
irq_add_shared_handler(DMA_IRQ_0, dmaHandler, 0);
110116
irq_set_enabled(DMA_IRQ_0, true);
111117

112-
dma_channel_configure(dmaChannel, &c,
118+
dma_channel_configure(_dmaChannel, &c,
113119
rawBuffer[rawBufferIndex], // Destinatinon pointer
114-
&pio->rxf[sm], // Source pointer
120+
&_pio->rxf[_smIdx], // Source pointer
115121
RAW_BUFFER_SIZE, // Number of transfers
116122
true // Start immediately
117123
);
@@ -123,7 +129,7 @@ int PDMClass::begin(int channels, int sampleRate)
123129

124130
void PDMClass::end()
125131
{
126-
dma_channel_abort(dmaChannel);
132+
dma_channel_abort(_dmaChannel);
127133
pinMode(_clkPin, INPUT);
128134
}
129135

@@ -171,10 +177,10 @@ void PDMClass::IrqHandler(bool halftranfer)
171177
static int cutSamples = 100;
172178

173179
// Clear the interrupt request.
174-
dma_hw->ints0 = 1u << dmaChannel;
180+
dma_hw->ints0 = 1u << _dmaChannel;
175181
// Restart dma pointing to the other buffer
176182
int shadowIndex = rawBufferIndex ^ 1;
177-
dma_channel_set_write_addr(dmaChannel, rawBuffer[shadowIndex], true);
183+
dma_channel_set_write_addr(_dmaChannel, rawBuffer[shadowIndex], true);
178184

179185
if (_doubleBuffer.available()) {
180186
// buffer overflow, stop

libraries/PDM/src/rp2040/pdm.pio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static inline void pdm_pio_program_init(PIO pio, uint sm, uint offset, uint clkP
2626
sm_config_set_in_pins(&c, dataPin);
2727
sm_config_set_sideset_pins(&c, clkPin);
2828
sm_config_set_clkdiv(&c, clkDiv);
29+
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
2930

3031
pio_sm_set_consecutive_pindirs(pio, sm, dataPin, 1, false);
3132
pio_sm_set_consecutive_pindirs(pio, sm, clkPin, 1, true);

libraries/PDM/src/rp2040/pdm.pio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static inline void pdm_pio_program_init(PIO pio, uint sm, uint offset, uint clkP
4343
sm_config_set_in_pins(&c, dataPin);
4444
sm_config_set_sideset_pins(&c, clkPin);
4545
sm_config_set_clkdiv(&c, clkDiv);
46+
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
4647
pio_sm_set_consecutive_pindirs(pio, sm, dataPin, 1, false);
4748
pio_sm_set_consecutive_pindirs(pio, sm, clkPin, 1, true);
4849
pio_sm_set_pins_with_mask(pio, sm, 0, (1u << clkPin) );

tools/makeboards.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,56 @@ def MakeBoardJSON(name, vendor_name, product_name, vid, pid, pwr, boarddefine, f
217217
sys.stdout = open(os.path.abspath(os.path.dirname(__file__)) + "/../boards.txt", "w")
218218
WriteWarning()
219219
BuildGlobalMenuList()
220+
221+
# Note to new board manufacturers: Please add your board so that it sorts
222+
# alphabetically starting with the company name and then the board name.
223+
# Otherwise it is difficult to find a specific board in the menu.
224+
225+
# Raspberry Pi
220226
MakeBoard("rpipico", "Raspberry Pi", "Pico", "0x2e8a", "0x000a", 250, "RASPBERRY_PI_PICO", 2, "boot2_w25q080_2_padded_checksum")
227+
228+
# Adafruit
221229
MakeBoard("adafruit_feather", "Adafruit", "Feather RP2040", "0x239a", "0x80f1", 250, "ADAFRUIT_FEATHER_RP2040", 8, "boot2_w25x10cl_4_padded_checksum")
222230
MakeBoard("adafruit_itsybitsy", "Adafruit", "ItsyBitsy RP2040", "0x239a", "0x80fd", 250, "ADAFRUIT_ITSYBITSY_RP2040", 8, "boot2_w25q080_2_padded_checksum")
223231
MakeBoard("adafruit_qtpy", "Adafruit", "QT Py RP2040", "0x239a", "0x80f7", 250, "ADAFRUIT_QTPY_RP2040", 8, "boot2_w25q080_2_padded_checksum")
224232
MakeBoard("adafruit_stemmafriend", "Adafruit", "STEMMA Friend RP2040", "0x239a", "0x80e3", 250, "ADAFRUIT_STEMMAFRIEND_RP2040", 8, "boot2_w25q080_2_padded_checksum")
225233
MakeBoard("adafruit_trinkeyrp2040qt", "Adafruit", "Trinkey RP2040 QT", "0x239a", "0x8109", 250, "ADAFRUIT_TRINKEYQT_RP2040", 8, "boot2_w25q080_2_padded_checksum")
226234
MakeBoard("adafruit_macropad2040", "Adafruit", "MacroPad RP2040", "0x239a", "0x8107", 250, "ADAFRUIT_MACROPAD_RP2040", 8, "boot2_w25q080_2_padded_checksum")
227235
MakeBoard("adafruit_kb2040", "Adafruit", "KB2040", "0x239a", "0x8105", 250, "ADAFRUIT_KB2040_RP2040", 8, "boot2_w25q080_2_padded_checksum")
236+
237+
# Arduino
228238
MakeBoard("arduino_nano_connect", "Arduino", "Nano RP2040 Connect", "0x2341", "0x0058", 250, "NANO_RP2040_CONNECT", 16, "boot2_w25q080_2_padded_checksum")
239+
240+
# Cytron
229241
MakeBoard("cytron_maker_nano_rp2040", "Cytron", "Maker Nano RP2040", "0x2e8a", "0x100f", 250, "CYTRON_MAKER_NANO_RP2040", 2, "boot2_w25q080_2_padded_checksum")
230242
MakeBoard("cytron_maker_pi_rp2040", "Cytron", "Maker Pi RP2040", "0x2e8a", "0x1000", 250, "CYTRON_MAKER_PI_RP2040", 2, "boot2_w25q080_2_padded_checksum")
231-
MakeBoard("sparkfun_promicrorp2040", "SparkFun", "ProMicro RP2040", "0x1b4f", "0x0026", 250, "SPARKFUN_PROMICRO_RP2040", 16, "boot2_generic_03h_4_padded_checksum")
232-
MakeBoard("generic", "Generic", "RP2040", "0x2e8a", "0xf00a", 250, "GENERIC_RP2040", 16, "boot2_generic_03h_4_padded_checksum")
243+
244+
# DeRuiLab
245+
MakeBoard("flyboard2040_core", "DeRuiLab", "FlyBoard2040Core", "0x2e8a", "0x008a", 500, "FLYBOARD2040_CORE", 4, "boot2_generic_03h_4_padded_checksum")
246+
247+
# iLabs
233248
MakeBoard("challenger_2040_lora", "iLabs", "Challenger 2040 LoRa", "0x2e8a", "0x1023", 250, "CHALLENGER_2040_LORA_RP2040", 8, "boot2_w25q080_2_padded_checksum")
234249
MakeBoard("challenger_2040_wifi", "iLabs", "Challenger 2040 WiFi", "0x2e8a", "0x1006", 250, "CHALLENGER_2040_WIFI_RP2040", 8, "boot2_w25q080_2_padded_checksum")
235250
MakeBoard("challenger_2040_lte", "iLabs", "Challenger 2040 LTE", "0x2e8a", "0x100b", 500, "CHALLENGER_2040_LTE_RP2040", 8, "boot2_w25q080_2_padded_checksum")
236251
MakeBoard("challenger_nb_2040_wifi", "iLabs", "Challenger NB 2040 WiFi", "0x2e8a", "0x100b", 500, "CHALLENGER_NB_2040_WIFI_RP2040", 8, "boot2_w25q080_2_padded_checksum")
237252
MakeBoard("ilabs_rpico32", "iLabs", "RPICO32", "0x2e8a", "0x1010", 250, "ILABS_2040_RPICO32_RP2040", 8, "boot2_w25q080_2_padded_checksum")
253+
254+
# Melopera
238255
MakeBoard("melopero_shake_rp2040", "Melopero", "Shake RP2040", "0x2e8a", "0x1005", 250, "MELOPERO_SHAKE_RP2040", 16, "boot2_w25q080_2_padded_checksum")
256+
257+
# Solder Party
239258
MakeBoard("solderparty_rp2040_stamp", "Solder Party", "RP2040 Stamp", "0x1209", "0xa182", 500, "SOLDERPARTY_RP2040_STAMP", 8, "boot2_generic_03h_4_padded_checksum")
259+
260+
# SparkFun
261+
MakeBoard("sparkfun_promicrorp2040", "SparkFun", "ProMicro RP2040", "0x1b4f", "0x0026", 250, "SPARKFUN_PROMICRO_RP2040", 16, "boot2_generic_03h_4_padded_checksum")
262+
263+
# Upesy
240264
MakeBoard("upesy_rp2040_devkit", "uPesy", "RP2040 DevKit", "0x2e8a", "0x1007", 250, "UPESY_RP2040_DEVKIT", 2, "boot2_w25q080_2_padded_checksum")
265+
266+
# WIZnet
241267
MakeBoard("wiznet_5100s_evb_pico", "WIZnet", "W5100S-EVB-Pico", "0x2e8a", "0x1008", 250, "WIZNET_5100S_EVB_PICO", 2, "boot2_w25q080_2_padded_checksum")
242-
MakeBoard("flyboard2040_core", "DeRuiLab", "FlyBoard2040Core", "0x2e8a", "0x008a", 500, "FLYBOARD2040_CORE", 4, "boot2_generic_03h_4_padded_checksum")
268+
269+
# Generic
270+
MakeBoard("generic", "Generic", "RP2040", "0x2e8a", "0xf00a", 250, "GENERIC_RP2040", 16, "boot2_generic_03h_4_padded_checksum")
271+
243272
sys.stdout.close()

variants/challenger_2040_lora/pins_arduino.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#define PIN_SPI1_MOSI (11u)
2525
#define PIN_SPI1_SCK (10u)
2626
#define PIN_SPI1_SS (9u)
27+
#define RFM95W_SS (9u)
28+
#define RFM95W_DIO0 (14u)
29+
#define RFM95W_DIO1 (15u)
30+
#define RFM95W_DIO2 (18u)
31+
#define RFM95W_RST (13u)
32+
#define RFM95W_SPI SPI1
2733

2834
// Wire
2935
#define PIN_WIRE0_SDA (0u)
@@ -32,6 +38,8 @@
3238
// Not pinned out
3339
#define PIN_WIRE1_SDA (31u)
3440
#define PIN_WIRE1_SCL (31u)
41+
#define PIN_SERIAL2_RX (31u)
42+
#define PIN_SERIAL2_TX (31u)
3543

3644
#define SERIAL_HOWMANY (1u)
3745
#define SPI_HOWMANY (2u)

0 commit comments

Comments
 (0)