STM32Fx: Customizing - Paciente8159/uCNC GitHub Wiki

µCNC for STM32F10x can be configured/customized to fit different STM32F10x powered boards other than Blue Pill

Jump to section

Customizing boardmap

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

Important note on STM32F4

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.

Configure IO pin

This is similar to the general customization instructions

Input pin options

Weak input pull-ups

All input pins can have a weak pull-up activated to drive them high if unconnected. This is similar to the general customization instructions

External interrupt feature

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. Blue Pill pin mapping

For Black Pill the pin mapping can be checked here. Black Pill pin mapping

This is similar to the general customization instructions

Configure communications

This is similar to the general customization instructions

Configure pwm clock

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 

Configure analog channel

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);

Configure step generator timer

This is similar to the general customization instructions

Systick is used as the RTC Timer so the RTC_Timer configuration as not effect.

Configure servo pins

This is similar to the general customization instructions