Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
e9f1e50b
Commit
e9f1e50b
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Board running boot.py, working REPL, soft reboot.
parent
ec63cce4
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
stm/Makefile
+1
-0
1 addition, 0 deletions
stm/Makefile
stm/lcd.c
+5
-0
5 additions, 0 deletions
stm/lcd.c
stm/lcd.h
+1
-0
1 addition, 0 deletions
stm/lcd.h
stm/main.c
+79
-82
79 additions, 82 deletions
stm/main.c
stm/usb.c
+4
-1
4 additions, 1 deletion
stm/usb.c
with
90 additions
and
83 deletions
stm/Makefile
+
1
−
0
View file @
e9f1e50b
...
@@ -50,6 +50,7 @@ PY_O = \
...
@@ -50,6 +50,7 @@ PY_O = \
emitinlinethumb.o
\
emitinlinethumb.o
\
runtime.o
\
runtime.o
\
vm.o
\
vm.o
\
repl.o
\
SRC_FATFS
=
\
SRC_FATFS
=
\
ff.c
\
ff.c
\
...
...
This diff is collapsed.
Click to expand it.
stm/lcd.c
+
5
−
0
View file @
e9f1e50b
#include
<string.h>
#include
<stm32f4xx_gpio.h>
#include
<stm32f4xx_gpio.h>
#include
"misc.h"
#include
"misc.h"
...
@@ -138,6 +139,10 @@ void lcd_init() {
...
@@ -138,6 +139,10 @@ void lcd_init() {
lcd_next_line
=
0
;
lcd_next_line
=
0
;
}
}
void
lcd_print_str
(
const
char
*
str
)
{
lcd_print_strn
(
str
,
strlen
(
str
));
}
void
lcd_print_strn
(
const
char
*
str
,
unsigned
int
len
)
{
void
lcd_print_strn
(
const
char
*
str
,
unsigned
int
len
)
{
int
redraw_min
=
lcd_line
*
LCD_BUF_W
+
lcd_column
;
int
redraw_min
=
lcd_line
*
LCD_BUF_W
+
lcd_column
;
int
redraw_max
=
redraw_min
;
int
redraw_max
=
redraw_min
;
...
...
This diff is collapsed.
Click to expand it.
stm/lcd.h
+
1
−
0
View file @
e9f1e50b
void
lcd_init
();
void
lcd_init
();
void
lcd_print_str
(
const
char
*
str
);
void
lcd_print_strn
(
const
char
*
str
,
unsigned
int
len
);
void
lcd_print_strn
(
const
char
*
str
,
unsigned
int
len
);
This diff is collapsed.
Click to expand it.
stm/main.c
+
79
−
82
View file @
e9f1e50b
...
@@ -77,6 +77,15 @@ void __fatal_error(const char *msg) {
...
@@ -77,6 +77,15 @@ void __fatal_error(const char *msg) {
#include
"parse.h"
#include
"parse.h"
#include
"compile.h"
#include
"compile.h"
#include
"runtime.h"
#include
"runtime.h"
#include
"repl.h"
py_obj_t
pyb_source_dir
(
py_obj_t
source_dir
)
{
return
py_const_none
;
}
py_obj_t
pyb_main
(
py_obj_t
main
)
{
return
py_const_none
;
}
py_obj_t
pyb_delay
(
py_obj_t
count
)
{
py_obj_t
pyb_delay
(
py_obj_t
count
)
{
sys_tick_delay_ms
(
rt_get_int
(
count
));
sys_tick_delay_ms
(
rt_get_int
(
count
));
...
@@ -98,7 +107,6 @@ py_obj_t pyb_sw() {
...
@@ -98,7 +107,6 @@ py_obj_t pyb_sw() {
FATFS
fatfs0
;
FATFS
fatfs0
;
/*
/*
void g(uint i) {
void g(uint i) {
printf("g:%d\n", i);
printf("g:%d\n", i);
...
@@ -149,7 +157,7 @@ static const char fresh_boot_py[] =
...
@@ -149,7 +157,7 @@ static const char fresh_boot_py[] =
;
;
// get lots of info about the board
// get lots of info about the board
static
void
board
_info
()
{
static
py_obj_t
pyb
_info
()
{
// get and print clock speeds
// get and print clock speeds
// SYSCLK=168MHz, HCLK=168MHz, PCLK1=42MHz, PCLK2=84MHz
// SYSCLK=168MHz, HCLK=168MHz, PCLK1=42MHz, PCLK2=84MHz
{
{
...
@@ -184,75 +192,79 @@ static void board_info() {
...
@@ -184,75 +192,79 @@ static void board_info() {
f_getfree
(
"0:"
,
&
nclst
,
&
fatfs
);
f_getfree
(
"0:"
,
&
nclst
,
&
fatfs
);
printf
(
"free=%u
\n
"
,
(
uint
)(
nclst
*
fatfs
->
csize
*
512
));
printf
(
"free=%u
\n
"
,
(
uint
)(
nclst
*
fatfs
->
csize
*
512
));
}
}
return
py_const_none
;
}
}
char
*
readline
(
const
char
*
prompt
)
{
/*
vstr_t
vstr
;
void gc_print_info() {
vstr_init
(
&
vstr
);
gc_info_t info;
gc_info(&info);
printf("! %lu total\n", info.total);
printf("! %lu : %lu\n", info.used, info.free);
printf("! 1=%lu 2=%lu m=%lu\n", info.num_1block, info.num_2block, info.max_block);
}
*/
int
readline
(
vstr_t
*
line
,
const
char
*
prompt
)
{
usb_vcp_send_str
(
prompt
);
usb_vcp_send_str
(
prompt
);
int
len
=
vstr_len
(
line
);
for
(;;)
{
for
(;;)
{
//extern int rx_buf_in;
//extern int rx_buf_out;
while
(
usb_vcp_rx_any
()
==
0
)
{
while
(
usb_vcp_rx_any
()
==
0
)
{
//printf("nope %x %x\n", rx_buf_in, rx_buf_out);
sys_tick_delay_ms
(
10
);
sys_tick_delay_ms
(
10
);
}
}
char
c
=
usb_vcp_rx_get
();
char
c
=
usb_vcp_rx_get
();
if
(
c
==
4
&&
vstr_len
(
&
vstr
)
==
0
)
{
if
(
c
==
4
&&
vstr_len
(
line
)
==
len
)
{
return
NULL
;
return
0
;
}
else
if
(
c
==
'\r'
)
{
}
else
if
(
c
==
'\r'
)
{
usb_vcp_send_str
(
"
\r\n
"
);
usb_vcp_send_str
(
"
\r\n
"
);
return
vstr_str
(
&
vstr
)
;
return
1
;
}
else
if
(
c
==
127
)
{
}
else
if
(
c
==
127
)
{
if
(
vstr_len
(
&
vstr
)
>
0
)
{
if
(
vstr_len
(
line
)
>
len
)
{
vstr_cut_tail
(
&
vstr
,
1
);
vstr_cut_tail
(
line
,
1
);
usb_vcp_send_str
(
"
\b
\b
"
);
usb_vcp_send_str
(
"
\b
\b
"
);
}
}
}
else
if
(
32
<=
c
&&
c
<=
126
)
{
}
else
if
(
32
<=
c
&&
c
<=
126
)
{
vstr_add_char
(
&
vstr
,
c
);
vstr_add_char
(
line
,
c
);
usb_vcp_send_strn
(
&
c
,
1
);
usb_vcp_send_strn
(
&
c
,
1
);
}
}
sys_tick_delay_ms
(
100
);
sys_tick_delay_ms
(
100
);
}
}
return
NULL
;
}
}
/*
void gc_print_info() {
gc_info_t info;
gc_info(&info);
printf("! %lu total\n", info.total);
printf("! %lu : %lu\n", info.used, info.free);
printf("! 1=%lu 2=%lu m=%lu\n", info.num_1block, info.num_2block, info.max_block);
}
*/
void
do_repl
()
{
void
do_repl
()
{
usb_vcp_send_str
(
"Micro Python
\r\n
"
);
usb_vcp_send_str
(
"Micro Python 0.5; STM32F405RG; PYBv2
\r\n
"
);
usb_vcp_send_str
(
"Type
\"
help
\"
for more information.
\r\n
"
);
vstr_t
line
;
vstr_init
(
&
line
);
for
(;;)
{
for
(;;)
{
char
*
line
=
readline
(
">>> "
);
vstr_reset
(
&
line
);
if
(
line
==
NULL
)
{
int
ret
=
readline
(
&
line
,
">>> "
);
if
(
ret
==
0
)
{
// EOF
// EOF
re
turn
;
b
re
ak
;
}
}
/*
if (is_compound_stmt(line)) {
if
(
vstr_len
(
&
line
)
==
0
)
{
continue
;
}
if
(
py_repl_is_compound_stmt
(
vstr_str
(
&
line
)))
{
for
(;;)
{
for
(;;)
{
char *line2 = readline("... ");
vstr_add_char
(
&
line
,
'\n'
);
if (line2 == NULL || strlen(line2) == 0) {
int
len
=
vstr_len
(
&
line
);
int
ret
=
readline
(
&
line
,
"... "
);
if
(
ret
==
0
||
vstr_len
(
&
line
)
==
len
)
{
// done entering compound statement
break
;
break
;
}
}
char *line3 = str_join(line, '\n', line2);
m_free(line);
m_free(line2);
line = line3;
}
}
}
}
*/
py_lexer_str_buf_t
sb
;
py_lexer_str_buf_t
sb
;
py_lexer_t
*
lex
=
py_lexer_new_from_str_len
(
"<stdin>"
,
line
,
strlen
(
line
),
false
,
&
sb
);
py_lexer_t
*
lex
=
py_lexer_new_from_str_len
(
"<stdin>"
,
vstr_str
(
&
line
)
,
v
str
_
len
(
&
line
),
false
,
&
sb
);
py_parse_node_t
pn
=
py_parse
(
lex
,
PY_PARSE_SINGLE_INPUT
);
py_parse_node_t
pn
=
py_parse
(
lex
,
PY_PARSE_SINGLE_INPUT
);
py_lexer_free
(
lex
);
py_lexer_free
(
lex
);
...
@@ -274,6 +286,8 @@ void do_repl() {
...
@@ -274,6 +286,8 @@ void do_repl() {
}
}
}
}
}
}
usb_vcp_send_str
(
"
\r\n
Micro Python REPL finished
\r\n
"
);
}
}
#define RAM_START (0x20000000) // fixed for chip
#define RAM_START (0x20000000) // fixed for chip
...
@@ -299,7 +313,7 @@ void gc_collect() {
...
@@ -299,7 +313,7 @@ void gc_collect() {
printf
(
" 1=%lu 2=%lu m=%lu
\n
"
,
info
.
num_1block
,
info
.
num_2block
,
info
.
max_block
);
printf
(
" 1=%lu 2=%lu m=%lu
\n
"
,
info
.
num_1block
,
info
.
num_2block
,
info
.
max_block
);
}
}
py_obj_t
py_gc
_collect
()
{
py_obj_t
py
b
_gc
()
{
gc_collect
();
gc_collect
();
return
py_const_none
;
return
py_const_none
;
}
}
...
@@ -322,24 +336,35 @@ int main() {
...
@@ -322,24 +336,35 @@ int main() {
// more sub-system init
// more sub-system init
sw_init
();
sw_init
();
lcd_init
();
storage_init
();
storage_init
();
soft_reset:
// LCD init
lcd_init
();
// GC init
// GC init
gc_init
(
&
_heap_start
,
(
void
*
)
HEAP_END
);
gc_init
(
&
_heap_start
,
(
void
*
)
HEAP_END
);
// Python init
//
Micro
Python init
qstr_init
();
qstr_init
();
rt_init
();
rt_init
();
// add some functions to the python namespace
// add some functions to the python namespace
rt_store_name
(
qstr_from_str_static
(
"gc"
),
rt_make_function_0
(
py_gc_collect
));
{
rt_store_name
(
qstr_from_str_static
(
"pyb_delay"
),
rt_make_function_1
(
pyb_delay
));
py_obj_t
m
=
py_module_new
();
rt_store_name
(
qstr_from_str_static
(
"pyb_led"
),
rt_make_function_1
(
pyb_led
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"info"
),
rt_make_function_0
(
pyb_info
));
rt_store_name
(
qstr_from_str_static
(
"pyb_sw"
),
rt_make_function_0
(
pyb_sw
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"source_dir"
),
rt_make_function_1
(
pyb_source_dir
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"main"
),
rt_make_function_1
(
pyb_main
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"gc"
),
rt_make_function_0
(
pyb_gc
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"delay"
),
rt_make_function_1
(
pyb_delay
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"led"
),
rt_make_function_1
(
pyb_led
));
rt_store_attr
(
m
,
qstr_from_str_static
(
"sw"
),
rt_make_function_0
(
pyb_sw
));
rt_store_name
(
qstr_from_str_static
(
"pyb"
),
m
);
}
// print a message
// print a message
to the LCD
print
f
(
" micro py board
\n
"
);
lcd_
print
_str
(
" micro py board
\n
"
);
// local filesystem init
// local filesystem init
{
{
...
@@ -391,7 +416,7 @@ int main() {
...
@@ -391,7 +416,7 @@ int main() {
FIL
fp
;
FIL
fp
;
f_open
(
&
fp
,
"0:/boot.py"
,
FA_WRITE
|
FA_CREATE_ALWAYS
);
f_open
(
&
fp
,
"0:/boot.py"
,
FA_WRITE
|
FA_CREATE_ALWAYS
);
UINT
n
;
UINT
n
;
f_write
(
&
fp
,
fresh_boot_py
,
sizeof
(
fresh_boot_py
),
&
n
);
f_write
(
&
fp
,
fresh_boot_py
,
sizeof
(
fresh_boot_py
)
-
1
/* don't count null terminator */
,
&
n
);
// TODO check we could write n bytes
// TODO check we could write n bytes
f_close
(
&
fp
);
f_close
(
&
fp
);
...
@@ -401,8 +426,11 @@ int main() {
...
@@ -401,8 +426,11 @@ int main() {
}
}
}
}
// USB
usb_init
();
// run /boot.py
// run /boot.py
if
(
0
)
{
if
(
1
)
{
py_lexer_file_buf_t
fb
;
py_lexer_file_buf_t
fb
;
py_lexer_t
*
lex
=
py_lexer_new_from_file
(
"0:/boot.py"
,
&
fb
);
py_lexer_t
*
lex
=
py_lexer_new_from_file
(
"0:/boot.py"
,
&
fb
);
py_parse_node_t
pn
=
py_parse
(
lex
,
PY_PARSE_FILE_INPUT
);
py_parse_node_t
pn
=
py_parse
(
lex
,
PY_PARSE_FILE_INPUT
);
...
@@ -430,11 +458,6 @@ int main() {
...
@@ -430,11 +458,6 @@ int main() {
// turn boot-up LED off
// turn boot-up LED off
led_state
(
PYB_LED_G1
,
0
);
led_state
(
PYB_LED_G1
,
0
);
// USB
if
(
1
)
{
usb_init
();
}
//printf("init;al=%u\n", m_get_total_bytes_allocated()); // 1600, due to qstr_init
//printf("init;al=%u\n", m_get_total_bytes_allocated()); // 1600, due to qstr_init
//sys_tick_delay_ms(1000);
//sys_tick_delay_ms(1000);
...
@@ -653,31 +676,5 @@ int main() {
...
@@ -653,31 +676,5 @@ int main() {
//sdio_init();
//sdio_init();
}
}
int
i
=
0
;
goto
soft_reset
;
int
n
=
0
;
uint32_t
stc
=
sys_tick_counter
;
for
(;;)
{
sys_tick_delay_ms
(
10
);
if
(
sw_get
())
{
led_state
(
PYB_LED_G1
,
1
);
i
=
1
-
i
;
if
(
i
)
{
printf
(
" angel %05x.
\n
"
,
n
);
//usb_vcp_send("hello!\r\n", 8);
}
else
{
printf
(
" mishka %4u.
\n
"
,
n
);
//usb_vcp_send("angel!\r\n", 8);
}
n
+=
1
;
}
else
{
led_state
(
PYB_LED_G1
,
0
);
}
if
(
sys_tick_has_passed
(
stc
,
500
))
{
stc
+=
500
;
led_toggle
(
PYB_LED_G2
);
}
}
return
0
;
}
}
This diff is collapsed.
Click to expand it.
stm/usb.c
+
4
−
1
View file @
e9f1e50b
...
@@ -20,7 +20,10 @@ static int rx_buf_in;
...
@@ -20,7 +20,10 @@ static int rx_buf_in;
static
int
rx_buf_out
;
static
int
rx_buf_out
;
void
usb_init
()
{
void
usb_init
()
{
if
(
!
is_enabled
)
{
// only init USB once in the device's power-lifetime
USBD_Init
(
&
USB_OTG_dev
,
USB_OTG_FS_CORE_ID
,
&
USR_desc
,
&
USBD_PYB_cb
,
&
USR_cb
);
USBD_Init
(
&
USB_OTG_dev
,
USB_OTG_FS_CORE_ID
,
&
USR_desc
,
&
USBD_PYB_cb
,
&
USR_cb
);
}
rx_buf_in
=
0
;
rx_buf_in
=
0
;
rx_buf_out
=
0
;
rx_buf_out
=
0
;
is_enabled
=
1
;
is_enabled
=
1
;
...
...
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