-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
230adb2
commit a693639
Showing
13 changed files
with
4,221 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
Name: boardmap_rp_pico2.h | ||
Description: Contains all MCU and PIN definitions for Raspberry Pi Pico2 to run µCNC. | ||
Copyright: Copyright (c) João Martins | ||
Author: João Martins | ||
Date: 07-11-2024 | ||
µ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_PICO2_H | ||
#define BOARDMAP_RPI_PICO2_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#ifndef MCU | ||
#define MCU MCU_RP2350 | ||
#endif | ||
|
||
#ifndef BOARD_NAME | ||
#define BOARD_NAME "RPi Pico2" | ||
#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 | ||
|
||
#define LIMIT_Z_PULLUP | ||
#define LIMIT_Y_PULLUP | ||
#define LIMIT_X_PULLUP | ||
|
||
// Setup control input pins | ||
// #define ESTOP_BIT 0 | ||
// #define ESTOP_PORT A | ||
// #define ESTOP_ISR | ||
|
||
// Setup com pins | ||
#define RX_BIT 1 | ||
#define RX_PULLUP | ||
#define TX_BIT 0 | ||
// only uncomment this if other port other then 0 is used | ||
// #define UART_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 | ||
|
||
// disable EEPROM emulation | ||
// #ifndef RAM_ONLY_SETTINGS | ||
// #define RAM_ONLY_SETTINGS | ||
// #endif | ||
|
||
#define I2C_CLK_BIT 27 | ||
#define I2C_DATA_BIT 26 | ||
#define I2C_PORT 1 | ||
// #define I2C_ADDRESS 1 | ||
|
||
/** | ||
* This is an example of how to use RP2040 PIO to control | ||
* up to 4 chainned 74hc595 (32 output pins) using only 3 pins | ||
* from the board. | ||
* The 3 pins should be sequential (for example GPIO's 26, 27 and 28) | ||
* | ||
* RP2040 does not yet support software generate PWM | ||
* | ||
* **/ | ||
|
||
// // Use PIO to shift data to 74HC595 shift registers (up to 4) | ||
// // IO pins should be sequencial GPIO pins starting by data, then clock then the latch pin | ||
// #define IC74HC595_CUSTOM_SHIFT_IO //Enables custom MCU data shift transmission. In RP2040 that is via a PIO | ||
// #define IC74HC595_PIO_DATA 26 | ||
// #define IC74HC595_PIO_CLK 27 | ||
// #define IC74HC595_PIO_LATCH 28 | ||
// // enabling IC74HC595_CUSTOM_SHIFT_IO will force IC74HC595_COUNT to be set to 4 no matter what | ||
// // support up to 4 chained 74HC595. Less can be used (overflow bits will be discarded like in the ESP32 I2S implementation) | ||
// #define IC74HC595_COUNT 4 | ||
|
||
// #define STEP0_EN_IO_OFFSET 0 | ||
// #define STEP0_IO_OFFSET 1 | ||
// #define DIR0_IO_OFFSET 2 | ||
// #define STEP1_EN_IO_OFFSET 3 | ||
// #define STEP1_IO_OFFSET 4 | ||
// #define DIR1_IO_OFFSET 5 | ||
// #define STEP2_EN_IO_OFFSET 6 | ||
// #define STEP2_IO_OFFSET 7 | ||
// #define DIR2_IO_OFFSET 8 | ||
// #define STEP3_EN_IO_OFFSET 9 | ||
// #define STEP3_IO_OFFSET 10 | ||
// #define DIR3_IO_OFFSET 11 | ||
// #define STEP4_EN_IO_OFFSET 12 | ||
// #define STEP4_IO_OFFSET 13 | ||
// #define DIR4_IO_OFFSET 14 | ||
// #define DOUT0_IO_OFFSET 15 | ||
|
||
#define SPI2_CLK_BIT 18 | ||
#define SPI2_SDO_BIT 19 | ||
#define SPI2_SDI_BIT 16 | ||
#define SPI2_CS_BIT 17 | ||
#define SPI2_PORT 0 | ||
|
||
// #define SPI2_CLK_BIT 10 | ||
// #define SPI2_SDO_BIT 11 | ||
// #define SPI2_SDI_BIT 12 | ||
// #define SPI2_CS_BIT 13 | ||
// #define SPI2_PORT 1 | ||
|
||
/** | ||
* New multicore mode - Experimental | ||
* */ | ||
// #define RP2040_RUN_MULTICORE | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
################## | ||
# RP2350 Boards # | ||
################## | ||
|
||
[common_rp2350] | ||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git | ||
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git | ||
framework = arduino | ||
board_build.core = earlephilhower | ||
board_build.filesystem_size = 0.5m | ||
; change microcontroller | ||
board_build.mcu = rp2350 | ||
; change MCU frequency | ||
board_build.f_cpu = 150000000L | ||
; lib_deps = adafruit/Adafruit TinyUSB Library@^2.0.3 | ||
build_flags = ${env.build_flags} -std=gnu99 -Wall -fdata-sections -ffunction-sections -fno-exceptions -Wl,--gc-sections -DRAM_ONLY_SETTINGS | ||
debug_tool = cmsis-dap | ||
lib_deps = | ||
${env.lib_deps} | ||
SPI | ||
Wire | ||
EEPROM | ||
lib_ignore = | ||
HTTPUpdateServer | ||
LittleFS | ||
WiFi | ||
WebServer | ||
SerialBT | ||
DNSServer | ||
Hash | ||
BluetoothSerial | ||
|
||
[env:RP2350-PICO2] | ||
extends = common_rp2350 | ||
board = generic_rp2350 | ||
build_flags = ${common_rp2350.build_flags} -D BOARD=\"src/hal/boards/rp2350/boardmap_rpi_pico2.h\" | ||
lib_deps = | ||
${env.lib_deps} | ||
SPI | ||
Wire | ||
EEPROM | ||
|
||
[env:RP2350-CUSTOM] | ||
extends = common_rp2350 | ||
build_flags = ${common_rp2350.build_flags} -DMCU=MCU_CUSTOM | ||
board = ${env.board} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
_µCNC for RP2040 can be built this way_ | ||
|
||
## Method one - PlatformIO (preferred) | ||
|
||
1. Get [Visual Studio Code](https://code.visualstudio.com/download) and install it. | ||
2. Install the PlatformIO extension. | ||
3. Open uCNC folder in VSCode. | ||
4. Edit ```cnc_config.h file``` and ```cnc_hal_config.h file``` to fit your needs and board. | ||
5. If needed edit the platformio.ini file environment for your board. Compile the sketch and upload it to your board. | ||
|
||
## Method two - Arduino IDE (easiest) | ||
|
||
1. Get [Arduino IDE](https://www.arduino.cc/en/software) and install it. | ||
2. If you don't have install ESP8266 for Arduino with Arduino board manager has explained [here](https://github.com/earlephilhower/arduino-pico#installing-via-arduino-boards-manager) | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
; | ||
;Name: ic74hc595.pio | ||
;Description: Implements a custom PIO for 74HC595 shift register in µCNC for RP2040. | ||
; | ||
;Copyright: Copyright (c) João Martins | ||
;Author: João Martins | ||
;Date: 02-11-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. | ||
; | ||
|
||
.program ic74hc595 | ||
.side_set 1 opt | ||
|
||
pull ; shift TX to OSR | ||
set x, 31 ; load loop counter | ||
set pins, 0 ; set all pins low (latch) | ||
bitloop: ; loop bits | ||
out pins, 1 side 0 ; Shift 1 bit from OSR to the data pin and the remaining down | ||
jmp x-- bitloop side 1 ; decrement loop and bring clock up | ||
set pins, 2 ; set 3rd pin (4=0b100) up (latch) | ||
|
||
% c-sdk { | ||
#include "hardware/clocks.h" | ||
|
||
static inline void ic74hc595_program_init(PIO pio, uint sm, uint offset, uint pin_data, uint pin_clk, uint pin_latch, uint freq) { | ||
pio_sm_config c = ic74hc595_program_get_default_config(offset); | ||
sm_config_set_out_pins(&c, pin_data, 1); // define one pin to respond to the out instruction | ||
sm_config_set_set_pins(&c, pin_clk, 2); // define all pins to respond to the set instruction | ||
sm_config_set_sideset_pins(&c, pin_clk); // define clock as the side set base pin (and only) | ||
// Only support MSB-first in this example code (shift to left, no auto push/pull, threshold=nbits) | ||
sm_config_set_out_shift(&c, false, false, 32); | ||
// All pins output | ||
pio_sm_set_consecutive_pindirs(pio, sm, pin_data, 3, true); | ||
pio_gpio_init(pio, pin_data); | ||
pio_gpio_init(pio, pin_clk); | ||
pio_gpio_init(pio, pin_latch); | ||
// We only need TX, so get an 8-deep FIFO! | ||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); | ||
// SM transmits 1 bit per 8 execution cycles. | ||
float div = (float)clock_get_hz(clk_sys) / (freq << 1); | ||
sm_config_set_clkdiv(&c, div); | ||
pio_sm_init(pio, sm, offset, &c); | ||
pio_sm_set_enabled(pio, sm, true); | ||
} | ||
|
||
static inline void ic74hc595_program_write(PIO pio, uint sm, uint out) { | ||
pio_sm_put_blocking(pio, sm, out); | ||
} | ||
%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// -------------------------------------------------- // | ||
// This file is autogenerated by pioasm; do not edit! // | ||
// -------------------------------------------------- // | ||
|
||
#pragma once | ||
|
||
#if !PICO_NO_HARDWARE | ||
#include "hardware/pio.h" | ||
#endif | ||
|
||
// --------- // | ||
// ic74hc595 // | ||
// --------- // | ||
|
||
#define ic74hc595_wrap_target 0 | ||
#define ic74hc595_wrap 5 | ||
|
||
static const uint16_t ic74hc595_program_instructions[] = { | ||
// .wrap_target | ||
0x80a0, // 0: pull block | ||
0xe03f, // 1: set x, 31 | ||
0xe000, // 2: set pins, 0 | ||
0x7001, // 3: out pins, 1 side 0 | ||
0x1843, // 4: jmp x--, 3 side 1 | ||
0xe002, // 5: set pins, 2 | ||
// .wrap | ||
}; | ||
|
||
#if !PICO_NO_HARDWARE | ||
static const struct pio_program ic74hc595_program = { | ||
.instructions = ic74hc595_program_instructions, | ||
.length = 6, | ||
.origin = -1, | ||
}; | ||
|
||
static inline pio_sm_config ic74hc595_program_get_default_config(uint offset) | ||
{ | ||
pio_sm_config c = pio_get_default_sm_config(); | ||
sm_config_set_wrap(&c, offset + ic74hc595_wrap_target, offset + ic74hc595_wrap); | ||
sm_config_set_sideset(&c, 2, true, false); | ||
return c; | ||
} | ||
|
||
#include "hardware/clocks.h" | ||
static inline void ic74hc595_program_init(PIO pio, uint sm, uint offset, uint pin_data, uint pin_clk, uint pin_latch, uint freq) | ||
{ | ||
pio_sm_config c = ic74hc595_program_get_default_config(offset); | ||
sm_config_set_out_pins(&c, pin_data, 1); // define one pin to respond to the out instruction | ||
sm_config_set_set_pins(&c, pin_clk, 2); // define all pins to respond to the set instruction | ||
sm_config_set_sideset_pins(&c, pin_clk); // define clock as the side set base pin (and only) | ||
// Only support MSB-first in this example code (shift to left, no auto push/pull, threshold=nbits) | ||
sm_config_set_out_shift(&c, false, false, 32); | ||
// All pins output | ||
pio_sm_set_consecutive_pindirs(pio, sm, pin_data, 3, true); | ||
pio_gpio_init(pio, pin_data); | ||
pio_gpio_init(pio, pin_clk); | ||
pio_gpio_init(pio, pin_latch); | ||
// We only need TX, so get an 8-deep FIFO! | ||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); | ||
// SM transmits 1 bit per 8 execution cycles. | ||
float div = (float)clock_get_hz(clk_sys) / (freq << 1); | ||
sm_config_set_clkdiv(&c, div); | ||
pio_sm_init(pio, sm, offset, &c); | ||
pio_sm_set_enabled(pio, sm, true); | ||
} | ||
static inline void ic74hc595_program_write(PIO pio, uint sm, uint out) | ||
{ | ||
pio_sm_put_blocking(pio, sm, out); | ||
} | ||
|
||
#endif |
Oops, something went wrong.