File tree Expand file tree Collapse file tree 9 files changed +225
-0
lines changed Expand file tree Collapse file tree 9 files changed +225
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,11 @@ def build(env):
104
104
tusb_config ["CFG_TUSB_MCU" ] = "OPT_MCU_SAM{}{}" .format (target .family .upper (), target .series .upper ())
105
105
env .copy ("tinyusb/src/portable/microchip/samd/" , "portable/microchip/samd/" )
106
106
107
+ elif target .platform == "rp" :
108
+ if target .family == "20" :
109
+ tusb_config ["CFG_TUSB_MCU" ] = "OPT_MCU_RP2040"
110
+ env .copy ("tinyusb/src/portable/raspberrypi/rp2040/" , "portable/raspberrypi/rp2040/" )
111
+
107
112
if env .has_module (":freertos" ):
108
113
tusb_config ["CFG_TUSB_OS" ] = "OPT_OS_FREERTOS"
109
114
env .copy ("tinyusb/src/osal/osal_freertos.h" , "osal/osal_freertos.h" )
@@ -165,6 +170,8 @@ def build(env):
165
170
irqs = irq_data ["port_irqs" ][speed ]
166
171
elif target .platform == "sam" and target .family in ["g" ]:
167
172
irqs = ["UDP" ]
173
+ elif target .platform == "rp" and target .family in ["20" ]:
174
+ irqs = ["USBCTRL_IRQ" ]
168
175
else :
169
176
irqs = ["USB" ]
170
177
Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ tusb_get_device_serial(uint16_t *serial_str)
40
40
(uint32_t *)0x0080A00C, (uint32_t *)0x0080A040,
41
41
(uint32_t *)0x0080A044, (uint32_t *)0x0080A048
42
42
%% endif
43
+ %% elif target.platform in ["rp"]
44
+ /* sysinfo CHIP_ID and GIT_REV */
45
+ ((uint32_t *)0x40000000),((uint32_t *)0x40000040),
46
+ ((uint32_t *)0x40000000),((uint32_t *)0x40000040),
43
47
%% endif
44
48
};
45
49
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, Andrey Kunitsyn
3
+ *
4
+ * This file is part of the modm project.
5
+ *
6
+ * This Source Code Form is subject to the terms of the Mozilla Public
7
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+ // ----------------------------------------------------------------------------
11
+
12
+ #pragma once
13
+
14
+ /**
15
+ * Pico SDK compatibility for tinyusb
16
+ */
17
+ #include "hardware/regs/intctrl.h"
18
+
19
+ static inline void
20
+ irq_set_enabled (int irqn , bool enable )
21
+ {
22
+ if (enable ) NVIC_EnableIRQ (irqn );
23
+ else NVIC_DisableIRQ (irqn );
24
+ }
25
+
26
+ static inline void
27
+ irq_set_exclusive_handler (int irqn , void (* handler )())
28
+ {
29
+ (void )irqn ;
30
+ (void )handler ;
31
+ // do nothing, irq implemented at modm
32
+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,15 @@ def build(env):
38
38
env .copy ("pico-sdk/include" , "" )
39
39
env .copy ("address_mapped.h" , "hardware/address_mapped.h" )
40
40
41
+ if env .has_module (":tinyusb" ):
42
+ env .substitutions = {
43
+ "with_debug" : env .has_module (":debug" )
44
+ }
45
+ env .copy ("pico.h" )
46
+ env .template ("pico.cpp.in" , "pico.cpp" )
47
+ env .copy ("irq.h" , "hardware/irq.h" )
48
+ env .copy ("resets.h" , "hardware/resets.h" )
49
+
41
50
env .substitutions = {
42
51
"headers" : headers ,
43
52
"defines" : defines ,
Original file line number Diff line number Diff line change
1
+ #include "pico.h"
2
+ #include "hardware/resets.h"
3
+
4
+ #include <modm/platform/core/resets.hpp>
5
+ %% if with_debug
6
+ #include <modm/debug.hpp>
7
+ %% endif
8
+
9
+ /**
10
+ * Pico SDK compatibility for tinyusb
11
+ */
12
+
13
+ extern "C" void reset_block(uint32_t blocks)
14
+ {
15
+ modm::platform::Resets::reset(blocks);
16
+ }
17
+ extern "C" void unreset_block_wait(uint32_t blocks)
18
+ {
19
+ modm::platform::Resets::unresetWait(blocks);
20
+ }
21
+
22
+ extern "C" void panic(const char *fmt, ...)
23
+ {
24
+ %% if with_debug
25
+ va_list va;
26
+ va_start(va, fmt);
27
+ modm::log::info.vprintf(fmt, va);
28
+ va_end(va);
29
+ %% endif
30
+ modm_assert(0, "pico", "Pico-SDK panic!");
31
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, Andrey Kunitsyn
3
+ *
4
+ * This file is part of the modm project.
5
+ *
6
+ * This Source Code Form is subject to the terms of the Mozilla Public
7
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+ // ----------------------------------------------------------------------------
11
+
12
+ #pragma once
13
+
14
+ /**
15
+ * Pico SDK compatibility for tinyusb
16
+ */
17
+
18
+ #include <modm/architecture/interface/assert.h>
19
+ #include <stdint.h>
20
+ /* need for static_assert at C compilation */
21
+ #include <assert.h>
22
+ #define TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX 0
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+ /* override expensive assert implementation */
28
+ #undef assert
29
+ #define assert (X ) modm_assert((X), "pico", __FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #X "\"")
30
+ void
31
+ panic (const char * fmt , ...);
32
+
33
+ #ifdef __cplusplus
34
+ }
35
+ #endif
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, Andrey Kunitsyn
3
+ *
4
+ * This file is part of the modm project.
5
+ *
6
+ * This Source Code Form is subject to the terms of the Mozilla Public
7
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+ // ----------------------------------------------------------------------------
11
+
12
+ #pragma once
13
+
14
+ /**
15
+ * Pico SDK compatibility for tinyusb
16
+ */
17
+ #include "hardware/structs/resets.h"
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+ void
24
+ reset_block (uint32_t blocks );
25
+ void
26
+ unreset_block_wait (uint32_t blocks );
27
+
28
+ #ifdef __cplusplus
29
+ }
30
+ #endif
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright (c) 2022, Andrey Kunitsyn
5
+ #
6
+ # This file is part of the modm project.
7
+ #
8
+ # This Source Code Form is subject to the terms of the Mozilla Public
9
+ # License, v. 2.0. If a copy of the MPL was not distributed with this
10
+ # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11
+ # -----------------------------------------------------------------------------
12
+
13
+ # -----------------------------------------------------------------------------
14
+ def init (module ):
15
+ module .name = ":platform:usb"
16
+ module .description = "Universal Serial Bus (USB)"
17
+
18
+ def prepare (module , options ):
19
+ device = options [":target" ]
20
+ if not device .has_driver ("usb:rp20*" ):
21
+ return False
22
+
23
+
24
+ module .depends (
25
+ ":architecture:interrupt" ,
26
+ ":cmsis:device" ,
27
+ ":platform:gpio" )
28
+
29
+ return True
30
+
31
+ def build (env ):
32
+ env .outbasepath = "modm/src/modm/platform/usb"
33
+ env .copy ('usb.hpp' )
34
+ if env .has_module (":tinyusb:device:cdc" ):
35
+ env .copy (repopath ("ext/hathach/uart.hpp" ), "uart.hpp" )
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022, Andrey Kunitsyn
3
+ *
4
+ * This file is part of the modm project.
5
+ *
6
+ * This Source Code Form is subject to the terms of the Mozilla Public
7
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+ // ----------------------------------------------------------------------------
11
+
12
+ #pragma once
13
+
14
+ #include < modm/platform/device.hpp>
15
+ #include < modm/platform/gpio/connector.hpp>
16
+
17
+ namespace modm ::platform
18
+ {
19
+
20
+ // / @ingroup modm_platform_usb
21
+ class Usb
22
+ {
23
+ public:
24
+ template <class SystemClock >
25
+ static void
26
+ initialize (uint8_t priority = 3 )
27
+ {
28
+ static_assert (SystemClock::UsbFrequency == 48_MHz, " USB must have a 48MHz clock!" );
29
+ NVIC_SetPriority (USBCTRL_IRQ_IRQn, priority);
30
+ }
31
+
32
+ template <class ... Signals>
33
+ static void
34
+ connect ()
35
+ {
36
+ using Connector = GpioConnector<Peripheral::Usb, Signals...>;
37
+ // Dp, Dm use dedicated pins, but Vbus and Overcurrent can be connected
38
+ Connector::connect ();
39
+ }
40
+ };
41
+
42
+ } // namespace modm::platform
You can’t perform that action at this time.
0 commit comments