USART tx length fix, some experiments with cpp string manip
This commit is contained in:
@@ -21,7 +21,7 @@ Usart::Usart(USART_TypeDef* usart, uint32_t baudRate, uint32_t wordLength, uint3
|
||||
.OverSampling = overSampling}} {}
|
||||
|
||||
bool Usart::init() {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
if (mHandle.Instance == USART2) {
|
||||
// USART2 clock enable
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
@@ -61,8 +61,12 @@ void Usart::println(const std::string_view str) {
|
||||
|
||||
void Usart::tx(const std::string_view range) {
|
||||
for (uint32_t pt{0}; pt <= range.size(); pt += TX_BUFSIZE) {
|
||||
HAL_UART_Transmit(&mHandle, reinterpret_cast<const uint8_t*>(range.begin() + pt),
|
||||
TX_BUFSIZE, TX_TIMEOUT_MS);
|
||||
uint8_t txLen{TX_BUFSIZE};
|
||||
if (range.length() < TX_BUFSIZE) {
|
||||
txLen = range.length();
|
||||
}
|
||||
HAL_UART_Transmit(&mHandle, reinterpret_cast<const uint8_t*>(range.begin() + pt), txLen,
|
||||
TX_TIMEOUT_MS);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user