-
Notifications
You must be signed in to change notification settings - Fork 64
STM32Fx: Customizing
µCNC for STM32F10x can be configured/customized to fit different STM32F10x powered boards other than Blue Pill
Jump to section
µCNC for STM32F1x/STM32F4x 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/stm32/ directory and then the respective board file.
µCNC for STM32F1x/STM32F4x is like for AVR but takes an extra step if you are using a board with a different STM32F1x/STM32F4xflavor other then the STM32F10x03C8 used in the Blue Pill board. It's necessary to create the boiler-plate project to fit your particular MCU. The Blue Pill source code is a good example on how to implement this. It's mostly written in plain C and it's mainly bare-metal (no vendor HAL or middleware). The only stack used is the tinyUSB library for the USB VCP port that works on a wide range of MCU's. The pinout configuration follows (almost all of) the STM32 Grbl pinout.
STM32F4 lacks EEPROM emulation. Storing settings will not be possible. That means that they have to be loaded at startup. Also coordinate systems will be lost on restart.
This is similar to the general customization instructions
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. STM32F1x/STM32F4x has 16 External Interrupts that can be assign to one input of a single port. For example External Interrupt 0 can only be assigned to pin 0 of one of the Ports (A or B or C or ...). For Blue Pill the pin mapping can be checked here.
For Black Pill the pin mapping can be checked here.
This is similar to the general customization instructions
This is similar to the general customization instructions
To configure the pwm clock, the used channel and timer must be supplied. To find the used channel register and timer we must check the MCU datasheet. Looking at the pin mapping shown above for Blue Pill and knowing that we are going to use pin A8 has the spindle pwm control we can see that the pwm on that pin is generated via Timer1 - Channel 1.
/Setup PWM
#define PWM0_BIT 8 //assigns PWM0 pin
#define PWM0_PORT A //assigns PWM0 pin
#define PWM0_CHANNEL 1
#define PWM0_TIMER 1
Although not used anywhere inside µCNC reading analog pins is possible. Beside configuring the pin like an input pin, two more definitions are needed to configure the AVR analog reading. These are setting the channel and the desired prescaller for the conversion. For example on STM32F1 ADC0 (Analog channel 0) is on pin A0. To configure it as µCNC's ANALOG0 input add the following code to the boardmap file:
#define ANALOG0_BIT 0
#define ANALOG0_PORT A
#define ANALOG0_CHANNEL 0 //STM32F1 channel 0
To make a read just do
uint8_t value = mcu_get_analog(ANALOG0);
This is similar to the general customization instructions
Systick is used as the RTC Timer so the RTC_Timer configuration as not effect.
This is similar to the general customization instructions
µ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