IO Pin as External Input

Set these two IOs as input ports, and determine by checking their high/low level.

What chip model are you using?
hwp_pbr corresponds to PBR0~PBR5, not PB51.
It is recommended to directly use:
HAL_PIN_Set(PAD_PB51, GPIO_B51, PIN_PULLUP, 0);
rt_pin_mode(PIN_PB51, PIN_MODE_INPUT_PULLUP); to set pull-up input