Closed terjeio closed 1 month ago
@datadev Since USB is the default comm channel it has to be commented out in my_machine.h. Have you done that?
Yes I have done that Idk if I have to define all the other pins to adapt to my current board (sorry for not mentioning this before) to make whole things work?
This is my custom map pins to adapt the board of mine:
// file_name: "my_board_map.h"
#define BOARD_NAME "MY BOARD"
#define HAS_BOARD_INIT
#define SERIAL_PORT 2 // GPIOA: TX = 2, RX = 3
// Define step pulse output pins.
#define X_STEP_PORT GPIOD
#define X_STEP_PIN 13 // X
#define Y_STEP_PORT GPIOD
#define Y_STEP_PIN 11 // Y
#define Z_STEP_PORT GPIOE
#define Z_STEP_PIN 2 // Z
#define STEP_OUTMODE GPIO_BITBAND
//#define STEP_PINMODE PINMODE_OD // Uncomment for open drain outputs
// Define step direction output pins.
#define X_DIRECTION_PORT GPIOD
#define X_DIRECTION_PIN 12
#define Y_DIRECTION_PORT GPIOB
#define Y_DIRECTION_PIN 15
#define Z_DIRECTION_PORT GPIOE
#define Z_DIRECTION_PIN 3
#define DIRECTION_OUTMODE GPIO_BITBAND
//#define DIRECTION_PINMODE PINMODE_OD // Uncomment for open drain outputs
// Define homing/hard limit switch input pins.
#define X_LIMIT_PORT GPIOA
#define X_LIMIT_PIN 11 // X- Limit
#define Y_LIMIT_PORT GPIOA
#define Y_LIMIT_PIN 12 // Y- Limit
#define Z_LIMIT_PORT GPIOB
#define Z_LIMIT_PIN 12 // Z- Limit
#define LIMIT_INMODE GPIO_BITBAND
// EOF
To adapt the project that I am doing, the board just need these several pins so I just remove unused features. Note that, I will use USART2 serial port which is PA2 and PA3 pins to receive ad send command between my laptop and the MCU.
Components for thermistor conditioning on the inputs are interfering? Or are you testing with your own board?
FYI my Nucleo-64 board works with the port, from the $pins
output:
[PIN:PA3,RX,Primary UART]
[PIN:PA2,TX,Primary UART]
Sure, I am using a custom-built board with an STM32F407VET6 microcontroller. My goal is to connect the desired USART port (RS232) between my laptop and the MCU to drive the stepper motors without any additional external sensors. I believe I may have made some errors in the configuration process.
Could you please guide me on how to properly configure the STM32F407VET6 to use the desired serial port? Specifically, I would like to know which files and settings I need to customize in STM32CubeIDE, given that I am using my own custom board.
Alternatively, I am open to using PlatformIO for this project. This platform is new to me, but if you can provide a detailed procedure, I would greatly appreciate it.
I don't know if there was something I am missed.
driver.json
:
{
"name": "MY BOARD MAP",
"symbol": "MY_BOARD",
"MAP": "boards/my_board_map.h",
"caps": {
"uart": 1,
"axes": 3,
"serial_ports": 1
},
"symbols": {
"STM32F407xx": "",
"HSE_VALUE": 8000000
}
},
platformio.ini
:
[env:my_board]
# Untested and might not boot. Please report issues at:
# https://github.com/grblHAL/STM32F4xx/issues
board = genericSTM32F407VGT6
board_build.ldscript = STM32F407VGTX_FLASH.ld
build_flags = ${common.build_flags}
# See Inc/my_machine.h for options
-D MY_BOARD=
-D HSE_VALUE=8000000
-D USB_SERIAL_CDC=1
-D VECT_TAB_OFFSET=0x8000
lib_deps = ${common.lib_deps}
eeprom
lib_extra_dirs = ${common.lib_extra_dirs}
I use STM32CubeIDE
Then driver.json (only for the Web Builder) and platformio.ini is not used by the build process. Modify _mymachine.ini instead. Uncomment this line to make the compiler use your board definition.
Idk if I have to define all the other pins to adapt to my current board (sorry for not mentioning this before) to make whole things work?
No - but some may be required, the compiler will complain if they are. BTW when you edit a comment I am not notified, when doing so add a new comment telling me a bout the edit or just add a new one instead.
This is my_machine_map.h
file:
#define BOARD_NAME "MY BOARD"
#define HAS_BOARD_INIT
#define SERIAL_PORT 2 // GPIOA: TX = 2, RX = 3
// Define step pulse output pins.
#define X_STEP_PORT GPIOD
#define X_STEP_PIN 13 // X
#define Y_STEP_PORT GPIOD
#define Y_STEP_PIN 11 // Y
#define Z_STEP_PORT GPIOE
#define Z_STEP_PIN 2 // Z
#define STEP_OUTMODE GPIO_BITBAND
//#define STEP_PINMODE PINMODE_OD // Uncomment for open drain outputs
// Define step direction output pins.
#define X_DIRECTION_PORT GPIOD
#define X_DIRECTION_PIN 12
#define Y_DIRECTION_PORT GPIOB
#define Y_DIRECTION_PIN 15
#define Z_DIRECTION_PORT GPIOE
#define Z_DIRECTION_PIN 3
#define DIRECTION_OUTMODE GPIO_BITBAND
//#define DIRECTION_PINMODE PINMODE_OD // Uncomment for open drain outputs
// Define homing/hard limit switch input pins.
#define X_LIMIT_PORT GPIOA
#define X_LIMIT_PIN 11 // X- Limit
#define Y_LIMIT_PORT GPIOA
#define Y_LIMIT_PIN 12 // Y- Limit
#define Z_LIMIT_PORT GPIOB
#define Z_LIMIT_PIN 12 // Z- Limit
#define LIMIT_INMODE GPIO_BITBAND
// EOF
When I build the project using the "17 Release F407 8MHz" option, I encounter numerous warnings and errors related to features that my board does not use or support. How can I disable these features during the build process without affecting the original code? In other words, how can I achieve a clean build in the correct manner?
Alright, instead of removing the code, I have commented out all out the pin definitions, and now I just left with this error that I don't know how to fix:
18:53:57 **** Incremental Build of configuration Release F407 8MHz for project GRBL Driver STM32F401 ****
make -j8 all
arm-none-eabi-gcc -o "grblHAL F407 8MHz.elf" @"objects.list" -mcpu=cortex-m4 -T"C:\Users\ltd\Documents\STM32\GRBL Driver STM32F401\STM32F407VGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="grblHAL F407 8MHz.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -u _scanf_float -Wl,--start-group -lc -lm -Wl,--end-group
C:/ST/STM32CubeIDE_1.15.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.12.3.rel1.win32_1.0.100.202403111256/tools/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: grblHAL F407 8MHz.elf has a LOAD segment with RWX permissions
C:/ST/STM32CubeIDE_1.15.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.12.3.rel1.win32_1.0.100.202403111256/tools/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: ./Src/driver.o: in function `driver_init':
driver.c:(.text.driver_init+0x3a4): undefined reference to `board_init'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:110: grblHAL F407 8MHz.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.
18:53:59 Build Failed. 2 errors, 1 warnings. (took 1s.710ms)
Uncomment this line in your map file
#define HAS_BOARD_INIT
Uncomment this line in your map file
You meant comment the line, I did and built successfully. However, the board still can't connect with the laptop via USART:
Check that the correct code is active, e.g. here (driver.c):
and here (serial.c):
The code that is on a grey background is not used.
If you hover over a symbol such as SERIAL_PORT above you can see the value. Is it correct (2)?
FYI it is sometimes neccesary to rebuild the index to get it working correctly, right click on the project and select Index > Rebuild from the popup menu to do that.
I assume you are using a UART <> USB breakout board (or onboard chip) for communicating. Is that correctly wired? Can you scope the TX pin? Any output on that? If you connect with a terminal such as putty and then reset the board do you get any output in the terminal? If you are programming the board via a ST-link then set breakpoints to check that the code is reached. E.g. in serialPutC() and the related interrupt handler (UART0_IRQHandler). Reset the board via the debugger when doing so - the startup message is output when initialization is complete.
Yes, I have checked them all:
When I scope the TX pin, it stays HIGH all the time (from the beginning after I reset the board).
I am unsure if the issue arises from using a different chip, specifically the STM32F407VET6 instead of the STM32F407VGT6. After building and compiling the code, it does not work as expected. Could this discrepancy be the source of the problem?
For the debugging, I toggled the breakpoints here as you said:
And it did not meet any breakpoints and ended up in this line:
Ok, then something goes badly wrong during startup. Set breakpoints in driver.c to figure out where/what. Start with driver_init(), is it entered and does it complete? If so then check driver_setup()...
Alright, found this in grbllib.c
, when I step into this function, it brings me to the HardFault_Handler
function:
Then either is hal.coolant.set_state is null or coolantSetState() (which hal.coolant.set_state points to) in driver.c fails.
I believe I just need to comment out that section since I am not using the coolant feature. However, I encountered another issue. The execution gets stuck at the following line and cannot proceed past this statement:
Additionally, I would like to ask for more guidance. If I continue debugging like this, I am unsure where to start and stop. Specifically, where does the code loop in the GRBL command send and receive streaming mode?
Specifically, where does the code loop in the GRBL command send and receive streaming mode?
Inside protocol_main_loop(), this function only returns on a soft reset (CTRL-X received or the grblHAL reset input asserted).
After redefining the coolant pins and uncommenting the related code, I was able to successfully run and connect the STM32F407VGT6 (test board). However, I am unable to achieve the same result with the STM32F407VET6 (current project-running board).
The primary difference between these two chips is the flash memory size: the "G" variant has 1024 KBytes, while the "E" variant has 512 KBytes. How can I easily port the project from the "G" variant to the "E" variant?
In the STM32F407VETX_FLASH.ld file auto-generated by the IDE, the memory configuration includes:
I modified the memory section of the VGT6 ld file as follows:
MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
BOOT_FLASH(rx) : ORIGIN = 0x08000000, LENGTH = 16K
EEPROM_EMUL(xrw) : ORIGIN = 0x08004000, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 512K - 16K - 16K
}
Additionally, I added the following section for CCMRAM:
_siccmram = LOADADDR(.ccmram);
/* CCM-RAM section
*
* IMPORTANT NOTE!
* If initialized variables are placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.ccmram :
{
. = ALIGN(4);
_sccmram = .; /* create a global symbol at ccmram start */
*(.ccmram)
*(.ccmram*)
. = ALIGN(4);
_eccmram = .; /* create a global symbol at ccmram end */
} >CCMRAM AT> FLASH
After building and uploading it, seemed like not working. Am I do it correctly?
Although I can connect to the board and it works pretty well, however, I don't know if I should re-map the memory?
I don't know if I should re-map the memory?
If it is working now then you do not need to. This since nothing is stored at the higher end of the flash.
I think this is a good startup for the setup process. Thank you for helping me @terjeio. Guess that we can close this issue now.
I am using STM32F407VET6, in GRBLHAL, there is STM32F407VGT6 using BTT SKR 2.0 board with default USART1, I have changed to USART2 in the code, but it did not work when I connect that 2 pins between the laptop and the MCU I use STM32CubeIDE, to build the selected project which issues STM32F4 8MHz
This is what I have modified in the code:
Originally posted by @datdadev in https://github.com/grblHAL/STM32F4xx/issues/77#issuecomment-2238571477