Skip to content

Commit

Permalink
Add support for rp2350 micro-controllers (#6725) (#455)
Browse files Browse the repository at this point in the history
* lib: Move lib/rp2040/elf2uf2 to lib/elf2uf2

Recent versions of the rp2040 sdk no longer contain the elf2uf2 tool.
So, move that code to a new dedicated directory.  This is in
preparation for updating the rp2040 sdk version.

Signed-off-by: Kevin O'Connor <[email protected]>

* lib: Update lib/rp2040 to v2.0.0 SDK release

Signed-off-by: Kevin O'Connor <[email protected]>

* lib: Update can2040 to support v2.0.0 of pico-sdk

A new version of can2040 is needed due to changes in the 2.0.0 release
of the pico-sdk.

Signed-off-by: Kevin O'Connor <[email protected]>

* lib: Add rp2350 files to pico-sdk

Signed-off-by: Kevin O'Connor <[email protected]>

* lib: Add cortex-m33 support files to lib/cmsis-core/

This is in preparation for adding support for rp2350 mcus.

Signed-off-by: Kevin O'Connor <[email protected]>

* armcm_boot: Support ARM cortex-m33 chips

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Rename CONFIG_RP2040_yyy Kconfig symbols to CONFIG_RPXXXX_yyy

Rename the Kconfig symbols.  This is in preparation to adding support
for the rp2350 mcu.

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Rename rp2040_link.lds.S to rpxxxx_link.lds.S

This is in preparation for rp2350 support.

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Avoid using memcpy() on USB dpram

Some versions of the system memcpy() may make unaligned memory
accesses, which can result in a bus fault when accessing the usb dpram
device memory.

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Use a higher USB PLL internal frequency

The rp2350 chip requires a higher internal frequency, so choose a
value that works for both rp2040 and rp2350.

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Initial rp2350 support

Signed-off-by: Kevin O'Connor <[email protected]>

* lib: Update rp2040_flash to upstream picotool.git v2.0.0

This is in preparation for adding rp2350 flash support.

Signed-off-by: Kevin O'Connor <[email protected]>

* lib: Update rp2040_flash code to support rp2350 reboot

Signed-off-by: Kevin O'Connor <[email protected]>

* flash_usb: Initial support for flashing rp2350 chips

Signed-off-by: Kevin O'Connor <[email protected]>

* temperature_mcu: Add support for rp2350 MCUs

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Move chipid reading to bootrom.c

Rewrite chipid.c so that it contains just the USB and canbus id
manipulation code.  Move the low-level chipid reading to bootrom.c.

Also, introduce a new bootrom_reboot_usb_bootloader() function in
bootrom.c so that the main.c code does not need to know the specifics
of rebooting into the bootrom.

Signed-off-by: Kevin O'Connor <[email protected]>

* rp2040: Add rp2350 bootrom based chipid and reboot to bootloader code

This adds the bootrom code needed to implement "reboot into
bootloader" and "chipid" capabilities.

Signed-off-by: Kevin O'Connor <[email protected]>

* docs: Add rp2350 to benchmarks

Signed-off-by: Kevin O'Connor <[email protected]>

---------

Signed-off-by: Kevin O'Connor <[email protected]>
Co-authored-by: Kevin O'Connor <[email protected]>
  • Loading branch information
rogerlz and KevinOConnor authored Dec 5, 2024
1 parent b2b6c6b commit 119023e
Show file tree
Hide file tree
Showing 276 changed files with 146,762 additions and 8,562 deletions.
26 changes: 19 additions & 7 deletions docs/Benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ micro-controller.
| 1 stepper | 85 |
| 3 stepper | 359 |

### RP2040 step rate benchmark
### RPxxxx step rate benchmark

The following configuration sequence is used on the RP2040:
The following configuration sequence is used on the RP2040 and RP2350:

```
allocate_oids count=3
Expand All @@ -408,15 +408,26 @@ config_stepper oid=2 step_pin=gpio27 dir_pin=gpio5 invert_step=-1 step_pulse_tic
finalize_config crc=0
```

The test was last run on commit `59314d99` with gcc version
`arm-none-eabi-gcc (Fedora 10.2.0-4.fc34) 10.2.0` on a Raspberry Pi
Pico board.
The test was last run on commit `f6718291` with gcc version
`arm-none-eabi-gcc (Fedora 14.1.0-1.fc40) 14.1.0` on Raspberry Pi
Pico and Pico 2 boards.

| rp2040 | ticks |
| rp2040 (*) | ticks |
| -------------------- | ----- |
| 1 stepper | 5 |
| 3 stepper | 22 |

| rp2350 | ticks |
| -------------------- | ----- |
| 1 stepper | 36 |
| 3 stepper | 169 |

(*) Note that the reported rp2040 ticks are relative to a 12Mhz
scheduling timer and do not correspond to its 125Mhz internal ARM
processing rate. It is expected that 5 scheduling ticks corresponds to
~47 ARM core cycles and 22 scheduling ticks corresponds to ~224 ARM
core cycles.

### Linux MCU step rate benchmark

The following configuration sequence is used on a Raspberry Pi:
Expand Down Expand Up @@ -477,7 +488,8 @@ hub.
| sam4s8c (USB) | 650K | 8d4a5c16 | arm-none-eabi-gcc (Fedora 7.4.0-1.fc30) 7.4.0 |
| samd51 (USB) | 864K | 01d2183f | arm-none-eabi-gcc (Fedora 7.4.0-1.fc30) 7.4.0 |
| stm32f446 (USB) | 870K | 01d2183f | arm-none-eabi-gcc (Fedora 7.4.0-1.fc30) 7.4.0 |
| rp2040 (USB) | 873K | c5667193 | arm-none-eabi-gcc (Fedora 10.2.0-4.fc34) 10.2.0 |
| rp2040 (USB) | 885K | f6718291 | arm-none-eabi-gcc (Fedora 14.1.0-1.fc40) 14.1.0 |
| rp2350 (USB) | 885K | f6718291 | arm-none-eabi-gcc (Fedora 14.1.0-1.fc40) 14.1.0 |

## Host Benchmarks

Expand Down
1 change: 1 addition & 0 deletions docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ represent total number of steps per second on the micro-controller.
| AR100 | 3529K | 2507K |
| STM32F407 | 3652K | 2459K |
| STM32F446 | 3913K | 2634K |
| RP2350 | 4167K | 2663K |
| SAME70 | 6667K | 4737K |
| STM32H743 | 9091K | 6061K |

Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/temperature_mcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _build_config(self):
self.mcu_type = _mcu.get_constants().get("MCU", "")
# Run MCU specific configuration
cfg_funcs = [
("rp2040", self.config_rp2040),
("rp2", self.config_rp2040),
("sam3", self.config_sam3),
("sam4", self.config_sam4),
("same70", self.config_same70),
Expand Down
17 changes: 12 additions & 5 deletions lib/README
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,23 @@ The stm32h7 directory contains code from:
version v1.9.0 (ccb11556044540590ca6e45056e6b65cdca2deb2). Contents
taken from the Drivers/CMSIS/Device/ST/STM32H7xx/ directory.

The rp2040 directory contains code from the pico sdk:
The pico-sdk directory contains code from the pico sdk:
https://github.com/raspberrypi/pico-sdk.git
version 1.2.0 (bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7). It has been
version 2.0.0 (efe2103f9b28458a1615ff096054479743ade236). It has been
modified so that it can build outside of the pico sdk. See
rp2040.patch for the modifications.
pico-sdk.patch for the modifications.

The elf2uf2 directory contains code from the pico sdk:
https://github.com/raspberrypi/pico-sdk.git
version 1.2.0 (bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7). Contents
taken from the tools/elf2uf2/ directory.

The rp2040_flash directory contains a light-weight bootsel flash tool.
It uses C part of the the `picoboot_connection` directory found in:
https://github.com/raspberrypi/picotool.git
version v1.1.0 (55fd880c3dc029b961fc1a0967a6cfdc0af02721).
version 2.0.0 (8a9af99ab10b20b1c6afb30cd9384e562a6647f9). Note that
Makefile and main.c are locally developed files (the remaining files
are from the picotool repo).

The hub-ctrl directory contains code from:
https://github.com/codazoda/hub-ctrl.c/
Expand Down Expand Up @@ -167,7 +174,7 @@ used to upload firmware to devices flashed with the CanBoot bootloader.

The can2040 directory contains code from:
https://github.com/KevinOConnor/can2040
version v1.6.0 (af3d21e5d61b8408c63fbdfb0aceb21d69d91693)
commit 13321ce2bc046e059a47def70f977a579a984462.

The Huada HC32F460 directory contains code from:
https://www.hdsc.com.cn/Category83-1490
Expand Down
18 changes: 9 additions & 9 deletions lib/can2040/can2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <stdint.h> // uint32_t
#include <string.h> // memset
#include "RP2040.h" // hw_set_bits
#include "can2040.h" // can2040_setup
#include "cmsis_gcc.h" // __DMB
#include "hardware/regs/dreq.h" // DREQ_PIO0_RX1
#include "hardware/structs/dma.h" // dma_hw
#include "hardware/structs/iobank0.h" // iobank0_hw
Expand Down Expand Up @@ -128,7 +128,7 @@ static void
pio_sync_setup(struct can2040 *cd)
{
pio_hw_t *pio_hw = cd->pio_hw;
struct pio_sm_hw *sm = &pio_hw->sm[0];
pio_sm_hw_t *sm = &pio_hw->sm[0];
sm->execctrl = (
cd->gpio_rx << PIO_SM0_EXECCTRL_JMP_PIN_LSB
| (can2040_offset_sync_end - 1) << PIO_SM0_EXECCTRL_WRAP_TOP_LSB
Expand All @@ -148,7 +148,7 @@ static void
pio_rx_setup(struct can2040 *cd)
{
pio_hw_t *pio_hw = cd->pio_hw;
struct pio_sm_hw *sm = &pio_hw->sm[1];
pio_sm_hw_t *sm = &pio_hw->sm[1];
sm->execctrl = (
(can2040_offset_shared_rx_end - 1) << PIO_SM0_EXECCTRL_WRAP_TOP_LSB
| can2040_offset_shared_rx_read << PIO_SM0_EXECCTRL_WRAP_BOTTOM_LSB);
Expand All @@ -165,15 +165,15 @@ static void
pio_match_setup(struct can2040 *cd)
{
pio_hw_t *pio_hw = cd->pio_hw;
struct pio_sm_hw *sm = &pio_hw->sm[2];
pio_sm_hw_t *sm = &pio_hw->sm[2];
sm->execctrl = (
(can2040_offset_match_end - 1) << PIO_SM0_EXECCTRL_WRAP_TOP_LSB
| can2040_offset_shared_rx_read << PIO_SM0_EXECCTRL_WRAP_BOTTOM_LSB);
sm->pinctrl = cd->gpio_rx << PIO_SM0_PINCTRL_IN_BASE_LSB;
sm->shiftctrl = 0;
sm->instr = 0xe040; // set y, 0
sm->instr = 0xa0e2; // mov osr, y
sm->instr = 0xa02a, // mov x, !y
sm->instr = 0xa02a; // mov x, !y
sm->instr = can2040_offset_match_load_next; // jmp match_load_next
}

Expand All @@ -182,7 +182,7 @@ static void
pio_tx_setup(struct can2040 *cd)
{
pio_hw_t *pio_hw = cd->pio_hw;
struct pio_sm_hw *sm = &pio_hw->sm[3];
pio_sm_hw_t *sm = &pio_hw->sm[3];
sm->execctrl = (
cd->gpio_rx << PIO_SM0_EXECCTRL_JMP_PIN_LSB
| can2040_offset_tx_conflict << PIO_SM0_EXECCTRL_WRAP_TOP_LSB
Expand Down Expand Up @@ -255,7 +255,7 @@ pio_tx_reset(struct can2040 *cd)
| (0x08 << PIO_CTRL_SM_RESTART_LSB));
pio_hw->irq = (SI_MATCHED | SI_ACKDONE) >> 8; // clear PIO irq flags
// Clear tx fifo
struct pio_sm_hw *sm = &pio_hw->sm[3];
pio_sm_hw_t *sm = &pio_hw->sm[3];
sm->shiftctrl = 0;
sm->shiftctrl = (PIO_SM0_SHIFTCTRL_FJOIN_TX_BITS
| PIO_SM0_SHIFTCTRL_AUTOPULL_BITS);
Expand All @@ -271,7 +271,7 @@ pio_tx_send(struct can2040 *cd, uint32_t *data, uint32_t count)
uint32_t i;
for (i=0; i<count; i++)
pio_hw->txf[3] = data[i];
struct pio_sm_hw *sm = &pio_hw->sm[3];
pio_sm_hw_t *sm = &pio_hw->sm[3];
sm->instr = 0xe001; // set pins, 1
sm->instr = 0x6021; // out x, 1
sm->instr = can2040_offset_tx_write_pin; // jmp tx_write_pin
Expand All @@ -287,7 +287,7 @@ pio_tx_inject_ack(struct can2040 *cd, uint32_t match_key)
pio_tx_reset(cd);
pio_hw->instr_mem[can2040_offset_tx_got_recessive] = 0xc023; // irq wait 3
pio_hw->txf[3] = 0x7fffffff;
struct pio_sm_hw *sm = &pio_hw->sm[3];
pio_sm_hw_t *sm = &pio_hw->sm[3];
sm->instr = 0xe001; // set pins, 1
sm->instr = 0x6021; // out x, 1
sm->instr = can2040_offset_tx_write_pin; // jmp tx_write_pin
Expand Down
Loading

0 comments on commit 119023e

Please sign in to comment.