Skip to content

Full Alternate function management for F1 series #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2017

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Aug 19, 2017

This add all AFIO REMAP for STM32 F1 series

@fpistm fpistm requested a review from a user August 19, 2017 11:27
@fpistm fpistm self-assigned this Aug 19, 2017
@fpistm fpistm added this to the next release milestone Aug 19, 2017
@RickKimball
Copy link
Contributor

RickKimball commented Aug 19, 2017

I gave this a try on the DISCO_F100RB, no difference, Serial.print() works fine but Serial.available() never gets any data. I went into debug. Again it seems to enter USART2_IRQHandler for output but never for input.

This works now thanks to your pin map changes, thanks!
pinMode(PC8,OUTPUT);

One thing I did notice is that the DISCO_F100RB is using the HSI. This board has both an 8MHz HSE and a 32K xtal.

I put a scope on the pin and we are back to the situation where the TX pin works and the RX pin doesn't work. In addition, the pin signal level it low instead of high.

I think the problem is that the RX pin isn't being set to input. I used the debugger to stop in uart_init
When I looked at the GPIO_InitStruct of the UART_RX pin just before it called HAL_GPIO_Init()
the mode was wrong. I used to debugger to override the value before HALL_GPIO_Init() was called. I hand set the Mode to 0 instead of 2

uart_init (obj=obj@entry=0x20000218 <Serial+148>) at ~/Arduino/hard
ware/st/stm32_alt/cores/arduino/stm32/uart.c:224
(gdb) p GPIO_InitStruct 
$12 = {Pin = 8, Mode = 2, Pull = 0, Speed = 3}
(gdb) set GPIO_InitStruct.Mode = 0
(gdb) p GPIO_InitStruct 
$13 = {Pin = 8, Mode = 0, Pull = 0, Speed = 3}

I let the debugger continue and it magically started working.

I think Line 216 in uart_init.c should be setting Mode to 0

 GPIO_InitStruct.Mode        = STM_PIN_MODE(pinmap_function(obj->pin_rx,PinMap_UART_RX));

However, It is getting set to 2

To fix this, I went into PeripheralPins.c and made PA_3 an input

#ifdef HAL_UART_MODULE_ENABLED
 const PinMap PinMap_UART_RX[] = {
-    {PA_3,  USART2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, AFIO_NONE)},
+    {PA_3,  USART2,  STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, AFIO_NONE)},

That works. So the pinmap_gen thing needs to do the right thing for all RX pins.

Thanks for looking into this problem!

working

@fpistm
Copy link
Member Author

fpistm commented Aug 19, 2017

Hum interesting.
After checking it seems that for F1 in PeripheralPins.c, we need to set:
STM_MODE_INPUT
instead of
STM_MODE_AF_PP

See the Mbed one for Nucleo-F103RB:
https://developer.mbed.org/users/mbed_official/code/mbed-dev/file/default/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/PeripheralPins.c
I need to understand why but probably linked to specific AF...
I will do the test with Nucleo-F103RB.
Thanks @RickKimball for your time and sorry to not saw this before....
Edit: same for CAN_RD.

@fpistm
Copy link
Member Author

fpistm commented Aug 20, 2017

For F1, AF implies to configure as INPUT. For Other series, AF is a specific GPIO config which handle Input or Output depending of the AF selected.
I will update PeripheralPins.c for UART RX and Can RD.

@fpistm fpistm merged commit 644ea7a into stm32duino:master Aug 21, 2017
@fpistm fpistm deleted the F1_AF branch August 21, 2017 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants