Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Heizung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3pb
Heizung
Commits
d4c46632
Commit
d4c46632
authored
1 year ago
by
Benjamin Koch
Browse files
Options
Downloads
Patches
Plain Diff
clean up
parent
ea2e5fee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firmware/rust1/src/rs485.rs
+14
-14
14 additions, 14 deletions
firmware/rust1/src/rs485.rs
firmware/rust1/src/uf2updater.rs
+4
-0
4 additions, 0 deletions
firmware/rust1/src/uf2updater.rs
with
18 additions
and
14 deletions
firmware/rust1/src/rs485.rs
+
14
−
14
View file @
d4c46632
use
defmt
::
*
;
use
defmt
::
*
;
use
embassy_futures
::
select
::
*
;
use
embassy_futures
::
select
::
*
;
use
embassy_futures
::
yield_now
;
use
embassy_rp
::
gpio
;
use
embassy_rp
::
gpio
;
use
embassy_rp
::
pac
;
use
embassy_rp
::
pac
;
use
embassy_rp
::
interrupt
::
UART0_IRQ
;
use
embassy_rp
::
interrupt
::
UART0_IRQ
;
...
@@ -482,24 +483,25 @@ impl<H: RS485Handler> RS485<H> {
...
@@ -482,24 +483,25 @@ impl<H: RS485Handler> RS485<H> {
*/
*/
},
},
Either4
::
Fourth
(
Either3
::
Third
(()))
=>
{
Either4
::
Fourth
(
Either3
::
Third
(()))
=>
{
let
x
=
unsafe
{
embassy_rp
::
pac
::
UART0
.uartfr
()
.read
()
.rxfe
()
};
// We were sometimes missing the last two chars so wait for the IRQ to copy them to the buffer.
let
x2
=
unsafe
{
embassy_rp
::
pac
::
UART0
.uartfr
()
.read
()
.0
};
let
mut
wait_for_rx_irq_cnt
=
0
;
let
mut
x5
=
0
;
while
!
unsafe
{
embassy_rp
::
pac
::
UART0
.uartfr
()
.read
()
.rxfe
()
}
&&
wait_for_rx_irq_cnt
<
500
{
while
!
unsafe
{
embassy_rp
::
pac
::
UART0
.uartfr
()
.read
()
.rxfe
()
}
{
// wait for IRQ to handle this
// wait for IRQ to handle this
x5
+=
1
;
wait_for_rx_irq_cnt
+=
1
;
if
false
{
Timer
::
after
(
Duration
::
from_micros
(
1
))
.await
;
}
else
{
yield_now
()
.await
;
}
}
}
let
rx_data
=
match
select
(
self
.rx
.read
(
&
mut
self
.rx_buffer
),
core
::
future
::
ready
(()))
.await
{
let
rx_data
=
match
select
(
self
.rx
.read
(
&
mut
self
.rx_buffer
),
core
::
future
::
ready
(()))
.await
{
Either
::
First
(
Ok
(
len
))
=>
{
Either
::
First
(
Ok
(
len
))
=>
{
// The UART uses a ringbuffer and it only pops data once so we need to ask a second
// The UART uses a ringbuffer and it only pops data once so we need to ask a second
// time if the frame wraps around the end of the ringbuffer and we want all data.
// time if the frame wraps around the end of the ringbuffer and we want all data.
//FIXME There is a race condition: If the ringbuffer was full, it will exactly fill our buffer.
// However, we could be receiving another character right now, which will probably cause a panic in read().
// -> Actually, pop() has a sane API so I think this cannot happen: The closure returns how
// much bytes have been processed and I think embassy-rp does that correctly.
match
select
(
self
.rx
.read
(
&
mut
self
.rx_buffer
[
len
..
]),
core
::
future
::
ready
(()))
.await
{
match
select
(
self
.rx
.read
(
&
mut
self
.rx_buffer
[
len
..
]),
core
::
future
::
ready
(()))
.await
{
Either
::
First
(
Ok
(
len2
))
=>
{
Either
::
First
(
Ok
(
len2
))
=>
{
info!
(
"DEBUG: We needed two calls to self.rx.read(): {} + {}"
,
len
,
len2
);
//
info!("DEBUG: We needed two calls to self.rx.read(): {} + {}", len, len2);
if
false
{
if
false
{
// ... and a third time's the charm because we may have received the last char right now.
// ... and a third time's the charm because we may have received the last char right now.
// -> Actually, it isn't. That's still not enough so we have the loop with rxfe above.
// -> Actually, it isn't. That's still not enough so we have the loop with rxfe above.
...
@@ -524,10 +526,8 @@ impl<H: RS485Handler> RS485<H> {
...
@@ -524,10 +526,8 @@ impl<H: RS485Handler> RS485<H> {
Ok
(
&
self
.rx_buffer
[
0
..
0
])
Ok
(
&
self
.rx_buffer
[
0
..
0
])
},
},
};
};
let
x3
=
unsafe
{
embassy_rp
::
pac
::
UART0
.uartfr
()
.read
()
.rxfe
()
};
if
wait_for_rx_irq_cnt
>
0
{
let
x4
=
unsafe
{
embassy_rp
::
pac
::
UART0
.uartfr
()
.read
()
.0
};
info!
(
"DEBUG: RX: {} bytes, waited for {} cycles"
,
rx_data
.map
(|
x
|
x
.len
()),
wait_for_rx_irq_cnt
);
if
!
x
||
!
x3
{
info!
(
"DEBUG: RX: {} bytes, {}, {}, {}, {}, x5={}"
,
rx_data
.map
(|
x
|
x
.len
()),
x
,
x2
,
x3
,
x4
,
x5
);
}
}
//let addr = unsafe { embassy_rp::pac::PIO0.sm(0).addr().read().addr() };
//let addr = unsafe { embassy_rp::pac::PIO0.sm(0).addr().read().addr() };
...
...
This diff is collapsed.
Click to expand it.
firmware/rust1/src/uf2updater.rs
+
4
−
0
View file @
d4c46632
...
@@ -90,6 +90,7 @@ impl<const FLASH_SIZE: usize> UF2UpdateHandler<FLASH_SIZE> {
...
@@ -90,6 +90,7 @@ impl<const FLASH_SIZE: usize> UF2UpdateHandler<FLASH_SIZE> {
}
}
pub
fn
write
(
self
:
&
mut
Self
,
pos
:
u32
,
data
:
&
[
u8
])
->
Result
<
(),
ModbusErrorCode
>
{
pub
fn
write
(
self
:
&
mut
Self
,
pos
:
u32
,
data
:
&
[
u8
])
->
Result
<
(),
ModbusErrorCode
>
{
//info!("UF2Updater::write: {}, len={}", pos, data.len());
if
data
.len
()
>
256
{
if
data
.len
()
>
256
{
// We could handle these cases but we are limited by Modbus frames anyway.
// We could handle these cases but we are limited by Modbus frames anyway.
info!
(
"Too much data in one call to UF2UpdateHandler::write()"
);
info!
(
"Too much data in one call to UF2UpdateHandler::write()"
);
...
@@ -144,6 +145,9 @@ impl<const FLASH_SIZE: usize> UF2UpdateHandler<FLASH_SIZE> {
...
@@ -144,6 +145,9 @@ impl<const FLASH_SIZE: usize> UF2UpdateHandler<FLASH_SIZE> {
let
uf2_block
=
&
self
.buf
.0
[
0
..
512
];
let
uf2_block
=
&
self
.buf
.0
[
0
..
512
];
//info!("process_sector: {}", uf2_block);
//info!("process_sector: len={}", uf2_block.len());
let
uf2_header
=
Uf2BlockHeader
::
read_from_prefix
(
uf2_block
)
.unwrap
();
let
uf2_header
=
Uf2BlockHeader
::
read_from_prefix
(
uf2_block
)
.unwrap
();
let
uf2_footer
=
Uf2BlockFooter
::
read_from_suffix
(
uf2_block
)
.unwrap
();
let
uf2_footer
=
Uf2BlockFooter
::
read_from_suffix
(
uf2_block
)
.unwrap
();
if
uf2_header
.magic_start0
!=
UF2_MAGIC_START0
||
uf2_header
.magic_start1
!=
UF2_MAGIC_START1
||
uf2_footer
.magic_end
!=
UF2_MAGIC_END
{
if
uf2_header
.magic_start0
!=
UF2_MAGIC_START0
||
uf2_header
.magic_start1
!=
UF2_MAGIC_START1
||
uf2_footer
.magic_end
!=
UF2_MAGIC_END
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment