We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
There is a Keil example that shows how to redirect 'printf' located in the Keil directory: C:\Keil\ARM\Boards\Keil\MCBSTM32E\RTX_Traffic
I am following this example copying 'Retarget.c' and 'Serial.c' into my project. I have also added UART initialization code.
At this point the following printf works great:
printf("-Performing Hardware Initialization\n");
However, when calling 'printf' with a different argument as shown below:
unsigned int stacked_r0 = 0xaa00bb11; ... printf ("R0 = %x\n", stacked_r0);
the tools (uVision and JTAG) lose connection with the target board. To get connected to the target board I have to hold the Reset button and let go of it just before attempting to connect. Otherwise it is unsuccessful connecting to the target board. Why would this be? Is there a missing library?
Hi,
1. did you try switching to SW and then connect?
2. Did you check if you probably override JTAG Pins with the UART Initialization?
> I have also added UART initialization code Did you work with
Reg &= ~(clear mask); Reg |= Bits to Write
? It is possible that you override the Port Pin configuration to the JTAG Port with the UART Init.
Example 1 (Bit on / off):
// Bit_on, bit_off definitions #define bit_on(BYTE, BIT) { BYTE |= 1 << BIT; } #define bit_off(BYTE, BIT) { BYTE &= ~(1 << BIT); }
Example 2 (Port Initialisation):
// AF enable #define AFIO_EN 0 // Alternate Function Enable // GPIO enable #define IOPA_EN 2 // GPIO A enable #define IOPB_EN 3 // GPIO B enable #define IOPC_EN 4 // GPIO C enable #define IOPD_EN 5 // GPIO D enable #define IOPE_EN 6 // GPIO E enable #define IOPF_EN 7 // GPIO F enable #define IOPG_EN 8 // GPIO G enable // DAC Enable #define DAC_EN 29 #define GPIO_CONF_BIT(BIT) ((BIT>7? BIT-8 : BIT) << 2) // 4Bits per port pin // Mode and Conf Bits #define MODE0 (unsigned int)0 #define MODE1 (unsigned int)1 #define CONF0 (unsigned int)2 #define CONF1 (unsigned int)3 // Port Mode #define GPIO_MODE_INPUT (((unsigned int)0<<MODE0) | ((unsigned int)0<<MODE1)) // GPIO is input #define GPIO_SPEED_2MHZ (((unsigned int)0<<MODE0) | ((unsigned int)1<<MODE1)) // Max output Speed 2MHz #define GPIO_SPEED_10MHZ (((unsigned int)1<<MODE0) | ((unsigned int)0<<MODE1)) // Max output Speed 10MHz #define GPIO_SPEED_50MHZ (((unsigned int)1<<MODE0) | ((unsigned int)1<<MODE1)) // Max output Speed 50MHz // Port Conf #define GPIO_OUT_PUSH_PULL (((unsigned int)0<<CONF0) | ((unsigned int)0<<CONF1)) // general purpose output push-pull #define GPIO_AF_PUSHPULL (((unsigned int)0<<CONF0) | ((unsigned int)1<<CONF1)) // alternate function push-pull #define GPIO_IN_FLOATING (((unsigned int)1<<CONF0) | ((unsigned int)0<<CONF1)) // input floating #define GPIO_IN_ANALOG (((unsigned int)0<<CONF0) | ((unsigned int)0<<CONF1)) // input analog #define GPIO_IN_PULL_DOWN (((unsigned int)0<<CONF0) | ((unsigned int)1<<CONF1)) // alternate function push-pull #define GPIO_IN_PULL_UP (((unsigned int)0<<CONF0) | ((unsigned int)1<<CONF1)) // alternate function push-pull int led_init(void) { bit_on(RCC->APB2ENR, IOPB_EN); // enable PORT B GPIOB->CRH = ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(8)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(9)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(10)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(11)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(12)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(13)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(14)) | \ ((GPIO_OUT_PUSH_PULL | GPIO_SPEED_2MHZ) << GPIO_CONF_BIT(15)); return(0); }
. BR, /th.