diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index c6582da4..b9333080 100644 --- a/ch32v003fun/ch32v003fun.c +++ b/ch32v003fun/ch32v003fun.c @@ -1211,13 +1211,21 @@ void handle_reset( void ) #if defined( FUNCONF_USE_UARTPRINTF ) && FUNCONF_USE_UARTPRINTF void SetupUART( int uartBRR ) { +#ifdef CH32V003 // Enable GPIOD and UART. RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_USART1; // Push-Pull, 10MHz Output, GPIO D5, with AutoFunction GPIOD->CFGLR &= ~(0xf<<(4*5)); GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP_AF)<<(4*5); - +#else + RCC->APB2PCENR |= RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1; + + // Push-Pull, 10MHz Output, GPIO A9, with AutoFunction + GPIOA->CFGHR &= ~(0xf<<(4*1)); + GPIOA->CFGHR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP_AF)<<(4*1); +#endif + // 115200, 8n1. Note if you don't specify a mode, UART remains off even when UE_Set. USART1->CTLR1 = USART_WordLength_8b | USART_Parity_No | USART_Mode_Tx; USART1->CTLR2 = USART_StopBits_1; diff --git a/ch32v003fun/ch32v003fun.h b/ch32v003fun/ch32v003fun.h index cf6e7e3a..ca69c05f 100644 --- a/ch32v003fun/ch32v003fun.h +++ b/ch32v003fun/ch32v003fun.h @@ -30,6 +30,12 @@ poll_input, handle_debug_input may be used with semihsoting. Note: Semihosting appears to currently only work on the CH32V003 (may be improved in future) + + For UART printf, on: + CH32V003, Port D5, 115200 8n1 + CH32V203, Port A9, 115200 8n1 + + Modifications can be made to SetupUart, or your own version as desired. */ diff --git a/minichlink/pgm-wch-linke.c b/minichlink/pgm-wch-linke.c index 36f41433..b37ae824 100644 --- a/minichlink/pgm-wch-linke.c +++ b/minichlink/pgm-wch-linke.c @@ -337,9 +337,11 @@ static int LESetupInterface( void * d ) return -1; wch_link_multicommands( (libusb_device_handle *)dev, 1, 4, "\x81\x0d\x01\x13" ); // Try forcing reset line low. + wch_link_command( (libusb_device_handle *)dev, "\x81\x0d\x01\xff", 4, 0, 0, 0); //Exit programming if( already_tried_reset > 3 ) { + MCF.DelayUS( iss, 5000 ); wch_link_command( dev, "\x81\x0d\x01\x03", 4, (int*)&transferred, rbuff, 1024 ); // Reply: Ignored, 820d050900300500 } else @@ -347,7 +349,6 @@ static int LESetupInterface( void * d ) MCF.DelayUS( iss, 5000 ); } - wch_link_multicommands( (libusb_device_handle *)dev, 3, 4, "\x81\x0b\x01\x01", 4, "\x81\x0d\x01\x02", 4, "\x81\x0d\x01\xff" ); wch_link_multicommands( (libusb_device_handle *)dev, 1, 4, "\x81\x0d\x01\x14" ); // Release reset line. wch_link_multicommands( (libusb_device_handle *)dev, 3, 4, "\x81\x0b\x01\x01", 4, "\x81\x0d\x01\x02", 4, "\x81\x0d\x01\xff" ); already_tried_reset++;