Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
7d7f59d7
Commit
7d7f59d7
authored
6 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stm32/uart: Factor out code to set RX buffer to function uart_set_rxbuf.
parent
9690757c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ports/stm32/machine_uart.c
+4
-11
4 additions, 11 deletions
ports/stm32/machine_uart.c
ports/stm32/uart.c
+15
-0
15 additions, 0 deletions
ports/stm32/uart.c
ports/stm32/uart.h
+1
-0
1 addition, 0 deletions
ports/stm32/uart.h
with
20 additions
and
11 deletions
ports/stm32/machine_uart.c
+
4
−
11
View file @
7d7f59d7
...
...
@@ -223,25 +223,18 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
}
self
->
char_width
=
CHAR_WIDTH_8BIT
;
}
self
->
read_buf_head
=
0
;
self
->
read_buf_tail
=
0
;
if
(
args
.
rxbuf
.
u_int
>=
0
)
{
// rxbuf overrides legacy read_buf_len
args
.
read_buf_len
.
u_int
=
args
.
rxbuf
.
u_int
;
}
if
(
args
.
read_buf_len
.
u_int
<=
0
)
{
// no read buffer
self
->
read_buf_len
=
0
;
self
->
read_buf
=
NULL
;
HAL_NVIC_DisableIRQ
(
self
->
irqn
);
__HAL_UART_DISABLE_IT
(
&
self
->
uart
,
UART_IT_RXNE
);
uart_set_rxbuf
(
self
,
0
,
NULL
);
}
else
{
// read buffer using interrupts
self
->
read_buf_len
=
args
.
read_buf_len
.
u_int
+
1
;
// +1 to adjust for usable length of buffer
self
->
read_buf
=
m_new
(
byte
,
self
->
read_buf_len
<<
self
->
char_width
);
__HAL_UART_ENABLE_IT
(
&
self
->
uart
,
UART_IT_RXNE
);
NVIC_SetPriority
(
IRQn_NONNEG
(
self
->
irqn
),
IRQ_PRI_UART
);
HAL_NVIC_EnableIRQ
(
self
->
irqn
);
size_t
len
=
args
.
read_buf_len
.
u_int
+
1
;
// +1 to adjust for usable length of buffer
uint8_t
*
buf
=
m_new
(
byte
,
len
<<
self
->
char_width
);
uart_set_rxbuf
(
self
,
len
,
buf
);
}
// compute actual baudrate that was configured
...
...
This diff is collapsed.
Click to expand it.
ports/stm32/uart.c
+
15
−
0
View file @
7d7f59d7
...
...
@@ -302,6 +302,21 @@ bool uart_init2(pyb_uart_obj_t *uart_obj) {
return
true
;
}
void
uart_set_rxbuf
(
pyb_uart_obj_t
*
self
,
size_t
len
,
void
*
buf
)
{
self
->
read_buf_head
=
0
;
self
->
read_buf_tail
=
0
;
self
->
read_buf_len
=
len
;
self
->
read_buf
=
buf
;
if
(
len
==
0
)
{
HAL_NVIC_DisableIRQ
(
self
->
irqn
);
__HAL_UART_DISABLE_IT
(
&
self
->
uart
,
UART_IT_RXNE
);
}
else
{
__HAL_UART_ENABLE_IT
(
&
self
->
uart
,
UART_IT_RXNE
);
NVIC_SetPriority
(
IRQn_NONNEG
(
self
->
irqn
),
IRQ_PRI_UART
);
HAL_NVIC_EnableIRQ
(
self
->
irqn
);
}
}
void
uart_deinit
(
pyb_uart_obj_t
*
self
)
{
self
->
is_enabled
=
false
;
UART_HandleTypeDef
*
uart
=
&
self
->
uart
;
...
...
This diff is collapsed.
Click to expand it.
ports/stm32/uart.h
+
1
−
0
View file @
7d7f59d7
...
...
@@ -64,6 +64,7 @@ void uart_init0(void);
void
uart_deinit_all
(
void
);
bool
uart_exists
(
int
uart_id
);
bool
uart_init2
(
pyb_uart_obj_t
*
uart_obj
);
void
uart_set_rxbuf
(
pyb_uart_obj_t
*
self
,
size_t
len
,
void
*
buf
);
void
uart_deinit
(
pyb_uart_obj_t
*
uart_obj
);
void
uart_irq_handler
(
mp_uint_t
uart_id
);
...
...
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