From eebef017186cfbd2a4663c3dda1eb98dad6f1725 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Fri, 31 Jul 2015 03:08:52 +0000 Subject: [PATCH] stm32f1: remove artificial limit on gpio remap mask Connectivity line devices have more remaps available, and the existing code was artificially and needlessly preventing those remaps from being set, even if defined. While implementing this, the existing code to handle SWJ remap was found to be inconsistent with the reference manual and has been fixed. Fixes github issue #369 --- lib/stm32/f1/gpio.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/stm32/f1/gpio.c b/lib/stm32/f1/gpio.c index cbfdba81..669fd46e 100644 --- a/lib/stm32/f1/gpio.c +++ b/lib/stm32/f1/gpio.c @@ -161,14 +161,20 @@ this function as its current value cannot be ascertained from the hardware. @param[in] swjdisable Unsigned int8. Disable parts of the SWJ capability @ref afio_swj_disable. -@param[in] maps Unsigned int32. Bitwise OR of map enable controls from @ref -afio_remap, @ref afio_remap_can1, @ref afio_remap_tim3, @ref afio_remap_tim2, -@ref afio_remap_tim1, @ref afio_remap_usart3. For connectivity line devices -only @ref afio_remap_cld are also available. +@param[in] maps Unsigned int32. Bitwise OR of map enable controls you wish to +enable from @ref afio_remap, @ref afio_remap_can1, @ref afio_remap_tim3, +@ref afio_remap_tim2, @ref afio_remap_tim1, @ref afio_remap_usart3. For +connectivity line devices only @ref afio_remap_cld are also available. */ void gpio_primary_remap(uint32_t swjdisable, uint32_t maps) { - AFIO_MAPR |= (swjdisable & AFIO_MAPR_SWJ_MASK) | (maps & 0x1FFFFF); + /* + * the SWJ_CFG bits are write only. (read is explicitly undefined) + * To be sure we set only the bits we want we must clear them first. + * However, we are still trying to only enable the map bits desired. + */ + uint32_t reg = AFIO_MAPR & ~AFIO_MAPR_SWJ_MASK; + AFIO_MAPR = reg | swjdisable | maps; } /*---------------------------------------------------------------------------*/