-
Notifications
You must be signed in to change notification settings - Fork 65
RP2040: Customizing
µCNC for RP2040 can be configured/customized to fit different boards like Pico and Pico W
Jump to section
µCNC for RP2040 can be customized either using the Web Config Tool or by manually modifing the source code files. For the latest method most configurations and pin assigning should be done in the corresponding boardmap file inside the uCNC/src/hal/boards/rp2040/ directory and then the respective board file.
An HAL pin need to be mapped to a physical IO pin. The way this is done is by defining the IO BIT. There is no need do define IO PORT on this MCU. This must be performed for every used pin. RP2040 PORT is ignored. This is similar to the general customization instructions
You can expand the IO output capabilities a MCU using the 74HC595 module. There are several options to run this. Either via a 3 output pins with bit-banging or using hardware SPI. In the case of the RP2040 a specialized option that takes advantage of the RP2040 PIO blocks can be used to create a 74HC595 driver capable of controlling up to 4 chained (daisy-chained) 74HC595 IC.
For this you just need to enable the custom 74HC595 IO shift option and define the pins used by the PIO to control the 74HC595 like this
#define IC74HC595_CUSTOM_SHIFT_IO //Enables custom MCU data shift transmission. In RP2040 that is via a PIO
#define IC74HC595_PIO_DATA 26 //use GPIO26 for the 74HC595 data
#define IC74HC595_PIO_CLK 27 //use GPIO27 for the 74HC595 clock
#define IC74HC595_PIO_LATCH 28 //use GPIO28 for the 74HC595 data latch
By default this will drive the 74HC595 at it's maximum speed of 20MHz. You can also modify the frequency by customizing the PIO clock speed like this:
#define IC74HC595_PIO_FREQ 10000000 //Run the 74HC595 at 10MHz
All input pins can have a weak pull-up activated to drive them high if unconnected. This is similar to the general customization instructions
All pins all repeatedly read by a soft polling routine. But for special function pins an interrupt driven event to force a reading and respective action can be also activated. This causes the response to be immediate and not depend on the pin reading routine cycle.
To make an input pin interruptable just declare #define <pin_name>_ISR
.
For RP2040 the pin mapping can be checked here.
This is similar to the general customization instructions
PWM clock is internally set in the mcumap file and there is no need to configure it. The only thing needed is to choose the PWM pin output.
//Setup PWM
#define PWM0_BIT 8 //assigns PWM0 pin
For analog pins, like in PWM the only thing you need to define is the pin. Arduino framework takes care of the rest:
#define ANALOG0_BIT 0
To make a read just do
uint8_t value = mcu_get_analog(ANALOG0);
All step and dir pins are modified inside a timer ISR (µCNC's heartbeat). In the RP2040 Timer 1 (of 4 available Timers) is used by default. RTC, SERVO and ONESHOT shares the same timer (uses Timer 2).
Servo timing control is shared with RTC. There is no need to configure this timer.
Both WiFi and Bluetooth share the same transition hardware. Enabling them both might lead to unexpected behavior and poor performance. Both WiFi and Bluetooth also save their last state. On power on their previous state (enabled or disabled) will automatically be reinstated.
WiFi interface exposes the following system commands that can be used to configure and control WiFi:
$wifion - this enables WiFi. When this command is issued all changes made to the WiFi settings are stored.
$wifioff - this disables WiFi. When this command is issued all changes made to the WiFi settings are stored.
$wifireset - this resets all WiFi settings.
$wifisave - this saves all WiFi settings. Settings will only be in effect after disabling and enabling the WiFi.
$wifiscan - scans all available WiFi AP's.
$wifissid - gets the current defined AP SSID.
$wifissid=<ssid> - (text) sets the current defined AP SSID.
$wifipass=<pass> - (text) sets the current WiFi password.
$wifimode=<mode_number> - (number) sets the WiFi mode. 1-STA+AP, 2-STA, 3-AP
$wifiip - gets the board IP address
Bluetooth interface exposes the following system commands that can be used to control BLE module:
$bthon - this enables WiFi. When this command is issued all changes made to the WiFi settings are stored.
$bthoff - this disables WiFi. When this command is issued all changes made to the WiFi settings are stored.
µ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. µ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.
µCNC Wiki
- Home
- Basic user guide
- Porting µCNC and adding custom HAL
- Customizing the HAL file
- Adding custom Tools and Modules to µCNC
- FAQ
µCNC for ALL MCU
µCNC for AVR
µCNC for STM32F1 and STM32F4
µCNC for SAMD21
µCNC for ESP8266
µCNC for ESP32
µCNC for NXP LPC176x
µCNC for NXP RP2040