8 years, 1 month ago.

Serial on STM32F031K6

Hi,

I'm having issues with getting serial working on the pins I want on the F031K6 which were working on the F042K6.

The F031K6 has labeled in their spec sheets that Pins: PA2 & PA3 can be used as USART1_TX and USART1_RX, respectively.

The F042K6 has USART2_TX, USART2_RX for pins PA2 & PA3.

This works as per spec sheet on the F042K6, but if I try to run the code on the F031K6 it freezes up and the uController doesn't do anything. If I comment out the Serial object the problem goes away.

I've noticed that the mbed diagram doesn't have both of these on there as well.

What gives? It seems like both of these should work the same.

1 Answer

8 years, 1 month ago.

There are more problems with F031K6. Eg. I2C does not work on pins PA_10, PA_9.

The source of all these problems is in the file:
targets/hal/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/PeripheralPins.c .

After my changes in this file, serial on PA_3 works. I checked.

To fix the RX pin PA_3, you need to use in project library library-dev instead mbed and edit this file.

Arrays of uart pins after correction:

//*** SERIAL ***

const PinMap PinMap_UART_TX[] = {
    {PA_2,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, // STDIO TX
    {PA_9,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
//  {PA_14, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, // SWCLK
    {PB_6,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
    {NC,    NC,     0}
};

const PinMap PinMap_UART_RX[] = {
    {PA_3, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
    {PA_10, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)},
    {PA_15, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_USART1)}, // STDIO RX
    {PB_7,  UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
    {NC,    NC,     0}
};


and for I2C:

//*** I2C ***

const PinMap PinMap_I2C_SDA[] = {
    {PA_10, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
    {PB_7,  I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)},
    {NC,    NC,    0}
};

const PinMap PinMap_I2C_SCL[] = {
    {PA_9,  I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
    {PB_6,  I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF1_I2C1)},
    {NC,    NC,    0}
};


I do not have time right now to check the rest of the file, so I do not know if everything else is ok. But if you need, just compare the tables 12 and 13 in the datasheet with the file.

Accepted Answer