Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified Documentation/PY32F002B_User_Manual.chm
Binary file not shown.
178 changes: 178 additions & 0 deletions Drivers/BSP/PY32F002Bxx_Start_Kit/py32f002bxx_Start_Kit.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ void BSP_PB_DeInit(Button_TypeDef Button)
*/
uint32_t BSP_PB_GetState(Button_TypeDef Button)
{
#if StartKitVersion == 2
return (HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]) == GPIO_PIN_RESET);
#else
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
#endif
}

#ifdef HAL_UART_MODULE_ENABLED
Expand Down Expand Up @@ -327,6 +331,180 @@ int __io_putchar(int ch)
return ch;
}

int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx=0;DataIdx<len;DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}
#endif
#else
static uint32_t ReloadD = 0;
static uint32_t MinD = 0;

/**
* @brief GPIO Config As USART
* @param None
* @retval None
*/
void BSP_USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};

DEBUG_USART_TX_GPIO_CLK_ENABLE();

GPIO_InitStruct.Pin = DEBUG_USART_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /* Push-pull output */
GPIO_InitStruct.Pull = GPIO_PULLUP; /* Enable pull-up */
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; /* GPIO speed */
/* GPIO Initialization */
HAL_GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,GPIO_PIN_SET);
ReloadD = SysTick->LOAD;
MinD = (ReloadD+1)*10/96;
}

/**
* @brief writes a character to the usart
* @param SystickStart
* @param ReloadData
* @param MinData
* @retval NULL
*/
static void BSP_Delay(uint32_t SystickStart,uint32_t ReloadData, uint32_t MinData)
{
uint32_t SystickCurrent = 0;
while(1)
{
SystickCurrent = SysTick->VAL;

if(SystickCurrent < SystickStart)
{
if((SystickStart-SystickCurrent) >= MinData)
{
break;
}
}
else
{
if(SystickCurrent <= (ReloadData+1 - MinData + SystickStart))
{
break;
}
}
}
}

/**
* @brief writes a character to the usart
* @param ch
* *f
* @retval the character
*/
static void BSP_TransmitChar(uint8_t ch)
{
uint8_t temp = 0;
uint32_t SystickStart = SysTick->VAL ;

for(uint8_t i=0;i<10;i++)
{
if(i==0)
{
HAL_GPIO_WritePin(DEBUG_USART_TX_GPIO_PORT,DEBUG_USART_TX_PIN,GPIO_PIN_RESET);
}
else if(i == 9)
{
BSP_Delay(SystickStart, ReloadD, MinD);

HAL_GPIO_WritePin(DEBUG_USART_TX_GPIO_PORT,DEBUG_USART_TX_PIN,GPIO_PIN_SET);

if(SystickStart >= MinD)
{
SystickStart = SystickStart - MinD;
}
else
{
SystickStart = ReloadD + 1 + SystickStart - MinD;
}
BSP_Delay(SystickStart, ReloadD, MinD);
}
else
{
temp=ch&0x01;
BSP_Delay(SystickStart, ReloadD, MinD);
switch(temp)
{
case 1:
{
HAL_GPIO_WritePin(DEBUG_USART_TX_GPIO_PORT,DEBUG_USART_TX_PIN,GPIO_PIN_SET);
break;
}
case 0:
{
HAL_GPIO_WritePin(DEBUG_USART_TX_GPIO_PORT,DEBUG_USART_TX_PIN,GPIO_PIN_RESET);
break;
}

default: break;
}
ch>>=1;
if(SystickStart > MinD)
{
SystickStart = SystickStart - MinD;
}
else
{
SystickStart = ReloadD + 1 + SystickStart - MinD;
}
}
}
}

#if (defined (__CC_ARM)) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
/**
* @brief writes a character to the usart
* @param ch
* *f
* @retval the character
*/
int fputc(int ch, FILE *f)
{
BSP_TransmitChar(ch);
return (ch);
}


#elif defined(__ICCARM__)
/**
* @brief writes a character to the usart
* @param ch
* *f
* @retval the character
*/
int putchar(int ch)
{
/* Send a byte to USART */
BSP_TransmitChar(ch);

return (ch);
}
#elif defined(__GNUC__)
/**
* @brief writes a character to the usart
* @param ch
* @retval the character
*/
int __io_putchar(int ch)
{
/* Send a byte to USART */
BSP_TransmitChar(ch);

return ch;
}

int _write(int file, char *ptr, int len)
{
int DataIdx;
Expand Down
9 changes: 9 additions & 0 deletions Drivers/BSP/PY32F002Bxx_Start_Kit/py32f002bxx_Start_Kit.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ typedef enum
BUTTON_MODE_EXTI = 1
} ButtonMode_TypeDef;

#define StartKitVersion 2
/* #define StartKitVersion 1 */

#define LEDn 1

#define LED3_PIN GPIO_PIN_1
Expand Down Expand Up @@ -137,6 +140,12 @@ typedef enum

#define DEBUG_USART_IRQHandler USART1_IRQHandler
#define DEBUG_USART_IRQ USART1_IRQn

#else

#define DEBUG_USART_TX_GPIO_PORT GPIOB
#define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define DEBUG_USART_TX_PIN GPIO_PIN_4
#endif
/************************************************************/

Expand Down
Loading