mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 02:35:23 +03:00
remove usart1 as it used common DMA with SPI2rx
This commit is contained in:
parent
33497f79b5
commit
e5b3edeffa
Binary file not shown.
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 15.0.0, 2025-01-08T17:55:30. -->
|
||||
<!-- Written by QtCreator 15.0.1, 2025-03-26T17:57:31. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
|
||||
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
@ -40,9 +40,9 @@
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
@ -51,10 +51,10 @@
|
||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
|
||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
||||
</valuemap>
|
||||
@ -79,7 +79,7 @@
|
||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">8</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||
@ -94,11 +94,12 @@
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/ELECTRONICS/STM32/F1-srcs/BISS_C_encoders</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
|
||||
@ -108,8 +109,8 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
@ -121,8 +122,8 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
@ -130,15 +131,15 @@
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||
|
||||
@ -11,8 +11,6 @@ spi.c
|
||||
spi.h
|
||||
strfunc.c
|
||||
strfunc.h
|
||||
usart.c
|
||||
usart.h
|
||||
usb_descr.c
|
||||
usb_descr.h
|
||||
usb_lib.c
|
||||
|
||||
@ -20,16 +20,19 @@
|
||||
|
||||
static inline void gpio_setup(){
|
||||
// Enable clocks to the GPIO subsystems (PB for ADC), turn on AFIO clocking to disable SWD/JTAG
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN | RCC_APB2ENR_SPI1EN;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
|
||||
// turn off SWJ/JTAG
|
||||
// AFIO->MAPR = AFIO_MAPR_SWJ_CFG_DISABLE;
|
||||
AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE; // for PA15
|
||||
// Set led as opendrain output
|
||||
GPIOC->CRH |= CRH(13, CNF_ODOUTPUT|MODE_SLOW);
|
||||
GPIOA->CRL = CRL(5, CNF_AFPP|MODE_FAST) | CRL(6, CNF_FLINPUT);
|
||||
// SPI1 pins
|
||||
//GPIOA->CRL = CRL(5, CNF_AFPP|MODE_FAST) | CRL(6, CNF_FLINPUT);
|
||||
// USB pullup (PA15) - pushpull output
|
||||
GPIOA->CRH = CRH(15, CNF_PPOUTPUT|MODE_SLOW);
|
||||
GPIOB->CRH = CRH(13, CNF_AFPP|MODE_FAST) | CRH(14, CNF_FLINPUT);
|
||||
// SPI2 pins
|
||||
//GPIOB->CRH = CRH(13, CNF_AFPP|MODE_FAST) | CRH(14, CNF_FLINPUT);
|
||||
}
|
||||
|
||||
void hw_setup(){
|
||||
|
||||
@ -40,11 +40,12 @@ int main(){
|
||||
hw_setup();
|
||||
USBPU_OFF();
|
||||
SysTick_Config(72000);
|
||||
/*
|
||||
#ifdef EBUG
|
||||
usart_setup();
|
||||
DBG("Start");
|
||||
uint32_t tt = 0;
|
||||
#endif
|
||||
*/
|
||||
USB_setup();
|
||||
#ifndef EBUG
|
||||
iwdg_setup();
|
||||
@ -56,6 +57,7 @@ int main(){
|
||||
LED_blink(LED0);
|
||||
lastT = Tms;
|
||||
}
|
||||
/*
|
||||
#ifdef EBUG
|
||||
if(Tms != tt){
|
||||
__disable_irq();
|
||||
@ -64,6 +66,7 @@ int main(){
|
||||
__enable_irq();
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
if(CDCready[I_CMD]){
|
||||
if(Tms - lastS > 9999){
|
||||
USB_sendstr(I_CMD, "Tms=");
|
||||
@ -75,6 +78,12 @@ int main(){
|
||||
if(l < 0) CMDWRn("ERROR: CMD USB buffer overflow or string was too long");
|
||||
else if(l) parse_cmd(inbuff);
|
||||
}
|
||||
int showval = spi_read_enc(0, encbuf);
|
||||
if(CDCready[I_CMD] && showval){
|
||||
CMDWR("ENCX=");
|
||||
hexdump(I_CMD, encbuf, ENCODER_BUFSZ);
|
||||
newline(I_CMD);
|
||||
}
|
||||
if(CDCready[I_X]){
|
||||
int l = USB_receivestr(I_X, inbuff, RBINSZ);
|
||||
if(l < 0) CMDWRn("ERROR: encX USB buffer overflow or string was too long");
|
||||
@ -83,9 +92,14 @@ int main(){
|
||||
CMDWR(inbuff);
|
||||
CMDWR("'\n");
|
||||
}
|
||||
if(spi_read_enc(0, encbuf)){ // send encoder data
|
||||
if(showval) // send encoder data
|
||||
hexdump(I_X, encbuf, ENCODER_BUFSZ);
|
||||
}
|
||||
}
|
||||
showval = spi_read_enc(1, encbuf);
|
||||
if(CDCready[I_CMD] && showval){
|
||||
CMDWR("ENCY=");
|
||||
hexdump(I_CMD, encbuf, ENCODER_BUFSZ);
|
||||
newline(I_CMD);
|
||||
}
|
||||
if(CDCready[I_Y]){
|
||||
int l = USB_receivestr(I_Y, inbuff, RBINSZ);
|
||||
@ -95,9 +109,8 @@ int main(){
|
||||
CMDWR(inbuff);
|
||||
CMDWR("'\n");
|
||||
}
|
||||
if(spi_read_enc(1, encbuf)){ // send encoder data
|
||||
if(showval) // send encoder data
|
||||
hexdump(I_Y, encbuf, ENCODER_BUFSZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -55,9 +55,11 @@ typedef enum{
|
||||
C_dumpconf,
|
||||
C_erasestorage,
|
||||
C_storeconf,
|
||||
C_reboot,
|
||||
C_reset,
|
||||
C_fin,
|
||||
C_encstart,
|
||||
C_encX,
|
||||
C_encY,
|
||||
C_spistat,
|
||||
C_spiinit,
|
||||
C_spideinit,
|
||||
@ -154,7 +156,7 @@ static errcode_e storeconf(_U_ cmd_e idx, _U_ char *par){
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static errcode_e reboot(_U_ cmd_e idx, _U_ char *par){
|
||||
static errcode_e reset(_U_ cmd_e idx, _U_ char *par){
|
||||
NVIC_SystemReset();
|
||||
return ERR_OK; // never reached
|
||||
}
|
||||
@ -164,9 +166,11 @@ static errcode_e fini(_U_ cmd_e idx, _U_ char *par){
|
||||
return ERR_OK; // never reached
|
||||
}
|
||||
|
||||
static errcode_e encstart(_U_ cmd_e idx, _U_ char *par){
|
||||
if(!spi_start_enc(0)) return ERR_FAIL;
|
||||
if(!spi_start_enc(1)) return ERR_FAIL;
|
||||
static errcode_e encstart(cmd_e idx, _U_ char *par){
|
||||
if(idx == C_encX || idx == C_encstart)
|
||||
if(!spi_start_enc(0)) return ERR_FAIL;
|
||||
if(idx == C_encY || idx == C_encstart)
|
||||
if(!spi_start_enc(1)) return ERR_FAIL;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@ -223,9 +227,11 @@ static const funcdescr_t commands[C_AMOUNT] = {
|
||||
[C_dumpconf] = {"dumpconf", dumpconf},
|
||||
[C_erasestorage] = {"erasestorage", erasestor},
|
||||
[C_storeconf] = {"storeconf", storeconf},
|
||||
[C_reboot] = {"reboot", reboot},
|
||||
[C_reset] = {"reset", reset},
|
||||
[C_fin] = {"fin", fini},
|
||||
[C_encstart] = {"readenc", encstart},
|
||||
[C_encX] = {"readX", encstart},
|
||||
[C_encY] = {"readY", encstart},
|
||||
[C_spistat] = {"spistat", spistat},
|
||||
[C_spiinit] = {"spiinit", spiinit},
|
||||
[C_spideinit] = {"spideinit", spideinit},
|
||||
@ -257,8 +263,10 @@ static const help_t helpmessages[] = {
|
||||
{-1, "Different commands"},
|
||||
{C_dummy, "dummy integer setter/getter"},
|
||||
{C_encstart, "start reading encoders"},
|
||||
{C_encX, "read only X encoder"},
|
||||
{C_encY, "read only Y encoder"},
|
||||
{C_help, "show this help"},
|
||||
{C_reboot, "reboot MCU"},
|
||||
{C_reset, "reset MCU"},
|
||||
{C_spideinit, "deinit SPI"},
|
||||
{C_spiinit, "init SPI"},
|
||||
{C_spistat, "get status of both SPI interfaces"},
|
||||
|
||||
@ -47,20 +47,20 @@ void spi_setup(uint8_t idx){
|
||||
RCC->AHBENR |= RCC_AHBENR_DMA1EN;
|
||||
volatile DMA_Channel_TypeDef *DMA = DMAs[idx];
|
||||
if(idx == 1){ // PA5/PA6; 72MHz
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
|
||||
RCC->APB2RSTR = RCC_APB2RSTR_SPI1RST;
|
||||
RCC->APB2RSTR = 0; // clear reset
|
||||
GPIOA->CRL = (GPIOA->CRL & ~(GPIO_CRL_CNF5 | GPIO_CRL_CNF6))
|
||||
| CRL(5, CNF_AFPP|MODE_FAST) | CRL(6, CNF_FLINPUT);
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
|
||||
SPI->CR1 = SPI_CR1_BR_0 | SPI_CR1_BR_2; // Fpclk/64
|
||||
SPI->CR1 = SPI_CR1_BR_1 | SPI_CR1_BR_2; // Fpclk/128
|
||||
NVIC_EnableIRQ(DMA1_Channel2_IRQn); // enable Rx interrupt
|
||||
}else if(idx == 2){ // PB12..PB15; 36MHz
|
||||
}else if(idx == 2){ // PB13/PB14; 36MHz
|
||||
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
|
||||
RCC->APB1RSTR = RCC_APB1RSTR_SPI2RST;
|
||||
RCC->APB1RSTR = 0;
|
||||
GPIOB->CRH = (GPIOB->CRH & ~(GPIO_CRH_CNF13 | GPIO_CRH_CNF14))
|
||||
| CRH(13, CNF_AFPP|MODE_FAST) | CRH(14, CNF_FLINPUT);
|
||||
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
|
||||
SPI->CR1 = SPI_CR1_BR_2; // Fpclk/32
|
||||
SPI->CR1 = SPI_CR1_BR_0 | SPI_CR1_BR_2; // Fpclk/64
|
||||
NVIC_EnableIRQ(DMA1_Channel4_IRQn);
|
||||
}else return; // err
|
||||
// Baudrate = 0b110 - fpclk/128
|
||||
@ -103,11 +103,15 @@ void spi_deinit(uint8_t idx){
|
||||
spi_status[idx] = SPI_NOTREADY;
|
||||
}
|
||||
|
||||
int spi_waitbsy(uint8_t idx){
|
||||
static int spi_waitbsy(uint8_t idx){
|
||||
CHKIDXR(idx);
|
||||
DBGs(u2str(idx));
|
||||
DBG("wait busy");
|
||||
WAITX(SPIs[idx]->SR & SPI_SR_BSY);
|
||||
if(SPIs[idx]->SR & SPI_SR_BSY){
|
||||
DBG("Busy - turn off");
|
||||
spi_onoff(idx, 0); // turn off SPI if it's busy
|
||||
}
|
||||
//DBGs(u2str(idx));
|
||||
//DBG("wait busy");
|
||||
//WAITX(SPIs[idx]->SR & SPI_SR_BSY);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -143,6 +147,8 @@ int spi_start_enc(int encodernum){
|
||||
|
||||
// SSI got fresh data
|
||||
void dma1_channel2_isr(){
|
||||
// turn off DMA
|
||||
DMA1_Channel2->CCR &= ~DMA_CCR_EN;
|
||||
if(DMA1->ISR & DMA_ISR_TEIF2){
|
||||
DMA1->IFCR = DMA_IFCR_CTEIF2;
|
||||
}
|
||||
@ -155,11 +161,11 @@ void dma1_channel2_isr(){
|
||||
//encoderbuf[7] = (ctr >> 0 ) & 0xff;
|
||||
}
|
||||
spi_onoff(1, 0);
|
||||
// turn off DMA
|
||||
DMA1_Channel2->CCR &= ~DMA_CCR_EN;
|
||||
}
|
||||
|
||||
void dma1_channel4_isr(){
|
||||
// turn off DMA
|
||||
DMA1_Channel4->CCR &= ~DMA_CCR_EN;
|
||||
if(DMA1->ISR & DMA_ISR_TEIF4){
|
||||
DMA1->IFCR = DMA_IFCR_CTEIF4;
|
||||
}
|
||||
@ -168,7 +174,5 @@ void dma1_channel4_isr(){
|
||||
freshdata[1] = 1;
|
||||
}
|
||||
spi_onoff(2, 0);
|
||||
// turn off DMA
|
||||
DMA1_Channel4->CCR &= ~DMA_CCR_EN;
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,5 @@ 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_start_enc(int encodernum);
|
||||
int spi_read_enc(uint8_t encno, uint8_t buf[8]);
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
#define BUILD_NUMBER "63"
|
||||
#define BUILD_DATE "2025-03-26"
|
||||
#define BUILD_NUMBER "73"
|
||||
#define BUILD_DATE "2025-03-27"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user