Skip to content

bug: transmits 08F5 which is not content of buffer #18

@deanqx

Description

@deanqx
#include <util/delay.h>

int main(void) {
  uart0_init(BAUD_CALC(9600UL));
  while (1) {
    uart0_putint(1023);
    uart0_puts("\r\n");
    _delay_ms(1000);
  }
}

Using -Os -std=gnu99 to compile.

cat /dev/ttyUSB0 | xxd
00000000: 3130 3233 08f5 0a0a 3130 3233 08f5 0a0a  1023....1023....
00000010: 3130 3233 08f5 0a0a 3130 3233 08f5 0a0a  1023....1023....
00000020: 3130 3233 08f5 0a0a 3130 3233 08f5 0a0a  1023....1023....

Original uart0_putint function from the library (comment added):

void uart0_putint(int16_t data)
{
#ifndef USART_NO_LOCAL_BUFFERS
	char u_tmp_buff[7]; // heading, 5 digit bytes, NULL
#endif

	itoa(data, u_tmp_buff, 10);
	uart0_putstr(u_tmp_buff);
	// asm volatile("nop");
}

Adding the nop command fixes this bug.

asm volatile("nop");
$ cat /dev/ttyUSB0 | xxd
00000000: 3130 3233 0a0a 3130 3233 0a0a 3130 3233  1023..1023..1023
00000010: 0a0a 3130 3233 0a0a 3130 3233 0a0a 3130  ..1023..1023..10

I don't think anyone will review this. In case someone does: I can provide concrete compile commands and more details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions