mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 11:54:30 +03:00
some code fixes, start to draw new schematic
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 12.0.2, 2024-03-07T19:39:35. -->
|
||||
<!-- Written by QtCreator 12.0.2, 2024-03-18T00:40:28. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@@ -133,6 +133,11 @@ static errcodes initspi2(CAN_message _U_ *msg){
|
||||
spi_setup(2);
|
||||
return ERR_OK;
|
||||
}
|
||||
// deinit SPI2
|
||||
static errcodes deinitspi2(CAN_message _U_ *msg){
|
||||
spi_deinit(2);
|
||||
return ERR_OK;
|
||||
}
|
||||
// send/read 1..4 bytes
|
||||
static errcodes sendspi2(CAN_message *msg){
|
||||
int n = msg->length - 4;
|
||||
@@ -175,6 +180,7 @@ static errcodes flagsetget(CAN_message *msg){
|
||||
uint8_t bit = 32;
|
||||
switch(idx){
|
||||
case CMD_ENCISSSI: bit = FLAGBIT(ENC_IS_SSI); break;
|
||||
case CMD_EMULPEP: bit = FLAGBIT(EMULATE_PEP); break;
|
||||
default: break;
|
||||
}
|
||||
if(bit > 31) return ERR_CANTRUN; // unknown error
|
||||
@@ -220,6 +226,7 @@ static const commonfunction funclist[CMD_AMOUNT] = {
|
||||
[CMD_EMULPEP] = {flagsetget, 0, 0, 0},
|
||||
[CMD_ENCREINIT] = {encreinit, 0, 0, 0},
|
||||
[CMD_TIMESTAMP] = {timestamp_getset, 0, 0xffffff, 0},
|
||||
[CMD_SPIDEINIT] = {deinitspi2, 0, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -38,9 +38,24 @@ void encoder_setup(){
|
||||
// read encoder value into buffer `outbuf`
|
||||
// return TRUE if all OK
|
||||
int read_encoder(uint8_t outbuf[4]){
|
||||
if(!FLAG(ENC_IS_SSI)) return FALSE;
|
||||
*((uint32_t*)outbuf) = 0;
|
||||
return spi_writeread(ENCODER_SPI, outbuf, 4);
|
||||
if(FLAG(ENC_IS_SSI)){
|
||||
int r = spi_read(ENCODER_SPI, outbuf, 4);
|
||||
return r;
|
||||
}
|
||||
usart_rstbuf();
|
||||
// just send some trash over USART1 if encoder is RS-422
|
||||
usart_send("teststring\n");
|
||||
char *x;
|
||||
uint32_t Tl = Tms;
|
||||
while(Tms - Tl < 10){
|
||||
int l = usart_getline(&x);
|
||||
if(l){
|
||||
for(int i = 0; i < l && i < 4; ++i) outbuf[i] = x[i];
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// send encoder data
|
||||
@@ -57,7 +72,6 @@ void CANsendEnc(){
|
||||
// send limit-switches data
|
||||
void CANsendLim(){
|
||||
CAN_message msg = {.data = {0}, .ID = the_conf.limitsID, .length = 8};
|
||||
msg.data[2] = getESW(0);
|
||||
msg.data[3] = getESW(1);
|
||||
msg.data[2] = getESW(1);
|
||||
CAN_send(&msg);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,11 @@
|
||||
(generator_version "8.99")
|
||||
(uuid "c774fcd8-2321-49e3-82b6-f080291ee83c")
|
||||
(paper "A4")
|
||||
(title_block
|
||||
(date "2024-03-18")
|
||||
(company "SAO RAS")
|
||||
(comment 1 "Instead of PEP controller")
|
||||
)
|
||||
(lib_symbols
|
||||
(symbol "Device:R"
|
||||
(pin_numbers hide)
|
||||
@@ -518,7 +523,7 @@
|
||||
(justify left)
|
||||
)
|
||||
)
|
||||
(property "Value" "360"
|
||||
(property "Value" "3k3"
|
||||
(at 109.093 51.943 90)
|
||||
(effects
|
||||
(font
|
||||
@@ -527,7 +532,7 @@
|
||||
(justify left)
|
||||
)
|
||||
)
|
||||
(property "Footprint" "Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder"
|
||||
(property "Footprint" "Resistor_SMD:R_2010_5025Metric_Pad1.40x2.65mm_HandSolder"
|
||||
(at 107.442 50.419 90)
|
||||
(effects
|
||||
(font
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
36
|
||||
],
|
||||
"visible_layers": "fffffff_ffffffff",
|
||||
"zone_display_mode": 0
|
||||
"zone_display_mode": 1
|
||||
},
|
||||
"git": {
|
||||
"repo_password": "",
|
||||
|
||||
@@ -565,11 +565,29 @@
|
||||
"label": "DNP",
|
||||
"name": "${DNP}",
|
||||
"show": true
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "#",
|
||||
"name": "${ITEM_NUMBER}",
|
||||
"show": false
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Manufacturer",
|
||||
"name": "Manufacturer",
|
||||
"show": false
|
||||
},
|
||||
{
|
||||
"group_by": false,
|
||||
"label": "Description",
|
||||
"name": "Description",
|
||||
"show": false
|
||||
}
|
||||
],
|
||||
"filter_string": "",
|
||||
"group_symbols": true,
|
||||
"name": "Grouped By Value",
|
||||
"name": "",
|
||||
"sort_asc": true,
|
||||
"sort_field": "Reference"
|
||||
},
|
||||
@@ -619,8 +637,8 @@
|
||||
"spice_save_all_currents": false,
|
||||
"spice_save_all_dissipations": false,
|
||||
"spice_save_all_voltages": false,
|
||||
"subpart_first_id": 65,
|
||||
"subpart_id_separator": 0
|
||||
"subpart_first_id": 49,
|
||||
"subpart_id_separator": 46
|
||||
},
|
||||
"sheets": [
|
||||
[
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -72,6 +72,7 @@ typedef enum{
|
||||
CMD_EMULPEP, // 19 - emulate (1) / not (0) PEP
|
||||
CMD_ENCREINIT, // 20 - reinit encoder
|
||||
CMD_TIMESTAMP, // 21 - 2mks 24-bit timestamp
|
||||
CMD_SPIDEINIT, // 22 - turn off SPI2
|
||||
CMD_AMOUNT // amount of CAN commands
|
||||
} can_cmd;
|
||||
|
||||
|
||||
@@ -81,10 +81,17 @@ void spi_setup(uint8_t idx){
|
||||
// DS=8bit; RXNE generates after 8bit of data in FIFO;
|
||||
SPI->CR2 |= SPI_CR2_FRXTH | SPI_CR2_DS_2|SPI_CR2_DS_1|SPI_CR2_DS_0;
|
||||
spi_status[idx] = SPI_READY;
|
||||
SPI->CR1 |= SPI_CR1_SPE;
|
||||
if(idx == 2) SPI->CR1 |= SPI_CR1_SPE; // turn on SPI1 only when reading data
|
||||
DBG("SPI works");
|
||||
}
|
||||
|
||||
void spi_onoff(uint8_t idx, uint8_t on){
|
||||
CHKIDX(idx);
|
||||
volatile SPI_TypeDef *SPI = SPIs[idx];
|
||||
if(on) SPI->CR1 |= SPI_CR1_SPE;
|
||||
else SPI->CR1 &= ~SPI_CR1_SPE;
|
||||
}
|
||||
|
||||
// turn off given SPI channel and release GPIO
|
||||
void spi_deinit(uint8_t idx){
|
||||
CHKIDX(idx);
|
||||
@@ -100,6 +107,7 @@ void spi_deinit(uint8_t idx){
|
||||
GPIOB->AFR[1] = GPIOB->AFR[1] & ~(GPIO_AFRH_AFRH4 | GPIO_AFRH_AFRH5 | GPIO_AFRH_AFRH6 | GPIO_AFRH_AFRH7);
|
||||
GPIOB->MODER = GPIOB->MODER & ~(GPIO_MODER_MODER12 | GPIO_MODER_MODER13 | GPIO_MODER_MODER14 | GPIO_MODER_MODER15);
|
||||
}
|
||||
spi_status[idx] = SPI_NOTREADY;
|
||||
}
|
||||
|
||||
int spi_waitbsy(uint8_t idx){
|
||||
@@ -120,6 +128,8 @@ int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n){
|
||||
DBG("not ready");
|
||||
return 0;
|
||||
}
|
||||
// clear SPI Rx FIFO
|
||||
for(int i = 0; i < 4; ++i) (void) SPI2->DR;
|
||||
for(uint32_t x = 0; x < n; ++x){
|
||||
WAITX(!(SPIs[idx]->SR & SPI_SR_TXE));
|
||||
*((volatile uint8_t*)&SPIs[idx]->DR) = data[x];
|
||||
@@ -129,6 +139,26 @@ int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n){
|
||||
return 1;
|
||||
}
|
||||
|
||||
// read data through SPI in read-only mode
|
||||
int spi_read(uint8_t idx, uint8_t *data, uint32_t n){
|
||||
CHKIDXR(idx);
|
||||
if(spi_status[idx] != SPI_READY || !data || !n){
|
||||
DBG("not ready");
|
||||
return 0;
|
||||
}
|
||||
// clear SPI Rx FIFO
|
||||
for(int i = 0; i < 4; ++i) (void) SPI2->DR;
|
||||
spi_onoff(idx, TRUE);
|
||||
for(uint32_t x = 0; x < n; ++x){
|
||||
if(x == n - 1) SPIs[idx]->CR1 &= ~SPI_CR1_RXONLY;
|
||||
WAITX(!(SPIs[idx]->SR & SPI_SR_RXNE));
|
||||
data[x] = *((volatile uint8_t*)&SPIs[idx]->DR);
|
||||
}
|
||||
spi_onoff(idx, FALSE);
|
||||
SPIs[idx]->CR1 |= SPI_CR1_RXONLY;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief spi_send_dma - send data over SPI2 through DMA (used both for writing and reading)
|
||||
* @param data - data to read
|
||||
|
||||
@@ -29,10 +29,12 @@ typedef enum{
|
||||
|
||||
extern spiStatus spi_status[AMOUNT_OF_SPI+1];
|
||||
|
||||
void spi_onoff(uint8_t idx, uint8_t on);
|
||||
void spi_deinit(uint8_t idx);
|
||||
void spi_setup(uint8_t idx);
|
||||
int spi_waitbsy(uint8_t idx);
|
||||
int spi_writeread(uint8_t idx, uint8_t *data, uint32_t n);
|
||||
int spi_read(uint8_t idx, uint8_t *data, uint32_t n);
|
||||
//int spi_write_dma(const uint8_t *data, uint8_t *rxbuf, uint32_t n);
|
||||
//int spi_read(uint8_t idx, uint8_t *data, uint32_t n);
|
||||
//uint8_t *spi_read_dma(uint32_t *n);
|
||||
|
||||
@@ -263,8 +263,11 @@ const char *getint(const char *txt, int32_t *I){
|
||||
}
|
||||
const char *nxt = getnum(s, &U);
|
||||
if(nxt == s) return txt;
|
||||
if(U & 0x80000000) return txt; // overfull
|
||||
*I = sign * (int32_t)U;
|
||||
if(U & 0x80000000){ // uint32_t
|
||||
*I = (int32_t)U;
|
||||
}else{
|
||||
*I = sign * (int32_t)U;
|
||||
}
|
||||
return nxt;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ static const funcdescr funclist[] = {
|
||||
{"reset", CMD_RESET, "reset MCU"},
|
||||
{"s", -TCMD_CANSEND, "send CAN message: ID 0..8 data bytes"},
|
||||
{"saveconf", CMD_SAVECONF, "save configuration"},
|
||||
{"spideinit", CMD_SPIDEINIT, "turn off SPI2"},
|
||||
{"spiinit", CMD_SPIINIT, "init SPI2"},
|
||||
{"spisend", CMD_SPISEND, "send 4 bytes over SPI2"},
|
||||
{"time", CMD_TIME, "get/set time (1ms, 32bit)"},
|
||||
@@ -90,6 +91,7 @@ static errcodes wdtest(const char _U_ *str){
|
||||
// names of bit flags (ordered from LSE of[0])
|
||||
static const char * const bitfields[] = {
|
||||
"encisSSI",
|
||||
"emulatePEP",
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -112,7 +114,7 @@ static errcodes dumpconf(const char _U_ *str){
|
||||
USB_sendstr("\nusartspeed="); printu(the_conf.usartspeed);
|
||||
const char * const *p = bitfields;
|
||||
int bit = 0;
|
||||
while(p){
|
||||
while(*p){
|
||||
newline();
|
||||
USB_sendstr(*p); USB_putbyte('='); USB_putbyte((the_conf.flags & (1<<bit)) ? '1' : '0');
|
||||
if(++bit > 31) break;
|
||||
|
||||
@@ -32,6 +32,14 @@ static volatile int rbufno = 0; // current rbuf number
|
||||
static char rbuf[2][UARTBUFSZ]; // receive buffers
|
||||
static volatile char *recvdata = NULL;
|
||||
|
||||
// reset incoming buffer
|
||||
void usart_rstbuf(){
|
||||
linerdy = 0;
|
||||
dlen = 0;
|
||||
bufovr = 0;
|
||||
recvdata = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* return length of received data (without trailing zero)
|
||||
*/
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
// input buffers size
|
||||
#define UARTBUFSZ (80)
|
||||
|
||||
void usart_rstbuf();
|
||||
void usart_setup();
|
||||
void usart_deinit();
|
||||
int usart_getline(char **line);
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#define BUILD_NUMBER "84"
|
||||
#define BUILD_DATE "2024-03-08"
|
||||
#define BUILD_NUMBER "93"
|
||||
#define BUILD_DATE "2024-03-17"
|
||||
|
||||
Reference in New Issue
Block a user