mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 10:45:11 +03:00
add floating print to STM32F303
This commit is contained in:
parent
867abe359a
commit
8f9e80afa9
@ -127,15 +127,131 @@ Loopback control of three stepper motors
|
|||||||
|
|
||||||
# Control points
|
# Control points
|
||||||
|
|
||||||
- **TP1** — 5V
|
- **TP1** 5V
|
||||||
- **TP2** — 3.3V
|
- **TP2** 3.3V
|
||||||
- **TP3** — NRST
|
- **TP3** NRST
|
||||||
- **TP4** — GND
|
- **TP4** GND
|
||||||
|
|
||||||
# Firmware download
|
# Firmware download
|
||||||
|
|
||||||
Activate "Jump to DFU" menu entry through USB protocol. Flash MCU by `dfu-util`.
|
Activate "Jump to DFU" menu entry through USB protocol. Flash MCU by `dfu-util`.
|
||||||
|
|
||||||
# USB protocol
|
# USB protocol
|
||||||
|
https://github.com/eddyem/stm32samples/tree/master/F0-nolib/3steppersLB build#138 @ 2021-12-02
|
||||||
|
Common commands format is cmd[ N[ = val]]
|
||||||
|
where N is command argument (0..127), val is its value
|
||||||
|
Different commands:
|
||||||
|
adc - get ADC values
|
||||||
|
button - get buttons state
|
||||||
|
buzzer - change buzzer state (1/0)
|
||||||
|
esw - get end switches state
|
||||||
|
ext - external outputs
|
||||||
|
mcut - get MCU T
|
||||||
|
mcuvdd - get MCU Vdd
|
||||||
|
ping - echo given command back
|
||||||
|
pwm - pwm value
|
||||||
|
relay - change relay state (1/0)
|
||||||
|
reset - reset MCU
|
||||||
|
time - get time from start
|
||||||
|
Confuguration:
|
||||||
|
accel - set/get accel/decel (steps/s^2)
|
||||||
|
encrev - set/get max encoder's pulses per revolution
|
||||||
|
encstepmax - maximal encoder ticks per step
|
||||||
|
encstepmin - minimal encoder ticks per step
|
||||||
|
eswreact - end-switches reaction
|
||||||
|
maxspeed - set/get max speed (steps per sec)
|
||||||
|
maxsteps - set/get max steps (from zero)
|
||||||
|
microsteps - set/get microsteps settings
|
||||||
|
minspeed - set/get min speed (steps per sec)
|
||||||
|
motflags - set/get motorN flags
|
||||||
|
saveconf - save current configuration
|
||||||
|
speedlimit - get limiting speed for current microsteps
|
||||||
|
Motors' commands:
|
||||||
|
abspos - set/get position (in steps)
|
||||||
|
emerg - emergency stop all motors
|
||||||
|
emstop - emergency stop motor (right now)
|
||||||
|
encpos - set/get encoder's position
|
||||||
|
gotoz - find zero position & refresh counters
|
||||||
|
motreinit - re-init motors after configuration changed
|
||||||
|
relpos - set relative steps, get remaining
|
||||||
|
relslow - set relative steps @ lowest speed
|
||||||
|
state - get motor state
|
||||||
|
stop - smooth motor stopping
|
||||||
|
USB-only commands:
|
||||||
|
canid - get/set CAN ID
|
||||||
|
canspeed - CAN bus speed
|
||||||
|
delignlist - delete ignore list
|
||||||
|
dfu - activate DFU mode
|
||||||
|
dumperr - dump error codes
|
||||||
|
dumpcmd - dump command codes
|
||||||
|
dumpconf - dump current configuration
|
||||||
|
filter - add/modify filter, format: bank# FIFO# mode(M/I) num0 [num1 [num2 [num3]]]
|
||||||
|
getctr - get TIM1/2/3 counters
|
||||||
|
ignbuf - print ignore buffer
|
||||||
|
ignore - add ID to ignore list (max 10 IDs)
|
||||||
|
listfilters - list all active filters
|
||||||
|
pause - pause IN packets displaying
|
||||||
|
resume - resume IN packets displaying
|
||||||
|
send - send data over CAN: send ID byte0 .. byteN
|
||||||
|
wd - check watchdog
|
||||||
|
|
||||||
# CAN bus protocol
|
# CAN bus protocol
|
||||||
|
|
||||||
|
bytes descr
|
||||||
|
0 Lcmd - command code
|
||||||
|
1 Hcmd
|
||||||
|
2 par - command paremeter (steper, ADC channel number etc)
|
||||||
|
3 err - error code (only in answer)
|
||||||
|
4 Ldata - optional data in int32_t
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7 Hdata
|
||||||
|
|
||||||
|
dumperr
|
||||||
|
Find known command: dumperr
|
||||||
|
Error codes:
|
||||||
|
0 - all OK
|
||||||
|
1 - wrong parameter's value
|
||||||
|
2 - wrong setter of parameter
|
||||||
|
3 - bad message length
|
||||||
|
4 - unknown command
|
||||||
|
5 - temporary can't run given command
|
||||||
|
|
||||||
|
|
||||||
|
dumpcmd
|
||||||
|
Find known command: dumpcmd
|
||||||
|
Commands list:
|
||||||
|
0 - Different commands:
|
||||||
|
1 - change relay state (1/0)
|
||||||
|
2 - change buzzer state (1/0)
|
||||||
|
3 - get ADC values
|
||||||
|
4 - get buttons state
|
||||||
|
5 - get end switches state
|
||||||
|
6 - get MCU T
|
||||||
|
7 - get MCU Vdd
|
||||||
|
8 - reset MCU
|
||||||
|
9 - get time from start
|
||||||
|
10 - pwm value
|
||||||
|
11 - external outputs
|
||||||
|
12 - save current configuration
|
||||||
|
13 - minimal encoder ticks per step
|
||||||
|
14 - maximal encoder ticks per step
|
||||||
|
15 - set/get microsteps settings
|
||||||
|
16 - set/get accel/decel (steps/s^2)
|
||||||
|
17 - set/get max speed (steps per sec)
|
||||||
|
18 - set/get min speed (steps per sec)
|
||||||
|
19 - get limiting speed for current microsteps
|
||||||
|
20 - set/get max steps (from zero)
|
||||||
|
21 - set/get max encoder's pulses per revolution
|
||||||
|
22 - set/get motorN flags
|
||||||
|
23 - end-switches reaction
|
||||||
|
24 - re-init motors after configuration changed
|
||||||
|
25 - set/get position (in steps)
|
||||||
|
26 - set relative steps, get remaining
|
||||||
|
27 - set relative steps @ lowest speed
|
||||||
|
28 - emergency stop motor (right now)
|
||||||
|
29 - smooth motor stopping
|
||||||
|
30 - emergency stop all motors
|
||||||
|
31 - find zero position & refresh counters
|
||||||
|
32 - get motor state
|
||||||
|
33 - set/get encoder's position
|
||||||
|
|||||||
0
F0-nolib/3steppersLB/steppers.bin
Executable file → Normal file
0
F0-nolib/3steppersLB/steppers.bin
Executable file → Normal file
0
F0-nolib/CANbus_stepper/src/canstepper.bin
Normal file → Executable file
0
F0-nolib/CANbus_stepper/src/canstepper.bin
Normal file → Executable file
0
F0-nolib/Chiller/chiller.bin
Normal file → Executable file
0
F0-nolib/Chiller/chiller.bin
Normal file → Executable file
0
F0-nolib/F0_testbrd/pl2303.bin
Normal file → Executable file
0
F0-nolib/F0_testbrd/pl2303.bin
Normal file → Executable file
0
F0-nolib/QuadEncoder/encoder.bin
Normal file → Executable file
0
F0-nolib/QuadEncoder/encoder.bin
Normal file → Executable file
0
F0-nolib/Servo/servo.bin
Normal file → Executable file
0
F0-nolib/Servo/servo.bin
Normal file → Executable file
0
F0-nolib/Socket_fans/sockfans.bin
Normal file → Executable file
0
F0-nolib/Socket_fans/sockfans.bin
Normal file → Executable file
0
F0-nolib/TM1637/tm1637.bin
Normal file → Executable file
0
F0-nolib/TM1637/tm1637.bin
Normal file → Executable file
0
F0-nolib/USBHID/usbhid.bin
Normal file → Executable file
0
F0-nolib/USBHID/usbhid.bin
Normal file → Executable file
0
F0-nolib/USB_pl2303_snippet/usb.bin
Normal file → Executable file
0
F0-nolib/USB_pl2303_snippet/usb.bin
Normal file → Executable file
0
F0-nolib/blink/blink.bin
Executable file → Normal file
0
F0-nolib/blink/blink.bin
Executable file → Normal file
0
F0-nolib/canbus/src/canbus.bin
Normal file → Executable file
0
F0-nolib/canbus/src/canbus.bin
Normal file → Executable file
0
F0-nolib/htu21d_nucleo/usart.bin
Normal file → Executable file
0
F0-nolib/htu21d_nucleo/usart.bin
Normal file → Executable file
@ -1 +1 @@
|
|||||||
Fx
|
/home/eddy/Yandex.Disk/Projects/stm32samples/F0-nolib/inc/Fx
|
||||||
0
F0-nolib/morze/morze.bin
Normal file → Executable file
0
F0-nolib/morze/morze.bin
Normal file → Executable file
0
F0-nolib/pl2303/pl2303.bin
Normal file → Executable file
0
F0-nolib/pl2303/pl2303.bin
Normal file → Executable file
0
F0-nolib/tsys01_nucleo/tsys01.bin
Normal file → Executable file
0
F0-nolib/tsys01_nucleo/tsys01.bin
Normal file → Executable file
0
F0-nolib/uart_blink/uartblink.bin
Normal file → Executable file
0
F0-nolib/uart_blink/uartblink.bin
Normal file → Executable file
0
F0-nolib/uart_blink_dma/uartblink.bin
Normal file → Executable file
0
F0-nolib/uart_blink_dma/uartblink.bin
Normal file → Executable file
0
F0-nolib/uart_nucleo/usart.bin
Normal file → Executable file
0
F0-nolib/uart_nucleo/usart.bin
Normal file → Executable file
0
F0-nolib/usbcan/usbcan.bin
Executable file → Normal file
0
F0-nolib/usbcan/usbcan.bin
Executable file → Normal file
0
F0-nolib/usbcan_relay/usbcan.bin
Executable file → Normal file
0
F0-nolib/usbcan_relay/usbcan.bin
Executable file → Normal file
0
F0/blink/blink.bin
Normal file → Executable file
0
F0/blink/blink.bin
Normal file → Executable file
0
F0/uart/uart.bin
Normal file → Executable file
0
F0/uart/uart.bin
Normal file → Executable file
0
F1-nolib/BMP180/BMP180.bin
Normal file → Executable file
0
F1-nolib/BMP180/BMP180.bin
Normal file → Executable file
0
F1-nolib/BMP280/BMP280.bin
Normal file → Executable file
0
F1-nolib/BMP280/BMP280.bin
Normal file → Executable file
0
F1-nolib/CDC_ACM/cdcacm.bin
Normal file → Executable file
0
F1-nolib/CDC_ACM/cdcacm.bin
Normal file → Executable file
0
F1-nolib/DHT22_DHT11/DHT22.bin
Normal file → Executable file
0
F1-nolib/DHT22_DHT11/DHT22.bin
Normal file → Executable file
0
F1-nolib/DS18/DS18.bin
Normal file → Executable file
0
F1-nolib/DS18/DS18.bin
Normal file → Executable file
0
F1-nolib/F1_testbrd/pl2303.bin
Normal file → Executable file
0
F1-nolib/F1_testbrd/pl2303.bin
Normal file → Executable file
0
F1-nolib/I2Cscan/I2Cscan.bin
Normal file → Executable file
0
F1-nolib/I2Cscan/I2Cscan.bin
Normal file → Executable file
0
F1-nolib/LED_Screen/LEDscreen.bin
Normal file → Executable file
0
F1-nolib/LED_Screen/LEDscreen.bin
Normal file → Executable file
0
F1-nolib/LED_Screen/genlist
Normal file → Executable file
0
F1-nolib/LED_Screen/genlist
Normal file → Executable file
0
F1-nolib/LED_Screen/scrtest/scrtest
Normal file → Executable file
0
F1-nolib/LED_Screen/scrtest/scrtest
Normal file → Executable file
0
F1-nolib/MAX7219_screen/MAX7219.bin
Normal file → Executable file
0
F1-nolib/MAX7219_screen/MAX7219.bin
Normal file → Executable file
0
F1-nolib/PL2303/pl2303.bin
Normal file → Executable file
0
F1-nolib/PL2303/pl2303.bin
Normal file → Executable file
0
F1-nolib/RGB_LED_Screen/RGBLEDscreen.bin
Normal file → Executable file
0
F1-nolib/RGB_LED_Screen/RGBLEDscreen.bin
Normal file → Executable file
0
F1-nolib/RGB_LED_Screen/getrand
Normal file → Executable file
0
F1-nolib/RGB_LED_Screen/getrand
Normal file → Executable file
@ -1 +0,0 @@
|
|||||||
/home/eddy/Yandex.Disk/Projects/mytakepic/.hg/wcache/checklink-target
|
|
||||||
301
F1-nolib/RGB_LED_Screen/proto.c
Normal file
301
F1-nolib/RGB_LED_Screen/proto.c
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the RGBLEDscreen project.
|
||||||
|
* Copyright 2020 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adcrandom.h"
|
||||||
|
#include "balls.h"
|
||||||
|
#include "fonts.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "usb.h"
|
||||||
|
|
||||||
|
extern uint8_t countms, rainbow, balls;
|
||||||
|
extern uint32_t Tms;
|
||||||
|
|
||||||
|
char *omit_spaces(const char *buf){
|
||||||
|
while(*buf){
|
||||||
|
if(*buf > ' ') break;
|
||||||
|
++buf;
|
||||||
|
}
|
||||||
|
return (char*)buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case of overflow return `buf` and N==0xffffffff
|
||||||
|
// read decimal number & return pointer to next non-number symbol
|
||||||
|
static char *getdec(const char *buf, uint32_t *N){
|
||||||
|
char *start = (char*)buf;
|
||||||
|
uint32_t num = 0;
|
||||||
|
while(*buf){
|
||||||
|
char c = *buf;
|
||||||
|
if(c < '0' || c > '9'){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(num > 429496729 || (num == 429496729 && c > '5')){ // overflow
|
||||||
|
*N = 0xffffff;
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
num *= 10;
|
||||||
|
num += c - '0';
|
||||||
|
++buf;
|
||||||
|
}
|
||||||
|
*N = num;
|
||||||
|
return (char*)buf;
|
||||||
|
}
|
||||||
|
// read hexadecimal number (without 0x prefix!)
|
||||||
|
static char *gethex(const char *buf, uint32_t *N){
|
||||||
|
char *start = (char*)buf;
|
||||||
|
uint32_t num = 0;
|
||||||
|
while(*buf){
|
||||||
|
char c = *buf;
|
||||||
|
uint8_t M = 0;
|
||||||
|
if(c >= '0' && c <= '9'){
|
||||||
|
M = '0';
|
||||||
|
}else if(c >= 'A' && c <= 'F'){
|
||||||
|
M = 'A' - 10;
|
||||||
|
}else if(c >= 'a' && c <= 'f'){
|
||||||
|
M = 'a' - 10;
|
||||||
|
}
|
||||||
|
if(M){
|
||||||
|
if(num & 0xf0000000){ // overflow
|
||||||
|
*N = 0xffffff;
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
num <<= 4;
|
||||||
|
num += c - M;
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++buf;
|
||||||
|
}
|
||||||
|
*N = num;
|
||||||
|
return (char*)buf;
|
||||||
|
}
|
||||||
|
// read octal number (without 0 prefix!)
|
||||||
|
static char *getoct(const char *buf, uint32_t *N){
|
||||||
|
char *start = (char*)buf;
|
||||||
|
uint32_t num = 0;
|
||||||
|
while(*buf){
|
||||||
|
char c = *buf;
|
||||||
|
if(c < '0' || c > '7'){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(num & 0xe0000000){ // overflow
|
||||||
|
*N = 0xffffff;
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
num <<= 3;
|
||||||
|
num += c - '0';
|
||||||
|
++buf;
|
||||||
|
}
|
||||||
|
*N = num;
|
||||||
|
return (char*)buf;
|
||||||
|
}
|
||||||
|
// read binary number (without b prefix!)
|
||||||
|
static char *getbin(const char *buf, uint32_t *N){
|
||||||
|
char *start = (char*)buf;
|
||||||
|
uint32_t num = 0;
|
||||||
|
while(*buf){
|
||||||
|
char c = *buf;
|
||||||
|
if(c < '0' || c > '1'){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(num & 0x80000000){ // overflow
|
||||||
|
*N = 0xffffff;
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
num <<= 1;
|
||||||
|
if(c == '1') num |= 1;
|
||||||
|
++buf;
|
||||||
|
}
|
||||||
|
*N = num;
|
||||||
|
return (char*)buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief getnum - read uint32_t from string (dec, hex or bin: 127, 0x7f, 0b1111111)
|
||||||
|
* @param buf - buffer with number and so on
|
||||||
|
* @param N - the number read
|
||||||
|
* @return pointer to first non-number symbol in buf
|
||||||
|
* (if it is == buf, there's no number or if *N==0xffffffff there was overflow)
|
||||||
|
*/
|
||||||
|
char *getnum(const char *txt, uint32_t *N){
|
||||||
|
char *nxt = NULL;
|
||||||
|
char *s = omit_spaces(txt);
|
||||||
|
if(*s == '0'){ // hex, oct or 0
|
||||||
|
if(s[1] == 'x' || s[1] == 'X'){ // hex
|
||||||
|
nxt = gethex(s+2, N);
|
||||||
|
if(nxt == s+2) nxt = (char*)txt;
|
||||||
|
}else if(s[1] > '0'-1 && s[1] < '8'){ // oct
|
||||||
|
nxt = getoct(s+1, N);
|
||||||
|
if(nxt == s+1) nxt = (char*)txt;
|
||||||
|
}else{ // 0
|
||||||
|
nxt = s+1;
|
||||||
|
*N = 0;
|
||||||
|
}
|
||||||
|
}else if(*s == 'b' || *s == 'B'){
|
||||||
|
nxt = getbin(s+1, N);
|
||||||
|
if(nxt == s+1) nxt = (char*)txt;
|
||||||
|
}else{
|
||||||
|
nxt = getdec(s, N);
|
||||||
|
if(nxt == s) nxt = (char*)txt;
|
||||||
|
}
|
||||||
|
return nxt;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* helpmsg =
|
||||||
|
"'0/1' - screen off/on\n"
|
||||||
|
"'2,3' - select font\n"
|
||||||
|
"'A' - get ADC values\n"
|
||||||
|
"'B' - start/stop rainBow\n"
|
||||||
|
"'b' - start/stop Balls\n"
|
||||||
|
"'C' - clear screen with given color\n"
|
||||||
|
"'F' - set foreground color\n"
|
||||||
|
"'G' - get 100 random numbers\n"
|
||||||
|
"'f' - get FPS\n"
|
||||||
|
"'R' - software reset\n"
|
||||||
|
"'W' - test watchdog\n"
|
||||||
|
"'Zz' -start/stop counting ms\n"
|
||||||
|
"Any text - put text @ screen\n"
|
||||||
|
;
|
||||||
|
|
||||||
|
const char *parse_cmd(const char *buf){
|
||||||
|
uint32_t N;
|
||||||
|
if(buf[1] == '\n'){ // one symbol commands
|
||||||
|
switch(*buf){
|
||||||
|
case '0':
|
||||||
|
ScreenOFF();
|
||||||
|
return "OFF\n";
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
ScreenON();
|
||||||
|
return "ON\n";
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
if(choose_font(FONT14)) return "Font14\n";
|
||||||
|
return "err\n";
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
if(choose_font(FONT16)) return "Font16\n";
|
||||||
|
return "err\n";
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
USB_send("Tsens="); USB_send(u2str(getADCval(0)));
|
||||||
|
USB_send("\nVref="); USB_send(u2str(getADCval(1)));
|
||||||
|
USB_send("\nRand="); USB_send(u2str(getRand()));
|
||||||
|
USB_send("\n");
|
||||||
|
return NULL;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
if(rainbow){
|
||||||
|
rainbow = 0;
|
||||||
|
return "Stop rainbow\n";
|
||||||
|
}else{
|
||||||
|
rainbow = 1;
|
||||||
|
return "Start rainbow\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
if(balls){
|
||||||
|
balls = 0;
|
||||||
|
return "Stop balls\n";
|
||||||
|
}else{
|
||||||
|
balls_init();
|
||||||
|
balls = 1;
|
||||||
|
return "Start balls\n";
|
||||||
|
}
|
||||||
|
case 'f':
|
||||||
|
if(SCREEN_RELAX == getScreenState()) return "Screen is inactive\n";
|
||||||
|
USB_send("FPS=");
|
||||||
|
USB_send(u2str(getFPS()));
|
||||||
|
USB_send("\n");
|
||||||
|
return NULL;
|
||||||
|
break;
|
||||||
|
case 'G':
|
||||||
|
/*USB_send(u2str(Tms)); USB_send("\n");
|
||||||
|
for(int i=0; i < 1000; ++i) getRand();
|
||||||
|
USB_send(u2str(Tms)); USB_send("\n");*/
|
||||||
|
for(int i = 0; i < 100; ++i){
|
||||||
|
USB_send(u2str(getRand()));
|
||||||
|
USB_send("\n");
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
USB_send("Soft reset\n");
|
||||||
|
NVIC_SystemReset();
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
USB_send("Wait for reboot\n");
|
||||||
|
while(1){nop();};
|
||||||
|
break;
|
||||||
|
case 'Z':
|
||||||
|
countms = 1;
|
||||||
|
return "Start\n";
|
||||||
|
break;
|
||||||
|
case 'z':
|
||||||
|
countms = 0;
|
||||||
|
return "Stop\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return helpmsg;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}else{
|
||||||
|
switch(*buf){
|
||||||
|
case 'C':
|
||||||
|
if(getnum(buf+1, &N)){
|
||||||
|
ScreenOFF();
|
||||||
|
setBGcolor(N);
|
||||||
|
ClearScreen();
|
||||||
|
ScreenON();
|
||||||
|
return "Background color\n";
|
||||||
|
}
|
||||||
|
return "Wrong color\n";
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
if(getnum(buf+1, &N)){
|
||||||
|
setFGcolor(N);
|
||||||
|
return "Foreground color\n";
|
||||||
|
}
|
||||||
|
return "Wrong color\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ScreenOFF();
|
||||||
|
ClearScreen();
|
||||||
|
PutStringAt(1, curfont->height + 3, buf);
|
||||||
|
ScreenON();
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return string with number `val`
|
||||||
|
char *u2str(uint32_t val){
|
||||||
|
static char strbuf[11];
|
||||||
|
char *bufptr = &strbuf[10];
|
||||||
|
*bufptr = 0;
|
||||||
|
if(!val){
|
||||||
|
*(--bufptr) = '0';
|
||||||
|
}else{
|
||||||
|
while(val){
|
||||||
|
*(--bufptr) = val % 10 + '0';
|
||||||
|
val /= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bufptr;
|
||||||
|
}
|
||||||
0
F1-nolib/SI7005_HTU21D/si7005.bin
Normal file → Executable file
0
F1-nolib/SI7005_HTU21D/si7005.bin
Normal file → Executable file
0
F1-nolib/SPI/SPI.bin
Normal file → Executable file
0
F1-nolib/SPI/SPI.bin
Normal file → Executable file
0
F1-nolib/SevenCDCs/cdcacmcore.bin
Normal file → Executable file
0
F1-nolib/SevenCDCs/cdcacmcore.bin
Normal file → Executable file
0
F1-nolib/Tetris/TETRIS.bin
Normal file → Executable file
0
F1-nolib/Tetris/TETRIS.bin
Normal file → Executable file
0
F1-nolib/Tetris/getrand
Normal file → Executable file
0
F1-nolib/Tetris/getrand
Normal file → Executable file
@ -1 +0,0 @@
|
|||||||
/home/eddy/Yandex.Disk/Projects/mytakepic/.hg/wcache/checklink-target
|
|
||||||
193
F1-nolib/Tetris/main.c
Normal file
193
F1-nolib/Tetris/main.c
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the TETRIS project.
|
||||||
|
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adcrandom.h"
|
||||||
|
#include "arkanoid.h"
|
||||||
|
#include "balls.h"
|
||||||
|
#include "buttons.h"
|
||||||
|
#include "fonts.h"
|
||||||
|
#include "hardware.h"
|
||||||
|
#include "menu.h"
|
||||||
|
#include "proto.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "snake.h"
|
||||||
|
#include "tetris.h"
|
||||||
|
#include "usb.h"
|
||||||
|
#include "usb_lib.h"
|
||||||
|
|
||||||
|
// timeout for autosleep (30s)
|
||||||
|
#define AUTOSLEEP_TMOUT (30000)
|
||||||
|
|
||||||
|
volatile uint32_t Tms = 0;
|
||||||
|
uint8_t balls = 0;
|
||||||
|
|
||||||
|
enum{
|
||||||
|
STATE_MENU,
|
||||||
|
STATE_SNAKE,
|
||||||
|
STATE_TETRIS,
|
||||||
|
STATE_ARKANOID,
|
||||||
|
STATE_SLEEP,
|
||||||
|
STATE_GAMEOVER
|
||||||
|
} curstate = STATE_SLEEP;
|
||||||
|
|
||||||
|
/* Called when systick fires */
|
||||||
|
void sys_tick_handler(void){
|
||||||
|
++Tms;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define USBBUFSZ (127)
|
||||||
|
// usb getline
|
||||||
|
static char *get_USB(){
|
||||||
|
static char tmpbuf[USBBUFSZ+1], *curptr = tmpbuf;
|
||||||
|
static int rest = USBBUFSZ;
|
||||||
|
int x = USB_receive(curptr);
|
||||||
|
curptr[x] = 0;
|
||||||
|
if(!x) return NULL;
|
||||||
|
if(curptr[x-1] == '\n'){
|
||||||
|
curptr = tmpbuf;
|
||||||
|
rest = USBBUFSZ;
|
||||||
|
return tmpbuf;
|
||||||
|
}
|
||||||
|
curptr += x; rest -= x;
|
||||||
|
if(rest <= 0){ // buffer overflow
|
||||||
|
curptr = tmpbuf;
|
||||||
|
rest = USBBUFSZ;
|
||||||
|
USB_send("USB buffer overflow\n");
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void process_menu(){
|
||||||
|
switch(menu_activated()){
|
||||||
|
case MENU_SLEEP:
|
||||||
|
USB_send("Select 'Sleep'\n");
|
||||||
|
ScreenOFF();
|
||||||
|
curstate = STATE_SLEEP;
|
||||||
|
break;
|
||||||
|
case MENU_BALLS:
|
||||||
|
USB_send("Select 'Balls'\n");
|
||||||
|
if(balls){
|
||||||
|
balls = 0;
|
||||||
|
}else{
|
||||||
|
curstate = STATE_SLEEP;
|
||||||
|
balls_init();
|
||||||
|
balls = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MENU_SNAKE:
|
||||||
|
USB_send("Select 'Snake'\n");
|
||||||
|
snake_init();
|
||||||
|
curstate = STATE_SNAKE;
|
||||||
|
break;
|
||||||
|
case MENU_TETRIS:
|
||||||
|
USB_send("Select 'Tetris'\n");
|
||||||
|
tetris_init();
|
||||||
|
curstate = STATE_TETRIS;
|
||||||
|
break;
|
||||||
|
case MENU_ARKANOID:
|
||||||
|
USB_send("Select 'Arkanoid'\n");
|
||||||
|
arkanoid_init();
|
||||||
|
curstate = STATE_ARKANOID;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gotomenu(){
|
||||||
|
curstate = STATE_MENU;
|
||||||
|
clear_events();
|
||||||
|
show_menu();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
uint32_t lastT = 0;
|
||||||
|
sysreset();
|
||||||
|
StartHSE();
|
||||||
|
SysTick_Config(72000);
|
||||||
|
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
||||||
|
|
||||||
|
hw_setup();
|
||||||
|
USBPU_OFF();
|
||||||
|
adc_setup();
|
||||||
|
USB_setup();
|
||||||
|
//iwdg_setup();
|
||||||
|
USBPU_ON();
|
||||||
|
|
||||||
|
keyevent evt;
|
||||||
|
while(1){
|
||||||
|
if(Tms - lastT > 499){
|
||||||
|
LED_blink(LED0);
|
||||||
|
lastT = Tms;
|
||||||
|
}
|
||||||
|
IWDG->KR = IWDG_REFRESH;
|
||||||
|
if(balls) process_balls();
|
||||||
|
process_keys();
|
||||||
|
switch(curstate){
|
||||||
|
case STATE_SLEEP:
|
||||||
|
if(keystate(KEY_M, &evt) && evt == EVT_RELEASE){
|
||||||
|
USB_send("Activate menu\n");
|
||||||
|
gotomenu();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATE_MENU:
|
||||||
|
process_menu();
|
||||||
|
if(Tms - lastUnsleep > AUTOSLEEP_TMOUT){
|
||||||
|
USB_send("Autosleep\n");
|
||||||
|
ScreenOFF();
|
||||||
|
curstate = STATE_SLEEP;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATE_SNAKE:
|
||||||
|
if(!snake_proces()){
|
||||||
|
show_gameover();
|
||||||
|
curstate = STATE_GAMEOVER;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATE_TETRIS:
|
||||||
|
if(!tetris_process()){
|
||||||
|
show_gameover();
|
||||||
|
curstate = STATE_GAMEOVER;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATE_ARKANOID:
|
||||||
|
if(!arkanoid_process()){
|
||||||
|
show_gameover();
|
||||||
|
curstate = STATE_GAMEOVER;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATE_GAMEOVER: // show gameover screen
|
||||||
|
if(keystate(KEY_M, &evt) && evt == EVT_RELEASE){
|
||||||
|
gotomenu();
|
||||||
|
}else if(Tms - lastUnsleep > AUTOSLEEP_TMOUT){
|
||||||
|
USB_send("Autosleep\n");
|
||||||
|
ScreenOFF();
|
||||||
|
curstate = STATE_SLEEP;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_proc();
|
||||||
|
char *txt; const char *ans;
|
||||||
|
if((txt = get_USB())){
|
||||||
|
ans = parse_cmd(txt);
|
||||||
|
if(ans) USB_send(ans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
0
F1-nolib/USB_HID/usbhid103.bin
Normal file → Executable file
0
F1-nolib/USB_HID/usbhid103.bin
Normal file → Executable file
0
F1-nolib/chronometer/chrono.bin
Executable file → Normal file
0
F1-nolib/chronometer/chrono.bin
Executable file → Normal file
0
F1-nolib/chronometer_v2/chrono.bin
Normal file → Executable file
0
F1-nolib/chronometer_v2/chrono.bin
Normal file → Executable file
0
F1-nolib/chronometer_v3/chrono.bin
Normal file → Executable file
0
F1-nolib/chronometer_v3/chrono.bin
Normal file → Executable file
0
F1-nolib/led_blink/blink.bin
Normal file → Executable file
0
F1-nolib/led_blink/blink.bin
Normal file → Executable file
0
F1-nolib/pl2303_snippet/pl2303.bin
Normal file → Executable file
0
F1-nolib/pl2303_snippet/pl2303.bin
Normal file → Executable file
0
F1-nolib/pl2303_snippet_naked/pl2303.bin
Normal file → Executable file
0
F1-nolib/pl2303_snippet_naked/pl2303.bin
Normal file → Executable file
0
F1-nolib/pwmdmatest/pwmtest.bin
Normal file → Executable file
0
F1-nolib/pwmdmatest/pwmtest.bin
Normal file → Executable file
0
F1-nolib/pwmtest/pwmtest.bin
Normal file → Executable file
0
F1-nolib/pwmtest/pwmtest.bin
Normal file → Executable file
0
F1-nolib/uart/uart.bin
Normal file → Executable file
0
F1-nolib/uart/uart.bin
Normal file → Executable file
0
F1-nolib/ws2815/ws2815.bin
Normal file → Executable file
0
F1-nolib/ws2815/ws2815.bin
Normal file → Executable file
0
F1/1_wire/onewire.bin
Normal file → Executable file
0
F1/1_wire/onewire.bin
Normal file → Executable file
0
F1/2.8TFT/dma_gpio.bin
Normal file → Executable file
0
F1/2.8TFT/dma_gpio.bin
Normal file → Executable file
0
F1/DMA_GPIO/dma_gpio.bin
Normal file → Executable file
0
F1/DMA_GPIO/dma_gpio.bin
Normal file → Executable file
0
F1/GPIO_TIM/tim_gpio.bin
Normal file → Executable file
0
F1/GPIO_TIM/tim_gpio.bin
Normal file → Executable file
0
F1/GPS+ultrasonic/timelapse.bin
Normal file → Executable file
0
F1/GPS+ultrasonic/timelapse.bin
Normal file → Executable file
0
F1/GPS/GPS.bin
Normal file → Executable file
0
F1/GPS/GPS.bin
Normal file → Executable file
0
F1/Jeep_generator/jeep_generator.bin
Normal file → Executable file
0
F1/Jeep_generator/jeep_generator.bin
Normal file → Executable file
0
F1/Timelapse_keyboard/timelapse.bin
Normal file → Executable file
0
F1/Timelapse_keyboard/timelapse.bin
Normal file → Executable file
0
F1/Timelapse_keyboard_only_lasers/timelapse.bin
Normal file → Executable file
0
F1/Timelapse_keyboard_only_lasers/timelapse.bin
Normal file → Executable file
0
F1/USBCDC_template/usb_cdc_simple.bin
Normal file → Executable file
0
F1/USBCDC_template/usb_cdc_simple.bin
Normal file → Executable file
0
F1/canon_lens/canon_lens.bin
Normal file → Executable file
0
F1/canon_lens/canon_lens.bin
Normal file → Executable file
0
F1/distance_meters/ultrasonic.bin
Normal file → Executable file
0
F1/distance_meters/ultrasonic.bin
Normal file → Executable file
0
F1/hid_mouse_keyboard/usbhid.bin
Normal file → Executable file
0
F1/hid_mouse_keyboard/usbhid.bin
Normal file → Executable file
0
F1/keyboard_snippet/keyboard.bin
Normal file → Executable file
0
F1/keyboard_snippet/keyboard.bin
Normal file → Executable file
0
F1/matrix_keyboard/matrkeyb.bin
Normal file → Executable file
0
F1/matrix_keyboard/matrkeyb.bin
Normal file → Executable file
0
F1/nokia5110/nokia5110.bin
Normal file → Executable file
0
F1/nokia5110/nokia5110.bin
Normal file → Executable file
0
F1/simple_cdc/usb_cdc_simple.bin
Normal file → Executable file
0
F1/simple_cdc/usb_cdc_simple.bin
Normal file → Executable file
0
F1/stepper_motion/usb_cdc_simple.bin
Normal file → Executable file
0
F1/stepper_motion/usb_cdc_simple.bin
Normal file → Executable file
0
F1/ultrasonic/ultrasonic.bin
Normal file → Executable file
0
F1/ultrasonic/ultrasonic.bin
Normal file → Executable file
0
F303-nolib/blink/blink.bin
Normal file → Executable file
0
F303-nolib/blink/blink.bin
Normal file → Executable file
146
F303-nolib/floatPrintf/Makefile
Normal file
146
F303-nolib/floatPrintf/Makefile
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
BINARY = usart1
|
||||||
|
BOOTPORT ?= /dev/ttyUSB0
|
||||||
|
BOOTSPEED ?= 115200
|
||||||
|
# MCU FAMILY
|
||||||
|
FAMILY ?= F3
|
||||||
|
# MCU code
|
||||||
|
MCU ?= F303xb
|
||||||
|
# or __ARM_ARCH_7EM__
|
||||||
|
ARMARCH = __ARM_ARCH_7M__
|
||||||
|
# change this linking script depending on particular MCU model,
|
||||||
|
LDSCRIPT ?= stm32f303xB.ld
|
||||||
|
# debug
|
||||||
|
#DEFS = -DEBUG
|
||||||
|
|
||||||
|
INDEPENDENT_HEADERS=
|
||||||
|
|
||||||
|
FP_FLAGS ?= -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -fsingle-precision-constant -mlittle-endian -DARM_MATH_CM4
|
||||||
|
ASM_FLAGS ?= -mthumb -mcpu=cortex-m4
|
||||||
|
ARCH_FLAGS = $(ASM_FLAGS) $(FP_FLAGS) -D $(ARMARCH)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Executables
|
||||||
|
# PREFIX ?= arm-none-eabi
|
||||||
|
# gcc from arm web site
|
||||||
|
PREFIX ?= /opt/bin/arm-none-eabi
|
||||||
|
#TOOLCHLIB ?= /opt/arm-none-eabi/lib
|
||||||
|
RM := rm -f
|
||||||
|
RMDIR := rmdir
|
||||||
|
CC := $(PREFIX)-gcc
|
||||||
|
# don't replace ld with gcc: the binary size would be much greater!!
|
||||||
|
LD := $(PREFIX)-ld
|
||||||
|
AR := $(PREFIX)-ar
|
||||||
|
AS := $(PREFIX)-as
|
||||||
|
SIZE := $(PREFIX)-size
|
||||||
|
OBJCOPY := $(PREFIX)-objcopy
|
||||||
|
OBJDUMP := $(PREFIX)-objdump
|
||||||
|
GDB := $(PREFIX)-gdb
|
||||||
|
STFLASH := $(shell which st-flash)
|
||||||
|
STBOOT := $(shell which stm32flash)
|
||||||
|
DFUUTIL := $(shell which dfu-util)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Source files
|
||||||
|
OBJDIR := mk
|
||||||
|
SRC := $(wildcard *.c)
|
||||||
|
OBJS := $(addprefix $(OBJDIR)/, $(SRC:%.c=%.o))
|
||||||
|
STARTUP := $(OBJDIR)/startup.o
|
||||||
|
MAP := $(OBJDIR)/$(BINARY).map
|
||||||
|
OBJS += $(STARTUP)
|
||||||
|
# dependencies: we need them to recompile files if their headers-dependencies changed
|
||||||
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
INC_DIR ?= ../inc
|
||||||
|
|
||||||
|
INCLUDE := -I$(INC_DIR)/Fx -I$(INC_DIR)/cm
|
||||||
|
LIB_DIR := $(INC_DIR)/ld
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# C flags
|
||||||
|
CFLAGS += -g -gdwarf-2 # debuggin symbols in listing
|
||||||
|
CFLAGS += -O2 -D__thumb2__=1 -MD
|
||||||
|
CFLAGS += -Wall -Werror -Wextra -Wshadow
|
||||||
|
CFLAGS += -fshort-enums -ffunction-sections -fdata-sections
|
||||||
|
#CFLAGS += -fno-common -ffunction-sections -fdata-sections -fno-stack-protector
|
||||||
|
CFLAGS += $(ARCH_FLAGS)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Linker flags
|
||||||
|
#LDFLAGS += -nostartfiles --static -nostdlib -specs=nosys.specs -specs=nano.specs
|
||||||
|
LDFLAGS += $(ARCH_FLAGS)
|
||||||
|
LDFLAGS += -specs=nano.specs -specs=nosys.specs
|
||||||
|
LDFLAGS += -L$(LIB_DIR)
|
||||||
|
#-L$(TOOLCHLIB)
|
||||||
|
LDFLAGS += -T$(LDSCRIPT)
|
||||||
|
LDFLAGS += -Wl,-Map=$(MAP),--cref -Wl,--gc-sections -Wl,--print-memory-usage
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Used libraries
|
||||||
|
#LDLIBS += -lc $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
||||||
|
|
||||||
|
DEFS += -DSTM32$(FAMILY) -DSTM32$(MCU)
|
||||||
|
|
||||||
|
ELF := $(OBJDIR)/$(BINARY).elf
|
||||||
|
LIST := $(OBJDIR)/$(BINARY).list
|
||||||
|
BIN := $(BINARY).bin
|
||||||
|
HEX := $(BINARY).hex
|
||||||
|
|
||||||
|
all: bin list size
|
||||||
|
|
||||||
|
elf: $(ELF)
|
||||||
|
bin: $(BIN)
|
||||||
|
hex: $(HEX)
|
||||||
|
list: $(LIST)
|
||||||
|
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
|
-include $(DEPS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(STARTUP): $(INC_DIR)/startup/vector.c
|
||||||
|
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) -o $@ -c $<
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.c
|
||||||
|
@echo " CC $<"
|
||||||
|
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) -o $@ -c $<
|
||||||
|
|
||||||
|
$(BIN): $(ELF)
|
||||||
|
@echo " OBJCOPY $(BIN)"
|
||||||
|
$(OBJCOPY) -Obinary $(ELF) $(BIN)
|
||||||
|
|
||||||
|
$(HEX): $(ELF)
|
||||||
|
@echo " OBJCOPY $(HEX)"
|
||||||
|
$(OBJCOPY) -Oihex $(ELF) $(HEX)
|
||||||
|
|
||||||
|
$(LIST): $(ELF)
|
||||||
|
@echo " OBJDUMP $(LIST)"
|
||||||
|
$(OBJDUMP) -S $(ELF) > $(LIST)
|
||||||
|
|
||||||
|
$(ELF): $(OBJDIR) $(OBJS)
|
||||||
|
@echo " LD $(ELF)"
|
||||||
|
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(ELF)
|
||||||
|
|
||||||
|
size: $(ELF)
|
||||||
|
$(SIZE) $(ELF)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo " CLEAN"
|
||||||
|
$(RM) $(OBJS) $(DEPS) $(ELF) $(HEX) $(LIST) $(MAP)
|
||||||
|
@rmdir $(OBJDIR) 2>/dev/null || true
|
||||||
|
|
||||||
|
|
||||||
|
flash: $(BIN)
|
||||||
|
@echo " FLASH $(BIN)"
|
||||||
|
$(STFLASH) write $(BIN) 0x8000000
|
||||||
|
|
||||||
|
boot: $(BIN)
|
||||||
|
@echo " LOAD $(BIN) through bootloader"
|
||||||
|
$(STBOOT) -b$(BOOTSPEED) $(BOOTPORT) -w $(BIN)
|
||||||
|
|
||||||
|
dfuboot: $(BIN)
|
||||||
|
@echo " LOAD $(BIN) THROUGH DFU"
|
||||||
|
$(DFUUTIL) -a0 -D $(BIN) -s 0x08000000
|
||||||
|
|
||||||
|
.PHONY: clean flash boot
|
||||||
32
F303-nolib/floatPrintf/hardware.c
Normal file
32
F303-nolib/floatPrintf/hardware.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the F303usart project.
|
||||||
|
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hardware.h"
|
||||||
|
#include "usart.h"
|
||||||
|
|
||||||
|
static inline void gpio_setup(){
|
||||||
|
RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN; // for USART and LEDs
|
||||||
|
for(int i = 0; i < 10000; ++i) nop();
|
||||||
|
GPIOB->MODER = GPIO_MODER_MODER0_O | GPIO_MODER_MODER1_O;
|
||||||
|
GPIOB->ODR = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hw_setup(){
|
||||||
|
gpio_setup();
|
||||||
|
}
|
||||||
|
|
||||||
27
F303-nolib/floatPrintf/hardware.h
Normal file
27
F303-nolib/floatPrintf/hardware.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the F303usart project.
|
||||||
|
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef __HARDWARE_H__
|
||||||
|
#define __HARDWARE_H__
|
||||||
|
|
||||||
|
#include "stm32f3.h"
|
||||||
|
|
||||||
|
void hw_setup();
|
||||||
|
|
||||||
|
#endif // __HARDWARE_H__
|
||||||
163
F303-nolib/floatPrintf/main.c
Normal file
163
F303-nolib/floatPrintf/main.c
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the F303usart project.
|
||||||
|
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stm32f3.h"
|
||||||
|
#include "hardware.h"
|
||||||
|
#include "usart.h"
|
||||||
|
|
||||||
|
//#include <arm_math.h>
|
||||||
|
|
||||||
|
volatile uint32_t Tms = 0;
|
||||||
|
|
||||||
|
void sys_tick_handler(void){
|
||||||
|
++Tms;
|
||||||
|
}
|
||||||
|
|
||||||
|
# define IEEE_754_FLOAT_MANTISSA_BITS (23)
|
||||||
|
# define IEEE_754_FLOAT_EXPONENT_BITS (8)
|
||||||
|
# define IEEE_754_FLOAT_SIGN_BITS (1)
|
||||||
|
# if (IS_BIG_ENDIAN == 1)
|
||||||
|
typedef union {
|
||||||
|
float value;
|
||||||
|
struct {
|
||||||
|
__int8_t sign : IEEE_754_FLOAT_SIGN_BITS;
|
||||||
|
__int8_t exponent : IEEE_754_FLOAT_EXPONENT_BITS;
|
||||||
|
__uint32_t mantissa : IEEE_754_FLOAT_MANTISSA_BITS;
|
||||||
|
};
|
||||||
|
} IEEE_754_float;
|
||||||
|
# else
|
||||||
|
typedef union {
|
||||||
|
float value;
|
||||||
|
struct {
|
||||||
|
__uint32_t mantissa : IEEE_754_FLOAT_MANTISSA_BITS;
|
||||||
|
__int8_t exponent : IEEE_754_FLOAT_EXPONENT_BITS;
|
||||||
|
__int8_t sign : IEEE_754_FLOAT_SIGN_BITS;
|
||||||
|
};
|
||||||
|
} IEEE_754_float;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
|
||||||
|
#define P(x) usart_putchar(x)
|
||||||
|
#define S(x) usart_send(x)
|
||||||
|
|
||||||
|
// be careful: if pow10 would be bigger you should change str[] size!
|
||||||
|
static const float pwr10[] = {1., 10., 100., 1000., 10000.};
|
||||||
|
static const float rounds[] = {0.5, 0.05, 0.005, 0.0005, 0.00005};
|
||||||
|
#define P10L (sizeof(pwr10)/sizeof(uint32_t) - 1)
|
||||||
|
static char * float2str(float x, uint8_t prec){
|
||||||
|
if(prec > P10L) prec = P10L;
|
||||||
|
static char str[16] = {0}; // -117.5494E-36\0 - 14 symbols max!
|
||||||
|
char *s = str + 14; // go to end of buffer
|
||||||
|
uint8_t minus = 0;
|
||||||
|
if(x < 0){
|
||||||
|
x = -x;
|
||||||
|
minus = 1;
|
||||||
|
}
|
||||||
|
int pow = 0; // xxxEpow
|
||||||
|
// now convert float to 1.xxxE3y
|
||||||
|
while(x > 1000.f){
|
||||||
|
x /= 1000.f;
|
||||||
|
pow += 3;
|
||||||
|
}
|
||||||
|
while(x < 1.){
|
||||||
|
x *= 1000.f;
|
||||||
|
pow -= 3;
|
||||||
|
}
|
||||||
|
// print Eyy
|
||||||
|
if(pow){
|
||||||
|
uint8_t m = 0;
|
||||||
|
if(pow < 0){pow = -pow; m = 1;}
|
||||||
|
while(pow){
|
||||||
|
register int p10 = pow/10;
|
||||||
|
*s-- = '0' + (pow - 10*p10);
|
||||||
|
pow = p10;
|
||||||
|
}
|
||||||
|
if(m) *s-- = '-';
|
||||||
|
*s-- = 'E';
|
||||||
|
}
|
||||||
|
// now our number is in [1, 1000]
|
||||||
|
uint32_t units;
|
||||||
|
if(prec){
|
||||||
|
units = (uint32_t) x;
|
||||||
|
uint32_t decimals = (uint32_t)((x-units+rounds[prec])*pwr10[prec]);
|
||||||
|
// print decimals
|
||||||
|
while(prec){
|
||||||
|
register int d10 = decimals / 10;
|
||||||
|
*s-- = '0' + (decimals - 10*d10);
|
||||||
|
decimals = d10;
|
||||||
|
--prec;
|
||||||
|
}
|
||||||
|
// decimal point
|
||||||
|
*s-- = '.';
|
||||||
|
}else{ // without decimal part
|
||||||
|
units = (uint32_t) (x + 0.5);
|
||||||
|
}
|
||||||
|
// print main units
|
||||||
|
if(units == 0) *s-- = '0';
|
||||||
|
else while(units){
|
||||||
|
register uint32_t u10 = units / 10;
|
||||||
|
*s-- = '0' + (units - 10*u10);
|
||||||
|
units = u10;
|
||||||
|
}
|
||||||
|
if(minus) *s-- = '-';
|
||||||
|
return s+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const float tests[] = {-1.23456789e-37, -3.14159265e-2, -1234.56789, -1.2345678, 0.1234567, 123.456789, 1.98765e7, 2.473829e31};
|
||||||
|
#define TESTN 8
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
sysreset();
|
||||||
|
if(!StartHSE()) StartHSI();
|
||||||
|
SysTick_Config((uint32_t)72000); // 1ms
|
||||||
|
hw_setup();
|
||||||
|
usart_setup();
|
||||||
|
usart_send("Start\n");
|
||||||
|
uint32_t ctr = Tms;
|
||||||
|
float x = 0.519, more = 5.123;
|
||||||
|
while(1){
|
||||||
|
if(Tms - ctr > 499){
|
||||||
|
//usart_send("ping\n");
|
||||||
|
ctr = Tms;
|
||||||
|
pin_toggle(GPIOB, 1 << 1 | 1 << 0); // toggle LED @ PB0
|
||||||
|
/**/
|
||||||
|
if((x += 0.519) > more){
|
||||||
|
//usart_send("MORE!\n");
|
||||||
|
more += 5.123;
|
||||||
|
//__get_FPSCR();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(bufovr){
|
||||||
|
bufovr = 0;
|
||||||
|
usart_send("bufovr\n");
|
||||||
|
}
|
||||||
|
char *txt = NULL;
|
||||||
|
if(usart_getline(&txt)){
|
||||||
|
if(*txt == '?'){
|
||||||
|
for(int i = 0; i < TESTN; ++i) for(int j = 0; j <= (int)P10L; ++j){
|
||||||
|
usart_send(float2str(tests[i], j));
|
||||||
|
usart_putchar('\n');
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
usart_send("Get by USART1: ");
|
||||||
|
usart_send(txt);
|
||||||
|
usart_putchar('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
106
F303-nolib/floatPrintf/usart.c
Normal file
106
F303-nolib/floatPrintf/usart.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the F303usart project.
|
||||||
|
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "stm32f3.h"
|
||||||
|
#include "hardware.h"
|
||||||
|
#include "usart.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static volatile int idatalen = 0; // received data line length (including '\n')
|
||||||
|
|
||||||
|
volatile int linerdy = 0, // received data ready
|
||||||
|
dlen = 0, // length of data (including '\n') in current buffer
|
||||||
|
bufovr = 0; // input buffer overfull
|
||||||
|
|
||||||
|
static volatile int rbufno = 0; // current rbuf number
|
||||||
|
static char rbuf[2][UARTBUFSZ]; // receive buffers
|
||||||
|
static volatile char *recvdata = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return length of received data (without trailing zero)
|
||||||
|
*/
|
||||||
|
int usart_getline(char **line){
|
||||||
|
if(bufovr){
|
||||||
|
bufovr = 0;
|
||||||
|
linerdy = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(!linerdy) return 0;
|
||||||
|
*line = (char*)recvdata;
|
||||||
|
linerdy = 0;
|
||||||
|
return dlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void usart_putchar(const char ch){
|
||||||
|
while(!(USART1->ISR & USART_ISR_TXE));
|
||||||
|
USART1->TDR = ch;
|
||||||
|
}
|
||||||
|
void usart_sendn(const char *str, int L){
|
||||||
|
if(!str) return;
|
||||||
|
for(int i = 0; i < L; ++i){
|
||||||
|
usart_putchar(str[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void usart_send(const char *str){
|
||||||
|
if(!str) return;
|
||||||
|
int L = 0;
|
||||||
|
const char *ptr = str;
|
||||||
|
while(*ptr++) ++L;
|
||||||
|
usart_sendn(str, L);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usart_setup(){
|
||||||
|
// USART1: Rx - PA10 (AF7), Tx - PA9 (AF7)
|
||||||
|
// setup pins:
|
||||||
|
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER9 | GPIO_MODER_MODER10)) |
|
||||||
|
GPIO_MODER_MODER9_AF | GPIO_MODER_MODER10_AF;
|
||||||
|
GPIOA->AFR[1] = (GPIOA->AFR[1] & ~(GPIO_AFRH_AFRH1 | GPIO_AFRH_AFRH2)) |
|
||||||
|
7 << (1 * 4) | 7 << (2 * 4); // PA9, PA10
|
||||||
|
// clock
|
||||||
|
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
|
||||||
|
USART1->ICR = 0xffffffff; // clear all flags
|
||||||
|
USART1->BRR = 720000 / 1152;
|
||||||
|
USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE | USART_CR1_RXNEIE; // 1start,8data,nstop; enable Rx,Tx,USART
|
||||||
|
uint32_t tmout = 16000000;
|
||||||
|
while(!(USART1->ISR & USART_ISR_TC)){if(--tmout == 0) break;} // polling idle frame Transmission
|
||||||
|
USART1->ICR = 0xffffffff; // clear all flags again
|
||||||
|
NVIC_SetPriority(USART1_IRQn, 0);
|
||||||
|
NVIC_EnableIRQ(USART1_IRQn);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usart1_exti25_isr(){
|
||||||
|
if(USART1->ISR & USART_ISR_RXNE){ // RX not emty - receive next char
|
||||||
|
// read RDR clears flag
|
||||||
|
uint8_t rb = USART1->RDR;
|
||||||
|
if(idatalen < UARTBUFSZ){ // put next char into buf
|
||||||
|
rbuf[rbufno][idatalen++] = rb;
|
||||||
|
if(rb == '\n'){ // got newline - line ready
|
||||||
|
linerdy = 1;
|
||||||
|
dlen = idatalen;
|
||||||
|
recvdata = rbuf[rbufno];
|
||||||
|
recvdata[dlen-1] = 0;
|
||||||
|
// prepare other buffer
|
||||||
|
rbufno = !rbufno;
|
||||||
|
idatalen = 0;
|
||||||
|
}
|
||||||
|
}else{ // buffer overrun
|
||||||
|
bufovr = 1;
|
||||||
|
idatalen = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
F303-nolib/floatPrintf/usart.h
Normal file
36
F303-nolib/floatPrintf/usart.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the F303usart project.
|
||||||
|
* Copyright 2021 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#ifndef __USART_H__
|
||||||
|
#define __USART_H__
|
||||||
|
|
||||||
|
#include "hardware.h"
|
||||||
|
|
||||||
|
// input buffers size
|
||||||
|
#define UARTBUFSZ (80)
|
||||||
|
|
||||||
|
extern volatile int linerdy, bufovr;
|
||||||
|
|
||||||
|
void usart_setup();
|
||||||
|
int usart_getline(char **line);
|
||||||
|
void usart_send(const char *str);
|
||||||
|
void usart_sendn(const char *str, int L);
|
||||||
|
void usart_putchar(const char ch);
|
||||||
|
|
||||||
|
#endif // __USART_H__
|
||||||
BIN
F303-nolib/floatPrintf/usart1.bin
Executable file
BIN
F303-nolib/floatPrintf/usart1.bin
Executable file
Binary file not shown.
@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
|
#define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field.
|
||||||
This value must be a multiple of 0x200. */
|
This value must be a multiple of 0x200. */
|
||||||
|
/*
|
||||||
|
TRUE_INLINE void enable_FPU(){
|
||||||
|
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); // set CP10 and CP11 Full Access
|
||||||
|
}*/
|
||||||
|
|
||||||
//extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
//extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
||||||
//extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */
|
//extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */
|
||||||
@ -45,11 +49,6 @@
|
|||||||
*/
|
*/
|
||||||
TRUE_INLINE void sysreset(void) // not usable
|
TRUE_INLINE void sysreset(void) // not usable
|
||||||
{
|
{
|
||||||
/* FPU settings ------------------------------------------------------------*/
|
|
||||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
|
||||||
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Reset the RCC clock configuration to the default reset state ------------*/
|
/* Reset the RCC clock configuration to the default reset state ------------*/
|
||||||
/* Set HSION bit */
|
/* Set HSION bit */
|
||||||
RCC->CR |= RCC_CR_HSION;
|
RCC->CR |= RCC_CR_HSION;
|
||||||
|
|||||||
7538
F303-nolib/inc/cm/arm_math.h
Normal file
7538
F303-nolib/inc/cm/arm_math.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -833,6 +833,14 @@ void WEAK __attribute__ ((naked)) __attribute__ ((noreturn)) reset_handler(void)
|
|||||||
// enable 8-byte stack alignment to comply with AAPCS
|
// enable 8-byte stack alignment to comply with AAPCS
|
||||||
SCB->CCR |= 0x00000200;
|
SCB->CCR |= 0x00000200;
|
||||||
|
|
||||||
|
/* FPU settings ------------------------------------------------------------*/
|
||||||
|
#if (__FPU_PRESENT == 1)
|
||||||
|
SCB->CPACR = 0x0f << 20 ; /* set CP10 and CP11 Full Access */
|
||||||
|
nop();
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
#endif
|
||||||
|
|
||||||
// copy initialized variables data
|
// copy initialized variables data
|
||||||
while ( dst < &_edata ) { *dst++ = *src++; }
|
while ( dst < &_edata ) { *dst++ = *src++; }
|
||||||
|
|
||||||
|
|||||||
0
F303-nolib/usart1/usart1.bin
Normal file → Executable file
0
F303-nolib/usart1/usart1.bin
Normal file → Executable file
0
F303-nolib/usarts/usart.bin
Normal file → Executable file
0
F303-nolib/usarts/usart.bin
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user