Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

MonoTimer does not work without debugger connected #76

Open
TheZoq2 opened this issue Apr 25, 2018 · 5 comments
Open

MonoTimer does not work without debugger connected #76

TheZoq2 opened this issue Apr 25, 2018 · 5 comments

Comments

@TheZoq2
Copy link
Contributor

TheZoq2 commented Apr 25, 2018

My current project reads a MonoTimer in order to keep track of signals which have been received. These signals are then sent over serial to a pc. This works flawlessly when the stlink debugger is connected, however without it connected the value read is always 0.

I assume this is because monotimer uses the "debug watch trace" peripheral which judging by the name means that it doesn't work without a debugger. Perhaps this should be specified in the documentation, or perhaps mono timer could be rewritten to use something that works without the debugger.

One thing to note is that the frequency reading still works.

@kellerkindt
Copy link
Contributor

Having the same issue, but only works if it just has been flashed by the debugger. Unplugging, and plugging it back to the debugger causes the MonoTimer to always read 0 ticks elapsed, until reflashed.

@kellerkindt
Copy link
Contributor

kellerkindt commented Sep 1, 2018

@TheZoq2 Got it running with the following workaround, which I call before MonoTimer::new:
unsafe { *(0xE000EDFC as *mut u32) |= 0x01000000; }
See example C Code here and here, especially this code section:

#define DEMCR_TRCENA    0x01000000

/* Core Debug registers */
#define DEMCR           (*((volatile uint32_t *)0xE000EDFC))
...
/* Enable DWT */
DEMCR |= DEMCR_TRCENA; 
*DWT_CYCCNT = 0;             
/* Enable CPU cycle counter */
DWT_CTRL |= CYCCNTENA;

There is no such equivalent of the /* Enable DWT */ DEMCR |= DEMCR_TRCENA; in the rust call in dwt.enable_cycle_counter(); in MonoTimer::new, it only results in /* Enable CPU cycle counter */ DWT_CTRL |= CYCCNTENA;

@TheZoq2
Copy link
Contributor Author

TheZoq2 commented Sep 2, 2018

Cool, I have since moved on to another solution without the MonoTimer but this might come in useful in the future.

A more rusty approach would be to use the demcr register here https://japaric.github.io/stm32f103xx-hal/cortex_m/peripheral/struct.DCB.html#structfield.demcr to avoid having a raw pointer. Might be worth making a pull request to fix it

@kellerkindt
Copy link
Contributor

kellerkindt commented Sep 2, 2018

A more rusty approach

Haha, definitely. I just needed some kind of a solution yesterday evening :)
Interesting that you found the demcr register, although I searched for it with the github search. Might have missed cortex_m crate though.
I am still a bit lost in the rust abstractions for the microcontrollers...

bors bot added a commit to rust-embedded/cortex-m that referenced this issue Sep 6, 2018
111: Add DCB::enable_trace() and DCB::disable_trace() r=korken89 a=kellerkindt

This is required for the cycle counter of DWT to work, if the power supply has been unplugged since the last time it has been flashed japaric/stm32f103xx-hal/issues/76.
See bit 24 here http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/CEGHJDCF.html

Corresponding PR in stm32f103xx-hal: japaric/stm32f103xx-hal/pull/94

Co-authored-by: kellerkindt <[email protected]>
Co-authored-by: Michael Watzko <[email protected]>
bors bot added a commit to rust-embedded/cortex-m that referenced this issue Sep 6, 2018
114: Release 0.5.7 r=japaric a=kellerkindt

As mentioned in /pull/111 (#111 (comment)), releasing 0.5.7 will allow the merge of japaric/stm32f103xx-hal/pull/94 which then allows japaric/stm32f103xx-hal/issues/76 to be resolved.

Co-authored-by: Michael Watzko <[email protected]>
Co-authored-by: Jorge Aparicio <[email protected]>
@tib888
Copy link

tib888 commented Sep 8, 2018

I just noticed that MonoTimer seems to be stopped, while I writing something to hstdout.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants