Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't compile 6-axis for Neculeo-64 STM32F4RE Board #263

Closed
MuhammadQaisarAli opened this issue Mar 8, 2023 · 13 comments
Closed

Can't compile 6-axis for Neculeo-64 STM32F4RE Board #263

MuhammadQaisarAli opened this issue Mar 8, 2023 · 13 comments

Comments

@MuhammadQaisarAli
Copy link

I followed the instructions given in "compiling girbalHAL section" to compile the driver for 6-axis. but after downlading biard, the driver is still 3 axis.
I edited the cnc3040 file for needs, and saved the file with the name "my_machine_map.h" in Inc folder. then i uncommented the "#define BOARD_MY_MACHINE " line. But didn't got success.

The webbuilder tool dont have 6 axis support for Nuclo64 boards, altho Bluepill F401 can have 5 axis.

@terjeio
Copy link
Contributor

terjeio commented Mar 8, 2023

Did you change N_AXIS to 6?

@MuhammadQaisarAli
Copy link
Author

Yes.. changed.

@MuhammadQaisarAli
Copy link
Author

MuhammadQaisarAli commented Mar 8, 2023

Here is the "MACROS"
image

Here is my_machine.h file

`// NOTE: Only one board may be enabled!
// If none is enabled pin mappings from generic_map.h will be used.
//#define BOARD_CNC3040
//#define BOARD_PROTONEER_3XX // For use with Nucleo-F411RE and F446RE boards.
//#define BOARD_GENERIC_UNO // For use with Nucleo-F411RE and F446RE boards.
//#define BOARD_CNC_BOOSTERPACK
//#define BOARD_MORPHO_CNC // For use with Nucleo-F411RE and F446RE boards. Work in progress.
//#define BOARD_MORPHO_DAC_CNC // For use with F446RE boards and a 32-bit I2S stereo DAC for X and Y output. EXPERIMENTAL
//#define BOARD_BLACKPILL // For use with F411 BlackPill, with optional auto square support for one axis
//#define BOARD_MINI_BLACKPILL // For use with F411 BlackPill, https://github.com/avizienis/Minimal-Black-Pill--STM32F4xx-BOB-for-grblHAL
//#define BOARD_BTT_SKR_PRO_1_1 // F407 based 3D Printer board
//#define BOARD_BTT_SKR_PRO_1_2 // F407 based 3D Printer board
//#define BOARD_BTT_SKR_20 // F407 based 3D Printer board
//#define BOARD_BTT_SKR_20_DAC // F407 based 3D Printer board, uses analog output (DAC) for spindle speed control
//#define BOARD_FYSETC_S6 // F446 based 3D Printer board
//#define BOARD_FLEXI_HAL // F446 CNC board
//#define BOARD_STM32F401_UNI // F401 CNC board
#define BOARD_MY_MACHINE // Add my_machine_map.h before enabling this!

// WARNING: BOARD_BTT_SKR_20 may fry your Trinamic drivers due to bad hardware design.
// The risk goes away if Q1 (HY1904C2) is shorted between source (S) and drain (D).
// See this issue for details: bigtreetech/SKR-2#63
// Note: grblHAL does not check for reversed drivers.

#if defined(NUCLEO_F401) || defined(NUCLEO_F411) || defined(NUCLEO_F446)
#define IS_NUCLEO_DEVKIT 1
#else
#define IS_NUCLEO_DEVKIT 0
#endif

// Configuration
// Uncomment to enable.

#if !IS_NUCLEO_DEVKIT && !defined(USB_SERIAL_CDC) // The Nucleo boards has an off-chip UART to USB interface.
#define USB_SERIAL_CDC 1 // Serial communication via native USB.
#endif
//#define SAFETY_DOOR_ENABLE 1 // Enable safety door input.
//#define BLUETOOTH_ENABLE 1 // Set to 1 for HC-05 module. Requires and claims one auxillary input pin.
//#define VFD_ENABLE 1 // Set to 1 or 2 for Huanyang VFD spindle. More here https://github.com/grblHAL/Plugins_spindle
//#define MODBUS_ENABLE 1 // Set to 1 for auto direction, 2 for direction signal on auxillary output pin.
//#define SDCARD_ENABLE 2 // Run gcode programs from SD card.
//#define MPG_ENABLE 1 // Enable MPG interface. Requires serial port and one handshake pin unless
// KEYPAD_ENABLE is set to 2 when mode switching is done by the CMD_MPG_MODE_TOGGLE (0x8B)
// command character. Set both MPG_ENABLE and KEYPAD_ENABLE to 2 to use a handshake pin anyway.
//#define KEYPAD_ENABLE 1 // Set to 1 for I2C keypad, 2 for other input such as serial data. If KEYPAD_ENABLE is set to 2
// and MPG_ENABLE is uncommented then a serial stream is shared with the MPG.
//#define DISPLAY_ENABLE 1 // Set to 1 for I2C display protocol, 2 for I2C LED protocol.
//#define MACROS_ENABLE 1 // Macros plugin. For macros that can be triggered by keypad plugin or auxillary inputs.
// Set to 1 for aux input triggers, 2 for keypad triggers or 3 for both.
//#define N_MACROS 1 // Number of macros to enable, max 8. If commented out default is 4 when triggered by aux inputs, 8 otherwise.
//#define ODOMETER_ENABLE 1 // Odometer plugin.
//#define PPI_ENABLE 1 // Laser PPI plugin. To be completed.
//#define LASER_COOLANT_ENABLE 1 // Laser coolant plugin. To be completed.
//#define TRINAMIC_ENABLE 2130 // Trinamic TMC2130 stepper driver support. NOTE: work in progress.
//#define TRINAMIC_ENABLE 5160 // Trinamic TMC5160 stepper driver support. NOTE: work in progress.
//#define TRINAMIC_ENABLE 2209 // Trinamic TMC2209 stepper driver support. NOTE: work in progress.
//#define TRINAMIC_I2C 1 // Trinamic I2C - SPI bridge interface.
//#define TRINAMIC_DEV 1 // Development mode, adds a few M-codes to aid debugging. Do not enable in production code.
//#define EEPROM_ENABLE 1 // I2C EEPROM support. Set to 1 for 24LC16 (2K), 3 for 24C32 (4K - 32 byte page) and 2 for other sizes. Enables eeprom plugin.
//#define EEPROM_IS_FRAM 1 // Uncomment when EEPROM is enabled and chip is FRAM, this to remove write delay.
//#define SPINDLE_SYNC_ENABLE 1 // Enable spindle sync support (G33, G76). !! NOTE: Alpha quality - enable only for test or verification.
// Currently only available for BOARD_T41BB5X_PRO and BOARD_T41U5XBB_SS.
#define ESTOP_ENABLE 0 // When enabled only real-time report requests will be executed when the reset pin is asserted.
// Note: if left commented out the default setting is determined from COMPATIBILITY_LEVEL.

// If the selected board map supports more than three motors ganging and/or auto-squaring
// of axes can be enabled here.
//#define X_GANGED 1
//#define X_AUTO_SQUARE 1
//#define Y_GANGED 1
//#define Y_AUTO_SQUARE 1
//#define Z_GANGED 1
//#define Z_AUTO_SQUARE 1
// For ganged axes the limit switch input (if available) can be configured to act as a max travel limit switch.
// NOTE: If board map already has max limit inputs defined this configuration will be ignored.
//#define X_GANGED_LIM_MAX 1
//#define Y_GANGED_LIM_MAX 1
//#define Z_GANGED_LIM_MAX 1`

here is my my_machine_map.h file
`/*
cnc3040_map.h - driver code for STM32F4xx ARM processors

Part of grblHAL

Grbl 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.

Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Grbl. If not, see http://www.gnu.org/licenses/.
*/

#if N_ABC_MOTORS > 2
#error "Axis configuration is not supported!"
#endif

#if TRINAMIC_ENABLE
#error Trinamic plugin not supported!
#endif

#if N_AXIS == 5
#define BOARD_NAME "Nucleo 64 5-axis"
#elif N_AXIS == 4
#define BOARD_NAME "Nucleo 64 4-axis"
#else
#define BOARD_NAME "Nucleo 64 3-axis"
#endif

#define I2C_PORT 1
#define IS_NUCLEO_BOB
//#define VARIABLE_SPINDLE // Comment out to disable variable spindle

// Define step pulse output pins.
#define STEP_PORT GPIOA
#define X_STEP_PIN 0
#define Y_STEP_PIN 11 // 2 is used by USB Serial port of Nucleo64
#define Z_STEP_PIN 4
#define STEP_OUTMODE GPIO_MAP
//#define STEP_PINMODE PINMODE_OD // Uncomment for open drain outputs

// Define step direction output pins.
#define DIRECTION_PORT GPIOA
#define X_DIRECTION_PIN 1
#define Y_DIRECTION_PIN 12 // 3 is used by USB Serial port of Nucleo64
#define Z_DIRECTION_PIN 5
#define DIRECTION_OUTMODE GPIO_MAP
//#define DIRECTION_PINMODE PINMODE_OD // Uncomment for open drain outputs

// Define stepper driver enable/disable output pin.
#define STEPPERS_ENABLE_PORT GPIOB
#define STEPPERS_ENABLE_PIN 9
//#define STEPPERS_ENABLE_PINMODE PINMODE_OD // Uncomment for open drain outputs

// Define homing/hard limit switch input pins.
#define LIMIT_PORT GPIOB
#define X_LIMIT_PIN 2
#define Y_LIMIT_PIN 10
#define Z_LIMIT_PIN 12
#define LIMIT_INMODE GPIO_MAP

// Define ganged axis or A axis step pulse and step direction output pins.
#if N_ABC_MOTORS > 0
#define M3_AVAILABLE
#define M3_STEP_PORT STEP_PORT
#define M3_STEP_PIN 6
#define M3_DIRECTION_PORT DIRECTION_PORT
#define M3_DIRECTION_PIN 7
#endif

// Define ganged axis or B axis step pulse and step direction output pins.
#if N_ABC_MOTORS == 2
#define M4_AVAILABLE
#define M4_STEP_PORT STEP_PORT
#define M4_STEP_PIN 9
#define M4_DIRECTION_PORT DIRECTION_PORT
#define M4_DIRECTION_PIN 10
#endif

// Define spindle enable and spindle direction output pins.
#define SPINDLE_ENABLE_PORT GPIOB
#define SPINDLE_ENABLE_PIN 1
#define SPINDLE_DIRECTION_PORT GPIOB
#define SPINDLE_DIRECTION_PIN 0

// Define spindle PWM output pin.
#define SPINDLE_PWM_PORT_BASE GPIOA_BASE
#define SPINDLE_PWM_PIN 8

// Define flood and mist coolant enable output pins.
#define COOLANT_FLOOD_PORT GPIOB
#define COOLANT_FLOOD_PIN 3
#define COOLANT_MIST_PORT GPIOB
#define COOLANT_MIST_PIN 4

// Define user-control controls (cycle start, reset, feed hold) input pins.
#define CONTROL_PORT GPIOB
#define RESET_PIN 5
#define FEED_HOLD_PIN 14
#define CYCLE_START_PIN 15
#if SAFETY_DOOR_ENABLE
#define SAFETY_DOOR_PIN 8
#endif
#define CONTROL_INMODE GPIO_MAP

// Define probe switch input pin.
#define PROBE_PORT GPIOB
#define PROBE_PIN 13`

Here is main screen snap,
image

While uploading, the following is selected as configuration file.
image

@terjeio
Copy link
Contributor

terjeio commented Mar 8, 2023

You have to select the debug build for 6. Debug F411 Nucleo 64 from the build tool.

FYI 1. Debug has N_AXIS set to 5, this overrides the config.h setting and the launch you chose do not use the generated binary.
image

This test in the map file will cause a compilation failure when N_AXIS is 6, remove it:

#if N_ABC_MOTORS > 2
#error "Axis configuration is not supported!"
#endif

There are no pin mappings for motor 5 (the C axis), you have to change the motor 4 definition from:

// Define ganged axis or B axis step pulse and step direction output pins.
#if N_ABC_MOTORS == 2
#define M4_AVAILABLE
#define M4_STEP_PORT STEP_PORT
#define M4_STEP_PIN 9
#define M4_DIRECTION_PORT DIRECTION_PORT
#define M4_DIRECTION_PIN 10
#endif

to

// Define ganged axis or B axis step pulse and step direction output pins.
#if N_ABC_MOTORS Z > 1
#define M4_AVAILABLE
#define M4_STEP_PORT STEP_PORT
#define M4_STEP_PIN 9
#define M4_DIRECTION_PORT DIRECTION_PORT
#define M4_DIRECTION_PIN 10
#endif

and add motor 5 definitions:

// Define ganged axis or C axis step pulse and step direction output pins.
#if N_ABC_MOTORS == 3
#define M5_AVAILABLE
#define M5_STEP_PORT STEP_PORT
#define M5_STEP_PIN 9
#define M5_DIRECTION_PORT DIRECTION_PORT
#define M5_DIRECTION_PIN 10
#endif

Change the pin numbers and possibly the ports used to match the pins you want to use!
If pins are on different ports than STEP_PORT and/or DIRECTION_PORT more changes has to be made, See the btt_skr_pro_v1_1_map.h for how to, or perhaps modify that instead.

@MuhammadQaisarAli
Copy link
Author

As there was no definition for 3rd motor, so i was going with 5-axis in this example. Thenk you very much for adding the code for 3rd motor as well.

@MuhammadQaisarAli
Copy link
Author

Everything goes well. In iosender I can see 6-axis now, but there is E-stop error,
image

for the time being I uncommented the following line to avoid the E-stop error. (By default the E-stop should have to be disabled).

#define ESTOP_ENABLE 0 // When enabled only real-time report requests will be executed when the reset pin is asserted.
But now reset is always asserted.
image

To fix it I disabled the pullup resistor on reset pin,
image

Or inverted the control pin.
image

One can see that its done via iosender app. How to do it via code?.

@terjeio
Copy link
Contributor

terjeio commented Mar 8, 2023

One can see that its done via iosender app. How to do it via code?.

$14=1 or you may change the setting default in grbl/config.h.
or connect a normally closed (NC) switch to the input (recommended).

@MuhammadQaisarAli
Copy link
Author

Thank you very much, did that already.

@MuhammadQaisarAli
Copy link
Author

MuhammadQaisarAli commented Mar 16, 2023

I modified added more code and was able to compile upto 8 axis (X,Y,Z,A,B,C,U,V). I tested the signals with oscilloscope as well, all 8 axis worked.
Now I started adding 9th axis (W), there was a lot of modification and upgradation to code in almost all files.

When I added 9th axis , the Limit_bit_mask macro raised a warning ⚠️ as (1<<W_Axis) is (1<<9), which makes the mask a 9 bit value and can't be assigned to uint8_t variable ( which was defined to store mask value). I change that variable from uint8_t to uint16_t.. the warning fixed, but now the compiled code takes just 2% of flash, which was 25% for 8- Axis. Obviously there is something wrong. Any idea 💡 what I am missing?.

@terjeio
Copy link
Contributor

terjeio commented Mar 16, 2023

Now I started adding 9th axis (W), there was a lot of modification and upgradation to code in almost all files.

Adding a 9+ axes will require changes in the core (the axis bit holder type has to be changed to 16 bits as you have found out). The most problematic will be that the NVS (EEPROM) layout has to be changed to accomodate that - could be tricky...

Do you have a use case for adding the 9th axis?

@MuhammadQaisarAli
Copy link
Author

MuhammadQaisarAli commented Mar 16, 2023

Adding a 9+ axes will require changes in the core (the axis bit holder type has to be changed to 16 bits as you have found out). The most problematic will be that the NVS (EEPROM) layout has to be changed to accomodate that - could be tricky...

Hmm..
Well, I changed the nvs.h file.
For 3 axis the nvs_end was 1023, while for more than 6 axis, it was 1151, which is 128 more than 1023 . As logical guess I added 256 to it, means I made nvs_end to be 1279. Although it was not calculated perfectly, but fortunately the code compiled and I was able to run 9 axis. The controller was checked with oscilloscope, ioSender and UGS as well.

I noticed two problems.
1: when the feed goes very high, the controller freezes and it's firmware settings are restored to default. But it happened only 2-3 times .

2: I created a random G-Code file for 9 axis, Used G1 command with 9 axis coordinates and a specific feed rate. I noticed that the feed rate on UGS is much higher than commanded feed rate, sometimes it goes to such a high feed rate, that controller can't generate pulses for, and as a result Controller freezes .

My firmware settings.
2uS for step time
250 steps/mm for all axis,
500000 mm/min for all axis
500 mm/sec^2 for all axis.

Rest of settings are default.

I generated the following random G code having 500 lines.
On each line, there is G1 followed by 9 axis, each axis can have random value between -250 and 250, followed by feed rate having random value between 50000 and 60000.

Do you have a use case for adding the 9th axis?

Well I believe, minimum number of basis axis to span a 3D object engraving is 5. Rest of axis are redundant.
But I am curious and want to touch the limits 😉.

@MuhammadQaisarAli
Copy link
Author

MuhammadQaisarAli commented Mar 17, 2023 via email

@terjeio
Copy link
Contributor

terjeio commented Mar 18, 2023

Uncomment this line to get a debug command, $Q, for the NVS layout.

There should not be any need to modify the NVS code itself, only the layout spec.

@terjeio terjeio closed this as completed Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants