Skip to content

Commit 2c30256

Browse files
committed
stm: Clean up main.c; disable libgcc by default.
f2d and d2f functions from libgcc does not work correctly, most likely due to the ABI being incorrect. libgcc disabled for now.
1 parent d51cfd1 commit 2c30256

7 files changed

Lines changed: 25 additions & 224 deletions

File tree

stm/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ CFLAGS += -Os -DNDEBUG
3636
endif
3737

3838
LDFLAGS = --nostdlib -T stm32f405.ld
39-
LIBS = $(shell $(CC) -print-libgcc-file-name)
39+
LIBS =
40+
41+
# uncomment this if you want libgcc
42+
#LIBS += $(shell $(CC) -print-libgcc-file-name)
4043

4144
SRC_C = \
4245
main.c \
@@ -58,10 +61,10 @@ SRC_C = \
5861
timer.c \
5962
audio.c \
6063
sdio.c \
61-
pybwlan.c \
6264
i2c.c \
6365
usrsw.c \
6466
adc.c \
67+
# pybwlan.c \
6568
6669
SRC_S = \
6770
startup_stm32f40xx.s \
@@ -133,7 +136,7 @@ SRC_CC3K = \
133136
ccspi.c \
134137
pybcc3k.c \
135138

136-
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_FATFS:.c=.o) $(SRC_STM:.c=.o) $(SRC_CC3K:.c=.o))
139+
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_FATFS:.c=.o) $(SRC_STM:.c=.o)) # $(SRC_CC3K:.c=.o))
137140
#OBJ += $(addprefix $(BUILD)/, $(SRC_STM_OTG:.c=.o))
138141

139142
all2: $(BUILD) $(BUILD)/flash.dfu

stm/led.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ static const mp_obj_type_t led_obj_type = {
208208
.methods = led_methods,
209209
};
210210

211-
mp_obj_t pyb_Led(mp_obj_t led_id) {
211+
static mp_obj_t pyb_Led(mp_obj_t led_id) {
212212
pyb_led_obj_t *o = m_new_obj(pyb_led_obj_t);
213213
o->base.type = &led_obj_type;
214214
o->led_id = mp_obj_get_int(led_id);
215215
return o;
216216
}
217+
218+
MP_DEFINE_CONST_FUN_OBJ_1(pyb_Led_obj, pyb_Led);

stm/led.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
typedef enum {
2+
// PYBv3
23
PYB_LED_R1 = 1,
34
PYB_LED_R2 = 2,
45
PYB_LED_G1 = 3,
56
PYB_LED_G2 = 4,
7+
// PYBv4
8+
PYB_LED_RED = 1,
9+
PYB_LED_GREEN = 2,
10+
PYB_LED_YELLOW = 3,
11+
PYB_LED_BLUE = 4,
612
//STM32F4DISC
713
PYB_LED_R = 1,
814
PYB_LED_G = 2,
@@ -14,4 +20,4 @@ void led_init(void);
1420
void led_state(pyb_led_t led, int state);
1521
void led_toggle(pyb_led_t led);
1622

17-
mp_obj_t pyb_Led(mp_obj_t led_id);
23+
MP_DECLARE_CONST_FUN_OBJ(pyb_Led_obj);

stm/main.c

Lines changed: 6 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,6 @@ void flash_error(int n) {
6161
led_state(PYB_LED_R2, 0);
6262
}
6363

64-
static void impl02_c_version(void) {
65-
int x = 0;
66-
while (x < 400) {
67-
int y = 0;
68-
while (y < 400) {
69-
volatile int z = 0;
70-
while (z < 400) {
71-
z = z + 1;
72-
}
73-
y = y + 1;
74-
}
75-
x = x + 1;
76-
}
77-
}
78-
7964
void __fatal_error(const char *msg) {
8065
lcd_print_strn("\nFATAL ERROR:\n", 14);
8166
lcd_print_strn(msg, strlen(msg));
@@ -108,41 +93,6 @@ mp_obj_t pyb_delay(mp_obj_t count) {
10893
return mp_const_none;
10994
}
11095

111-
mp_obj_t pyb_led(mp_obj_t state) {
112-
led_state(PYB_LED_G1, rt_is_true(state));
113-
return state;
114-
}
115-
116-
/*
117-
void g(uint i) {
118-
printf("g:%d\n", i);
119-
if (i & 1) {
120-
nlr_jump((void*)(42 + i));
121-
}
122-
}
123-
void f(void) {
124-
nlr_buf_t nlr;
125-
int i;
126-
for (i = 0; i < 4; i++) {
127-
printf("f:loop:%d:%p\n", i, &nlr);
128-
if (nlr_push(&nlr) == 0) {
129-
// normal
130-
//printf("a:%p:%p %p %p %u\n", &nlr, nlr.ip, nlr.sp, nlr.prev, nlr.ret_val);
131-
g(i);
132-
printf("f:lp:%d:nrm\n", i);
133-
nlr_pop();
134-
} else {
135-
// nlr
136-
//printf("b:%p:%p %p %p %u\n", &nlr, nlr.ip, nlr.sp, nlr.prev, nlr.ret_val);
137-
printf("f:lp:%d:nlr:%d\n", i, (int)nlr.ret_val);
138-
}
139-
}
140-
}
141-
void nlr_test(void) {
142-
f(1);
143-
}
144-
*/
145-
14696
void fatality(void) {
14797
led_state(PYB_LED_R1, 1);
14898
led_state(PYB_LED_G1, 1);
@@ -180,6 +130,8 @@ static const char *help_text =
180130
" pyb.switch() -- return True/False if switch pressed or not\n"
181131
" pyb.accel() -- get accelerometer values\n"
182132
" pyb.rand() -- get a 16-bit random number\n"
133+
" pyb.gpio(<port>) -- get port value (port='a4' for example)\n"
134+
" pyb.gpio(<port>, <val>) -- set port value, True or False, 1 or 0\n"
183135
;
184136

185137
// get some help about available functions
@@ -587,7 +539,7 @@ mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
587539

588540
static void rtc_init(void) {
589541
uint32_t rtc_clksrc;
590-
uint32_t timeout =10000;
542+
uint32_t timeout = 1000000;
591543

592544
/* Enable the PWR clock */
593545
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
@@ -839,7 +791,6 @@ int main(void) {
839791
rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync));
840792
rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc));
841793
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
842-
rt_store_attr(m, MP_QSTR_led, rt_make_function_n(1, pyb_led));
843794
rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj);
844795
rt_store_attr(m, MP_QSTR_servo, rt_make_function_n(2, pyb_servo_set));
845796
rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set));
@@ -849,7 +800,7 @@ int main(void) {
849800
rt_store_attr(m, MP_QSTR_hid, rt_make_function_n(1, pyb_hid_send_report));
850801
rt_store_attr(m, MP_QSTR_time, rt_make_function_n(0, pyb_rtc_read));
851802
rt_store_attr(m, MP_QSTR_rand, rt_make_function_n(0, pyb_rng_get));
852-
rt_store_attr(m, MP_QSTR_Led, rt_make_function_n(1, pyb_Led));
803+
rt_store_attr(m, MP_QSTR_Led, (mp_obj_t)&pyb_Led_obj);
853804
rt_store_attr(m, MP_QSTR_Servo, rt_make_function_n(1, pyb_Servo));
854805
rt_store_attr(m, MP_QSTR_I2C, rt_make_function_n(2, pyb_I2C));
855806
rt_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj);
@@ -990,151 +941,6 @@ int main(void) {
990941
vstr_free(vstr);
991942
}
992943

993-
//printf("init;al=%u\n", m_get_total_bytes_allocated()); // 1600, due to qstr_init
994-
//sys_tick_delay_ms(1000);
995-
996-
// Python!
997-
if (0) {
998-
//const char *pysrc = "def f():\n x=x+1\nprint(42)\n";
999-
const char *pysrc =
1000-
// impl01.py
1001-
/*
1002-
"x = 0\n"
1003-
"while x < 400:\n"
1004-
" y = 0\n"
1005-
" while y < 400:\n"
1006-
" z = 0\n"
1007-
" while z < 400:\n"
1008-
" z = z + 1\n"
1009-
" y = y + 1\n"
1010-
" x = x + 1\n";
1011-
*/
1012-
// impl02.py
1013-
/*
1014-
"#@micropython.native\n"
1015-
"def f():\n"
1016-
" x = 0\n"
1017-
" while x < 400:\n"
1018-
" y = 0\n"
1019-
" while y < 400:\n"
1020-
" z = 0\n"
1021-
" while z < 400:\n"
1022-
" z = z + 1\n"
1023-
" y = y + 1\n"
1024-
" x = x + 1\n"
1025-
"f()\n";
1026-
*/
1027-
/*
1028-
"print('in python!')\n"
1029-
"x = 0\n"
1030-
"while x < 4:\n"
1031-
" pyb_led(True)\n"
1032-
" pyb_delay(201)\n"
1033-
" pyb_led(False)\n"
1034-
" pyb_delay(201)\n"
1035-
" x += 1\n"
1036-
"print('press me!')\n"
1037-
"while True:\n"
1038-
" pyb_led(pyb_sw())\n";
1039-
*/
1040-
/*
1041-
// impl16.py
1042-
"@micropython.asm_thumb\n"
1043-
"def delay(r0):\n"
1044-
" b(loop_entry)\n"
1045-
" label(loop1)\n"
1046-
" movw(r1, 55999)\n"
1047-
" label(loop2)\n"
1048-
" subs(r1, r1, 1)\n"
1049-
" cmp(r1, 0)\n"
1050-
" bgt(loop2)\n"
1051-
" subs(r0, r0, 1)\n"
1052-
" label(loop_entry)\n"
1053-
" cmp(r0, 0)\n"
1054-
" bgt(loop1)\n"
1055-
"print('in python!')\n"
1056-
"@micropython.native\n"
1057-
"def flash(n):\n"
1058-
" x = 0\n"
1059-
" while x < n:\n"
1060-
" pyb_led(True)\n"
1061-
" delay(249)\n"
1062-
" pyb_led(False)\n"
1063-
" delay(249)\n"
1064-
" x = x + 1\n"
1065-
"flash(20)\n";
1066-
*/
1067-
// impl18.py
1068-
/*
1069-
"# basic exceptions\n"
1070-
"x = 1\n"
1071-
"try:\n"
1072-
" x.a()\n"
1073-
"except:\n"
1074-
" print(x)\n";
1075-
*/
1076-
// impl19.py
1077-
"# for loop\n"
1078-
"def f():\n"
1079-
" for x in range(400):\n"
1080-
" for y in range(400):\n"
1081-
" for z in range(400):\n"
1082-
" pass\n"
1083-
"f()\n";
1084-
1085-
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", pysrc, strlen(pysrc), 0);
1086-
1087-
// nalloc=1740;6340;6836 -> 140;4600;496 bytes for lexer, parser, compiler
1088-
printf("lex; al=%u\n", m_get_total_bytes_allocated());
1089-
sys_tick_delay_ms(1000);
1090-
qstr parse_exc_id;
1091-
const char *parse_exc_msg;
1092-
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT, &parse_exc_id, &parse_exc_msg);
1093-
mp_lexer_free(lex);
1094-
if (pn != MP_PARSE_NODE_NULL) {
1095-
printf("pars;al=%u\n", m_get_total_bytes_allocated());
1096-
sys_tick_delay_ms(1000);
1097-
//parse_node_show(pn, 0);
1098-
mp_obj_t module_fun = mp_compile(pn, 0, false);
1099-
printf("comp;al=%u\n", m_get_total_bytes_allocated());
1100-
sys_tick_delay_ms(1000);
1101-
1102-
if (module_fun == mp_const_none) {
1103-
printf("compile error\n");
1104-
} else {
1105-
// execute it!
1106-
1107-
// flash once
1108-
led_state(PYB_LED_G1, 1);
1109-
sys_tick_delay_ms(100);
1110-
led_state(PYB_LED_G1, 0);
1111-
1112-
nlr_buf_t nlr;
1113-
if (nlr_push(&nlr) == 0) {
1114-
mp_obj_t ret = rt_call_function_0(module_fun);
1115-
printf("done! got: ");
1116-
mp_obj_print(ret, PRINT_REPR);
1117-
printf("\n");
1118-
nlr_pop();
1119-
} else {
1120-
// uncaught exception
1121-
printf("exception: ");
1122-
mp_obj_print((mp_obj_t)nlr.ret_val, PRINT_REPR);
1123-
printf("\n");
1124-
}
1125-
1126-
// flash once
1127-
led_state(PYB_LED_G1, 1);
1128-
sys_tick_delay_ms(100);
1129-
led_state(PYB_LED_G1, 0);
1130-
1131-
sys_tick_delay_ms(1000);
1132-
printf("nalloc=%u\n", m_get_total_bytes_allocated());
1133-
sys_tick_delay_ms(1000);
1134-
}
1135-
}
1136-
}
1137-
1138944
// HID example
1139945
if (0) {
1140946
uint8_t data[4];
@@ -1170,23 +976,6 @@ int main(void) {
1170976

1171977
do_repl();
1172978

1173-
// benchmark C version of impl02.py
1174-
if (0) {
1175-
led_state(PYB_LED_G1, 1);
1176-
sys_tick_delay_ms(100);
1177-
led_state(PYB_LED_G1, 0);
1178-
impl02_c_version();
1179-
led_state(PYB_LED_G1, 1);
1180-
sys_tick_delay_ms(100);
1181-
led_state(PYB_LED_G1, 0);
1182-
}
1183-
1184-
// SD card testing
1185-
if (0) {
1186-
extern void sdio_init(void);
1187-
sdio_init();
1188-
}
1189-
1190979
printf("PYB: sync filesystems\n");
1191980
pyb_sync();
1192981

@@ -1196,7 +985,8 @@ int main(void) {
1196985
goto soft_reset;
1197986
}
1198987

1199-
/* now supplied by libgcc library
988+
// these 2 functions seem to actually work... no idea why
989+
// replacing with libgcc does not work (probably due to wrong calling conventions)
1200990
double __aeabi_f2d(float x) {
1201991
// TODO
1202992
return 0.0;
@@ -1206,7 +996,6 @@ float __aeabi_d2f(double x) {
1206996
// TODO
1207997
return 0.0;
1208998
}
1209-
*/
1210999

12111000
double sqrt(double x) {
12121001
// TODO

stm/qstrdefsport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Q(main)
1111
Q(sync)
1212
Q(gc)
1313
Q(delay)
14-
Q(led)
1514
Q(switch)
1615
Q(servo)
1716
Q(pwm)

stm/std.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void *memcpy(void *dest, const void *src, size_t n);
1111
void *memmove(void *dest, const void *src, size_t n);
1212
void *memset(void *s, int c, size_t n);
1313

14-
//int strlen(const char *str);
14+
size_t strlen(const char *str);
1515
int strcmp(const char *s1, const char *s2);
1616
int strncmp(const char *s1, const char *s2, size_t n);
1717
char *strndup(const char *s, size_t n);

stm/stm32fxxx_it.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ void EXTI15_10_IRQHandler(void) {
286286
// work out if it's A14 that had the interrupt
287287
if (EXTI_GetITStatus(EXTI_Line14) != RESET) {
288288
led_toggle(PYB_LED_G2);
289+
/* these are needed for CC3000 support
289290
extern void SpiIntGPIOHandler(void);
290291
extern uint32_t exti14_enabled;
291292
extern uint32_t exti14_missed;
@@ -296,6 +297,7 @@ void EXTI15_10_IRQHandler(void) {
296297
} else {
297298
exti14_missed = 1;
298299
}
300+
*/
299301
EXTI_ClearITPendingBit(EXTI_Line14);
300302
//printf("<- EXTI14 done\n");
301303
}

0 commit comments

Comments
 (0)