Possible error in my STM32F100RC MCU memory
- December 21, 2016
- 3 replies
- 2448 views
Posted on December 21, 2016 at 09:01
Hello. I found something strange in my STM32F100RC controller. I made a clean project in latest CubeMX to show this error.
When I try toswitch my MCU from full JTAG (reset state) to use only SWD pins the programming/debug interface stops working completely. I was forced to reflow two ICs before I found there is the error with init procedure.
The code:
int main(void) {
uint32_t initPauseCounter = 0xFFFFF; // pause that helps us to burn new firmware
while(initPauseCounter--); // before SWD stops working
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
__HAL_AFIO_REMAP_SWJ_ENABLE();
printf('AFIO->MAPR state: 0x%08lX\n', READ_REG(AFIO->MAPR));
printf('AFIO_MAPR_SWJ_CFG_NOJNTRST: 0x%08lX\n', AFIO_MAPR_SWJ_CFG_NOJNTRST);
printf('writing...\n');
__HAL_AFIO_REMAP_SWJ_NONJTRST();
printf('AFIO->MAPR state: 0x%08lX\n\n', READ_REG(AFIO->MAPR));
printf('AFIO_MAPR_SWJ_CFG_JTAGDISABLE: 0x%08lX\n', AFIO_MAPR_SWJ_CFG_JTAGDISABLE);
printf('writing...\n');
__HAL_AFIO_REMAP_SWJ_NOJTAG();
printf('AFIO->MAPR state: 0x%08lX\n\n', READ_REG(AFIO->MAPR));
printf('AFIO_MAPR_SWJ_CFG_DISABLE: 0x%08lX\n', AFIO_MAPR_SWJ_CFG_DISABLE);
printf('writing...\n');
__HAL_AFIO_REMAP_SWJ_DISABLE();
printf('AFIO->MAPR state: 0x%08lX\n\n', READ_REG(AFIO->MAPR));
while (1);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?It uses only SWD pins, USART1 and clocking from external oscillator. printf() function just redirecting output to USART1 by redefinition fputc() function.
Result from my device with F100RC MCU:
AFIO->MAPR state: 0x00000000
AFIO_MAPR_SWJ_CFG_NOJNTRST: 0x01000000
writing...
AFIO->MAPR state: 0x02000000
AFIO_MAPR_SWJ_CFG_JTAGDISABLE: 0x02000000
writing...
AFIO->MAPR state: 0x06000000
AFIO_MAPR_SWJ_CFG_DISABLE: 0x04000000
writing...
AFIO->MAPR state: 0x0E000000
And from Discovery board with F100RB MCU:
AFIO->MAPR state: 0x00000000
AFIO_MAPR_SWJ_CFG_NOJNTRST: 0x01000000
writing...
AFIO->MAPR state: 0x01000000
AFIO_MAPR_SWJ_CFG_JTAGDISABLE: 0x02000000
writing...
AFIO->MAPR state: 0x03000000
AFIO_MAPR_SWJ_CFG_DISABLE: 0x04000000
writing...
AFIO->MAPR state: 0x07000000
As you can see I read from the AFIO->MAPR register not the data that Iwrote to it before. The values
0x03000000 and
0x07000000 does not match to any JTAG modes.
How can I work this out?