gewiss schrieb:
> Wie finde ich den Fehler?
Google?
https://os.mbed.com/questions/76094/how-to-use-STM32F103RB-CAN/
https://community.st.com/s/question/0D50X00009XkevESAR/lost-swd-debugging-connection-at-halafioremapcan12-
Wenn man sich den Sourcecode der Makros anschaut:
1 | #define __HAL_AFIO_REMAP_CAN1_2() AFIO_REMAP_PARTIAL(AFIO_MAPR_CAN_REMAP_REMAP2, AFIO_MAPR_CAN_REMAP)
|
2 |
|
3 | #define AFIO_REMAP_PARTIAL(REMAP_PIN, REMAP_PIN_MASK) do{ uint32_t tmpreg = AFIO->MAPR; \
|
4 | tmpreg &= ~REMAP_PIN_MASK; \
|
5 | tmpreg |= AFIO_MAPR_SWJ_CFG; \
|
6 | tmpreg |= REMAP_PIN; \
|
7 | AFIO->MAPR = tmpreg; \
|
8 | }while(0U)
|
9 |
|
10 | /*!< SWJ_CFG configuration */
|
11 | #define AFIO_MAPR_SWJ_CFG_Pos (24U)
|
12 | #define AFIO_MAPR_SWJ_CFG_Msk (0x7U << AFIO_MAPR_SWJ_CFG_Pos) /*!< 0x07000000 */
|
13 | #define AFIO_MAPR_SWJ_CFG AFIO_MAPR_SWJ_CFG_Msk /*!< SWJ_CFG[2:0] bits (Serial Wire JTAG configuration) */
|
14 |
|
15 | /*!< CANRX mapped to PA11, CANTX mapped to PA12 */
|
16 | #define AFIO_MAPR_CAN_REMAP_REMAP2_Pos (14U)
|
17 | #define AFIO_MAPR_CAN_REMAP_REMAP2_Msk (0x1U << AFIO_MAPR_CAN_REMAP_REMAP2_Pos) /*!< 0x00004000 */
|
18 | #define AFIO_MAPR_CAN_REMAP_REMAP2 AFIO_MAPR_CAN_REMAP_REMAP2_Msk /*!< CANRX mapped to PB8, CANTX mapped to PB9 */
|
19 |
|
20 | #define AFIO_MAPR_CAN_REMAP_Pos (13U)
|
21 | #define AFIO_MAPR_CAN_REMAP_Msk (0x3U << AFIO_MAPR_CAN_REMAP_Pos) /*!< 0x00006000 */
|
22 | #define AFIO_MAPR_CAN_REMAP AFIO_MAPR_CAN_REMAP_Msk /*!< CAN_REMAP[1:0] bits (CAN Alternate function remapping) */
|
erhält man als (fast) vollständig substituierte Version:
1 | do{ uint32_t tmpreg = AFIO->MAPR; \
|
2 | tmpreg &= ~(3 << 13);
|
3 | tmpreg |= (7 << 24);
|
4 | tmpreg |= (1 << 14);
|
5 | AFIO->MAPR = tmpreg;
|
6 | }while(0U);
|
Das bedeutet es wird korrekt CAN auf Modus 2 geschaltet:
"10: CAN_RX mapped to PB8, CAN_TX mapped to PB9 (not available on 36-pin
package)"
Allerdings wird so ganz nebenbei auch "7" auf "Serial wire JTAG
configuration" geschrieben. Angeblich hat das "Other combinations: no
effect". Da es bei dir ja zu Problemen kommt, würde ich stattdessen mal
die gewünschte Konfiguration drüberschreiben.
Aus deinem Pixelmatsch-Schaltplan ist leider nur vage zu erraten dass du
SWD benutzt. Um also SWD aktiviert zu lassen, versuche statt des
Makro-Aufrufs mal:
1 | AFIO->MAPR = (AFIO->MAPR & ~(AFIO_MAPR_CAN_REMAP_Msk | AFIO_MAPR_SWJ_CFG_Msk)) | AFIO_MAPR_CAN_REMAP_REMAP2_Msk | AFIO_MAPR_SWJ_CFG_JTAGDISABLE_Msk;
|
Für SWD+JTAG entsprechend AFIO_MAPR_SWJ_CFG_RESET nehmen.