Skip to content

Commit

Permalink
Merge pull request #360 from Paciente8159/rp2040
Browse files Browse the repository at this point in the history
RP2040
  • Loading branch information
Paciente8159 committed Apr 7, 2023
2 parents ddf9e34 + f3c8b49 commit d2aee86
Show file tree
Hide file tree
Showing 40 changed files with 2,859 additions and 213 deletions.
4 changes: 2 additions & 2 deletions PINOUTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ This wiring can be completely modified by the user.
| DIN27 | STEPPER7_UART_RX |
| DIN28 | SOFT_UART_RX |
| DIN29 | SOFT_SPI_SDI or TMC_SPI_SDI or STEPPER_DIGIPOT_SDI |
| DIN30 | SOFT_I2C_SCL |
| DIN31 | SOFT_I2C_SDA |
| DIN30 | SOFT_I2C_CLK |
| DIN31 | SOFT_I2C_DATA |
Binary file modified docs/mcumap_gen.xlsx
Binary file not shown.
Binary file added docs/raspberrypi-pico-w-pinout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
[platformio]
include_dir=uCNC
src_dir=uCNC
default_envs = uno, ramps14, rambo, arduinoM0, bluepill_f103c8, blackpill_f401cc, d1, re_arm, d1_r32
default_envs = uno, ramps14, rambo, arduinoM0, bluepill_f103c8, blackpill_f401cc, d1, re_arm, d1_r32, rpi_pico
extra_configs =
uCNC/src/hal/boards/avr/avr.ini
uCNC/src/hal/boards/samd21/samd21.ini
uCNC/src/hal/boards/stm32/stm32.ini
uCNC/src/hal/boards/esp8266/esp8266.ini
uCNC/src/hal/boards/lpc176x/lpc176x.ini
uCNC/src/hal/boards/esp32/esp32.ini
uCNC/src/hal/boards/rp2040/rp2040.ini
; uCNC/src/hal/mcus/virtual/virtual.ini

[common]
Expand Down
2 changes: 1 addition & 1 deletion uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ extern "C"
* Storing is disabled and the defaults will be loaded at each power up
* This is useful if you don't have EEPROM/FLASH storage or the divide read/write maximum cycle count is low to prevent damage
* */
// #define RAM_ONLY_SETTINGS
#define RAM_ONLY_SETTINGS

/**
* EXPERIMENTAL! Uncomment to enable fast math macros to reduce the number of
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/cnc_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C"
#endif

#define CNC_MAJOR_MINOR_VERSION "1.6"
#define CNC_PATCH_VERSION ".pre"
#define CNC_PATCH_VERSION ".0-pre"

#define CNC_VERSION CNC_MAJOR_MINOR_VERSION CNC_PATCH_VERSION

Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/cnc_hal_config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1911,15 +1911,15 @@ extern "C"
#endif
#define DIO207 UNDEF_PIN
#endif
#ifndef I2C_SCL
#define I2C_SCL UNDEF_PIN
#ifndef I2C_CLK
#define I2C_CLK UNDEF_PIN
#ifdef DIO208
#undef DIO208
#endif
#define DIO208 UNDEF_PIN
#endif
#ifndef I2C_SDA
#define I2C_SDA UNDEF_PIN
#ifndef I2C_DATA
#define I2C_DATA UNDEF_PIN
#ifdef DIO209
#undef DIO209
#endif
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/hal/boards/avr/boardmap_ramps14.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ extern "C"
// #define DIN0_ISR 0

// hardware I2C
#define I2C_SCL_BIT 0
#define I2C_SCL_PORT D
#define I2C_SDA_BIT 1
#define I2C_SDA_PORT D
#define I2C_CLK_BIT 0
#define I2C_CLK_PORT D
#define I2C_DATA_BIT 1
#define I2C_DATA_PORT D
// software I2C
// #define DIN30_BIT 0
// #define DIN30_PORT D
Expand Down
10 changes: 10 additions & 0 deletions uCNC/src/hal/boards/boarddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ extern "C"
#include "esp32/boardmap_mks_dlc32.h"
#endif

#if (BOARD == BOARD_RPI_PICO)
#define MCU MCU_RP2040
#include "rp2040/boardmap_rpi_pico.h"
#endif

#if (BOARD == BOARD_RPI_PICO_W)
#define MCU MCU_RP2040
#include "rp2040/boardmap_rpi_pico_w.h"
#endif

#if (BOARD == BOARD_VIRTUAL)
#ifndef __linux__
#define MCU MCU_VIRTUAL_WIN
Expand Down
2 changes: 2 additions & 0 deletions uCNC/src/hal/boards/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ extern "C"
#define BOARD_WEMOS_D1_R32 50
#define BOARD_MKS_TINYBEE 51
#define BOARD_MKS_DLC32 52
#define BOARD_RPI_PICO 60
#define BOARD_RPI_PICO_W 61
#define BOARD_VIRTUAL 99

// special purpose board
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/hal/boards/lpc176x/boardmap_mks_base13.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ extern "C"
#define ANALOG3_CHANNEL 3

// hardware I2C
#define I2C_SCL_BIT 1
#define I2C_SCL_PORT 0
#define I2C_SDA_BIT 0
#define I2C_SDA_PORT 0
#define I2C_CLK_BIT 1
#define I2C_CLK_PORT 0
#define I2C_DATA_BIT 0
#define I2C_DATA_PORT 0
#define I2C_PORT 1
// software I2C
// #define DIN30_BIT 1
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/hal/boards/lpc176x/boardmap_re_arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ extern "C"
#define ANALOG2_CHANNEL 2

// hardware I2C
#define I2C_SCL_BIT 1
#define I2C_SCL_PORT 0
#define I2C_SDA_BIT 0
#define I2C_SDA_PORT 0
#define I2C_CLK_BIT 1
#define I2C_CLK_PORT 0
#define I2C_DATA_BIT 0
#define I2C_DATA_PORT 0
#define I2C_PORT 1
// software I2C
// #define DIN30_BIT 1
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/hal/boards/lpc176x/boardmap_skr_v14_turbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ extern "C"
#define ANALOG3_CHANNEL 3

// hardware I2C
#define I2C_SCL_BIT 1
#define I2C_SCL_PORT 0
#define I2C_SDA_BIT 0
#define I2C_SDA_PORT 0
#define I2C_CLK_BIT 1
#define I2C_CLK_PORT 0
#define I2C_DATA_BIT 0
#define I2C_DATA_PORT 0
#define I2C_PORT 1
// software I2C
// #define DIN30_BIT 1
Expand Down
80 changes: 80 additions & 0 deletions uCNC/src/hal/boards/rp2040/boardmap_rpi_pico.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Name: boardmap_rp_pico_w.h
Description: Contains all MCU and PIN definitions for Raspberry Pi Pico W to run µCNC.
Copyright: Copyright (c) João Martins
Author: João Martins
Date: 16/01/2023
µCNC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. Please see <http://www.gnu.org/licenses/>
µCNC is distributed WITHOUT ANY WARRANTY;
Also without the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
*/

#ifndef BOARDMAP_RPI_PICO_H
#define BOARDMAP_RPI_PICO_H

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef BOARD_NAME
#define BOARD_NAME "RPi Pico"
#endif

// SAME AS GRBL for test purposes
// Setup step pins
#define STEP2_BIT 10 // assigns STEP2 pin
#define STEP1_BIT 6 // assigns STEP1 pin
#define STEP0_BIT 2 // assigns STEP0 pin

// Setup dir pins
#define DIR2_BIT 11 // assigns DIR2 pin
#define DIR1_BIT 7 // assigns DIR1 pin
#define DIR0_BIT 3 // assigns DIR0 pin

#define LIMIT_Z_BIT 13
#define LIMIT_Y_BIT 9
#define LIMIT_X_BIT 5

// Setup control input pins
// #define ESTOP_BIT 0
// #define ESTOP_PORT A
//#define ESTOP_ISR

// Setup com pins
#define RX_BIT 1
#define TX_BIT 0
// only uncomment this if other port other then 0 is used
// #define COM_PORT 0

//forces USB
#define MCU_HAS_USB
// Setup PWM
#define PWM0_BIT 14 // assigns PWM0 pin

// Setup generic IO Pins
// spindle dir
#define DOUT0_BIT 15

// Stepper enable pin. For Grbl on Uno board a single pin is used
#define STEP2_EN_BIT 12
#define STEP1_EN_BIT 8
#define STEP0_EN_BIT 4

//activity LED
#define DOUT31_BIT 25


#ifdef __cplusplus
}
#endif

#endif
46 changes: 46 additions & 0 deletions uCNC/src/hal/boards/rp2040/boardmap_rpi_pico_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Name: boardmap_rp_pico_w.h
Description: Contains all MCU and PIN definitions for Raspberry Pi Pico W to run µCNC.
Copyright: Copyright (c) João Martins
Author: João Martins
Date: 16/01/2023
µCNC is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. Please see <http://www.gnu.org/licenses/>
µCNC is distributed WITHOUT ANY WARRANTY;
Also without the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
*/

#ifndef BOARDMAP_RPI_PICO_W_H
#define BOARDMAP_RPI_PICO_W_H

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef BOARD_NAME
#define BOARD_NAME "RPi Pico W"
#endif

#ifndef ENABLE_WIFI
#define ENABLE_WIFI
#endif

#define BOARD_HAS_CUSTOM_SYSTEM_COMMANDS

#include "boardmap_rpi_pico.h"

// led pin is controlled by the external WiFi controller
#undef DIO31_BIT

#ifdef __cplusplus
}
#endif

#endif
27 changes: 27 additions & 0 deletions uCNC/src/hal/boards/rp2040/rp2040.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##################
# RP2040 Boards #
##################

[common_rp2040]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
; board = pico
framework = arduino
board_build.core = earlephilhower
; board_build.filesystem_size = 0.5m
; change microcontroller
board_build.mcu = rp2040
; change MCU frequency
board_build.f_cpu = 133000000L
lib_deps = adafruit/Adafruit TinyUSB Library@^2.0.3
build_flags = -DUSE_TINYUSB

[env:rpi_pico]
extends = common_rp2040
board = rpipico
;build_src_filter = +<*>-<libraries/WiFi>
build_flags = -DBOARD=BOARD_RPI_PICO

[env:rpi_pico_w]
extends = common_rp2040
board = rpipicow
build_flags = -DBOARD=BOARD_RPI_PICO_W -DENABLE_WIFI
44 changes: 22 additions & 22 deletions uCNC/src/hal/mcus/avr/mcumap_avr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1905,29 +1905,29 @@ extern "C"
#define DIO207_INREG (__inreg__(SPI_CS_PORT))
#define DIO207_DIRREG (__dirreg__(SPI_CS_PORT))
#endif
#if (defined(I2C_SCL_PORT) && defined(I2C_SCL_BIT))
#if (defined(I2C_CLK_PORT) && defined(I2C_CLK_BIT))
#define DIO208 208
#define I2C_SCL 208
#define DIO208_PORT (I2C_SCL_PORT)
#define DIO208_BIT (I2C_SCL_BIT)
#define I2C_SCL_OUTREG (__outreg__(I2C_SCL_PORT))
#define I2C_SCL_INREG (__inreg__(I2C_SCL_PORT))
#define I2C_SCL_DIRREG (__dirreg__(I2C_SCL_PORT))
#define DIO208_OUTREG (__outreg__(I2C_SCL_PORT))
#define DIO208_INREG (__inreg__(I2C_SCL_PORT))
#define DIO208_DIRREG (__dirreg__(I2C_SCL_PORT))
#endif
#if (defined(I2C_SDA_PORT) && defined(I2C_SDA_BIT))
#define I2C_CLK 208
#define DIO208_PORT (I2C_CLK_PORT)
#define DIO208_BIT (I2C_CLK_BIT)
#define I2C_CLK_OUTREG (__outreg__(I2C_CLK_PORT))
#define I2C_CLK_INREG (__inreg__(I2C_CLK_PORT))
#define I2C_CLK_DIRREG (__dirreg__(I2C_CLK_PORT))
#define DIO208_OUTREG (__outreg__(I2C_CLK_PORT))
#define DIO208_INREG (__inreg__(I2C_CLK_PORT))
#define DIO208_DIRREG (__dirreg__(I2C_CLK_PORT))
#endif
#if (defined(I2C_DATA_PORT) && defined(I2C_DATA_BIT))
#define DIO209 209
#define I2C_SDA 209
#define DIO209_PORT (I2C_SDA_PORT)
#define DIO209_BIT (I2C_SDA_BIT)
#define I2C_SDA_OUTREG (__outreg__(I2C_SDA_PORT))
#define I2C_SDA_INREG (__inreg__(I2C_SDA_PORT))
#define I2C_SDA_DIRREG (__dirreg__(I2C_SDA_PORT))
#define DIO209_OUTREG (__outreg__(I2C_SDA_PORT))
#define DIO209_INREG (__inreg__(I2C_SDA_PORT))
#define DIO209_DIRREG (__dirreg__(I2C_SDA_PORT))
#define I2C_DATA 209
#define DIO209_PORT (I2C_DATA_PORT)
#define DIO209_BIT (I2C_DATA_BIT)
#define I2C_DATA_OUTREG (__outreg__(I2C_DATA_PORT))
#define I2C_DATA_INREG (__inreg__(I2C_DATA_PORT))
#define I2C_DATA_DIRREG (__dirreg__(I2C_DATA_PORT))
#define DIO209_OUTREG (__outreg__(I2C_DATA_PORT))
#define DIO209_INREG (__inreg__(I2C_DATA_PORT))
#define DIO209_DIRREG (__dirreg__(I2C_DATA_PORT))
#endif

// ISR on change inputs
Expand Down Expand Up @@ -4359,7 +4359,7 @@ extern "C"
#endif

// I2C
#if (defined(I2C_SCL) && defined(I2C_SDA))
#if (defined(I2C_CLK) && defined(I2C_DATA))
#define MCU_HAS_I2C
#ifndef I2C_FREQ
#define I2C_FREQ 400000UL
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/hal/mcus/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ _µCNC for ESP32 can be built this way_
2. If you don't have install ESP32 for Arduino with Arduino board manager has explained [here](https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html)
3. Go to uCNC folder and open uCNC.ino sketch.
4. Edit ```cnc_config.h file``` and ```cnc_hal_config.h file``` to fit your needs and board.
5. Compile the sketch and upload it to your board (via maple bootloader or other method).
5. Compile the sketch and upload it to your board.
6 changes: 3 additions & 3 deletions uCNC/src/hal/mcus/esp32/mcu_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,12 +736,12 @@ void mcu_init(void)
#ifdef MCU_HAS_I2C
i2c_config_t i2cconf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_SDA_BIT, // select GPIO specific to your project
.sda_io_num = I2C_DATA_BIT, // select GPIO specific to your project
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_SCL_BIT, // select GPIO specific to your project
.scl_io_num = I2C_CLK_BIT, // select GPIO specific to your project
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_FREQ, // select frequency specific to your project
.clk_flags = 0, // you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here
.clk_flags = 0, // you can use I2C_CLKK_SRC_FLAG_* flags to choose i2c source clock here
};
i2c_param_config((i2c_port_t)I2C_PORT, &i2cconf);
i2c_driver_install(I2C_PORT, I2C_MODE_MASTER, 0, 0, 0);
Expand Down
Loading

0 comments on commit d2aee86

Please sign in to comment.