Connect 4 pins from your STM32 to the pins labeled 1,2,4,8 on the rotary DIP switch. For example, using PORTA
PORTA pin 0 connects to pin "1" of DIP
PORTA pin 1 connects to pin "2" of DIP
PORTA pin 2 connects to pin "4" of DIP
PORTA pin 3 connects to pin "8" of DIP
Then at setup, determine the value of the DIP switch
uint8_t DIP_VALUE = 0;
DIP_VALUE = (uint8_t) (PORTA_IN & 0x0F);
If the modbus address is 8 bits, you can then OR DIP_VALUE to a common address, lets say 0xA0
address = 0xA0 | DIP_VALUE;
So depending on what type of DIP switch you have, you can have the following addresses depending on the value of the DIP
0xA0
0xA1
0xA2
0xA3
0xA4
0xA5
0xA6
0xA7
0xA8
0xA9
0xAA
0xAB
0xAC
0xAD
0xAE
0xAF