Giter Site home page Giter Site logo

UART problem about usb-sniffer-lite HOT 13 OPEN

noobestguy avatar noobestguy commented on July 17, 2024
UART problem

from usb-sniffer-lite.

Comments (13)

ataradov avatar ataradov commented on July 17, 2024

How exactly it does not work? How it was tested? This code is directly from the starter project that works.

Build the original starter project and check that it works on your hardware.

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

I've done exactly that, and it doesn't work! I'm receiving garbage

static void uart_init(uint32_t baud)
{
  RESETS_CLR->RESET = RESETS_RESET_uart0_Msk;
  while (0 == RESETS->RESET_DONE_b.uart0);

  baud = (F_PER * 4) / baud;

  UART0->UARTIBRD = baud / 64;
  UART0->UARTFBRD = baud % 64;

  UART0->UARTLCR_H = (3/*8 bits*/ << UART0_UARTLCR_H_WLEN_Pos) | UART0_UARTLCR_H_FEN_Msk;
  UART0->UARTCR = UART0_UARTCR_UARTEN_Msk | UART0_UARTCR_RXE_Msk | UART0_UARTCR_TXE_Msk;

  HAL_GPIO_UART_TX_init();
  HAL_GPIO_UART_RX_init();
}


//-----------------------------------------------------------------------------
int main(void)
{
  sys_init();
  timer_init();
  ...
  uart_init(115200);
  uart_puts("\r\nHello, world!\r\n");

PI PICO + debug probe (for PI PICO), recv data:

00 43 21 fffd 16 fffd fffd fffd 09 fffd 271 fffd fffd 35
29 fffd 

from usb-sniffer-lite.

ataradov avatar ataradov commented on July 17, 2024

Oh what hardware and with what device used as a receiver?

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

PI PICO + debug probe (for PI PICO), recv data:

00 43 21 fffd 16 fffd fffd fffd 09 fffd 271 fffd fffd 35
29 fffd 

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

image

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

@ataradov Does this code work for you?

from usb-sniffer-lite.

ataradov avatar ataradov commented on July 17, 2024

I can see junk being received by the Pico debug probe. It works fine with other adapters.

It also works fine after the initial Hello World string. If you type characters, it will echo them back correctly.

I assume this is some bug in the pico probe. It may not like initial level transitions when device is reset or something like this.

Try with a different USB to UART adapter.

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

oh, right!

sleeping a little.. and it works:

  uart_init(115200);
  for (uint32_t a = 0; a < 1000000; a++) {b++;};

  uart_puts("\r\nHello, world!\r\n");
  uart_puts("\r\nHello, world!\r\n");

from usb-sniffer-lite.

ataradov avatar ataradov commented on July 17, 2024

Yes, I was just going to suggest that. There is a chance that clock is not entirely stable at that point, but given that it works with a number of other adapters, but not with Pico Probe, I would assume this is some issue with the probe.
I don't have time to investigate that right now.

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

Thank you very much for the help. How can I implement a sleep function for X milliseconds in your baremetal environment?

from usb-sniffer-lite.

ataradov avatar ataradov commented on July 17, 2024

The same way as on any other MCU:

static void delay_ms(int ms)
{
  uint32_t cycles = ms * F_CPU / 3 / 1000;

  asm volatile (
    "1: sub %[cycles], %[cycles], #1 \n"
    "   bne 1b \n"
    : [cycles] "+r"(cycles)
  );
}

Normally you would want this to be located in the RAM through the section attribute, but in this case it already runs from the RAM.

from usb-sniffer-lite.

noobestguy avatar noobestguy commented on July 17, 2024

Great! Is there a way to generate the ELF file to debug it? I think there might be something wrong with the checksums or something. The U2F with your tool works great, but I'd like to use OpenOCD for debugging and a I need a valid ELF (the generated ELF with Makefile dont works)

from usb-sniffer-lite.

ataradov avatar ataradov commented on July 17, 2024

You can get the CRC value generated by the tool and place it in the linker script instead of a dummy value LONG(0xcccccccc).

The value would be different for different compilers, but you can get it by running

bin2uf2 -s -i UsbSnifferLite.bin -o UsbSnifferLite.bin 

It will show you the correct CRC. In my case it is 0x76b0d78e. So you would replace LONG(0xcccccccc) with LONG(0x76b0d78e).

from usb-sniffer-lite.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.