Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello_timer wrong printf output #35

Closed
Turro75 opened this issue May 19, 2021 · 6 comments · Fixed by #37
Closed

hello_timer wrong printf output #35

Turro75 opened this issue May 19, 2021 · 6 comments · Fixed by #37
Labels
bug Something isn't working

Comments

@Turro75
Copy link
Contributor

Turro75 commented May 19, 2021

running hello_timer.hex from pico examples result in this output:

Unimplemented peripheral PADS_BANK0_BASE read from 4
Unimplemented peripheral PADS_BANK0_BASE write to 4: -129
Unimplemented peripheral IO_BANK0_BASE write to 4: 2
Unimplemented peripheral PADS_BANK0_BASE read from 8
Unimplemented peripheral PADS_BANK0_BASE read from 8
Unimplemented peripheral PADS_BANK0_BASE write to 8: -129
Unimplemented peripheral IO_BANK0_BASE write to c: 2
UART sent: H
UART sent: e
UART sent: l
UART sent: l
UART sent: o
UART sent:
UART sent: T
UART sent: i
UART sent: m
UART sent: e
UART sent: r
UART sent: !
UART sent:
UART sent:

SEV
UART sent: T
UART sent: i
UART sent: m
UART sent: e
UART sent: r
UART sent:
UART sent: V
UART sent:
UART sent: f
UART sent: i
UART sent: r
UART sent: e
UART sent: d
UART sent: !
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
SEV
UART sent: c
UART sent: a
UART sent: n
UART sent: c
UART sent: e
UART sent: l
UART sent: l
UART sent: e
UART sent: d
UART sent: .
UART sent: .
UART sent: .
UART sent:
UART sent: V
UART sent:
UART sent:

SEV
SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
UART sent: R
UART sent: e
UART sent: p
UART sent: e
UART sent: a
UART sent: t
UART sent:
UART sent: a
UART sent: t
UART sent:
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent: V
UART sent:
UART sent:

SEV
SEV
UART sent: c
UART sent: a
UART sent: n
UART sent: c
UART sent: e
UART sent: l
UART sent: l
UART sent: e
UART sent: d
UART sent: .
UART sent: .
UART sent: .
UART sent:
UART sent: V
UART sent:
UART sent:

SEV
SEV
UART sent: D
UART sent: o
UART sent: n
UART sent: e
UART sent:
UART sent:

while on a real pico it prints:

Hello Timer!                                              
Timer 1 fired!                                            
Repeat at 2501544                                         
Repeat at 3001630                                         
Repeat at 3501668
Repeat at 4001705
Repeat at 4501742
Timer 1 fired!
Repeat at 2503970
Repeat at 3004063                                                                   
Repeat at 3504105                                                                   
Repeat at 4004144                                                                   
Repeat at 4504182                                                                   
cancelled... 1                                                                      
Repeat at 7504054                                                                   
Repeat at 8004053                                                                   
Repeat at 8504053                                                                   
Repeat at 9004053                                                                   
Repeat at 9504053                                                                   
Repeat at 10004053                                                                  
cancelled... 1                                                                      
Done      

Investigating with gdbdiff it looks like at some point the silicone runs code from bootrom and the emulator gets mad.
As far as I've seen it seems it does not properly handle the 16bit instructions when the memory address is in the bootrom memory.

on the silicone set a breakpoint at 0x10000416 (line 45 of hello_timer.c) then after roughly 70ish si it goes to bootrom memory area.

I tried this test, it actually use LSLS instruction instead of BL because not able to read/write properly at bootrom addresses:

it('should execute `bl 0x23c2` instruction', async () => {
    await cpu.setPC(0x00000122);
    await cpu.writeUint32(0x00000122, opcodeBL(0x23c2));
    await cpu.singleStep();
    const registers = await cpu.readRegisters();
    expect(registers.pc).toEqual(0x000024e8);
    expect(registers.lr).toEqual(0x00000127);
  });

@urish
Copy link
Contributor

urish commented May 19, 2021

Hmm... so the emulator doesn't print the numbers correctly?

I suspect it may have to do with the integer divider that we still haven't implemented.

Can you check if there are any writes to SIO addresses at 0xd0000060 or 0xd0000068 ?

@Turro75
Copy link
Contributor Author

Turro75 commented May 19, 2021

out.txt

correct, a lot of missing sio warnings, I didn't see anything to 68 but 60 there are, a lot.
also seen that __wrap_vprintf goes to bootrom EDIT this set gdbdiff useless as bootromB1 code does not match the silicone code.

@urish
Copy link
Contributor

urish commented May 20, 2021

Thanks for attaching the logs!

These are SIO reads (and not writes) but I can see some reads come from the integer divider area:

Read from invalid SIO address: 60
Read from invalid SIO address: 64
Read from invalid SIO address: 74
Read from invalid SIO address: 70

70 is DIV_QUOTIENT,
74 is DIV_REMAINDER

I guess printf() is trying to divide the number by 10 each time to get one digit at a time, and it uses the integer divider for that. But we haven't implemented it yet, so it spits out garbage...

One workaround may be to disable the hardware divider. There's probably a way to tell them compiler not to use the hardware divider, I'll try to google that / look into the SDK sources

@urish
Copy link
Contributor

urish commented May 20, 2021

I think this is the code is the build system which enables the hardware divider:

https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_divider/CMakeLists.txt

So maybe adding

pico_set_divider_implementation(hello_timer compiler)

to the project's CMakeLists.txt will do the trick?

Turro75 added a commit to Turro75/rp2040js that referenced this issue May 20, 2021
Also adds an helper console log when a pin is set/reset

close wokwi#35
@Turro75
Copy link
Contributor Author

Turro75 commented May 20, 2021

As it seemed not so complicated (for sure i introduced bugs, no doubt on this) I implemented the hardware divider and , as usual, You were right: the printf output is now correct

@urish
Copy link
Contributor

urish commented May 20, 2021

You implemented the hardware divider? Cool! I'll check the pull request soon.

@urish urish added the bug Something isn't working label May 20, 2021
Turro75 added a commit to Turro75/rp2040js that referenced this issue May 20, 2021
@urish urish linked a pull request May 21, 2021 that will close this issue
@urish urish closed this as completed in #37 May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants