Explorar el Código

Enable SPI/DMA data transfer.

Vladimir N. Shilov hace 4 años
padre
commit
59b3f22310
Se han modificado 3 ficheros con 28 adiciones y 18 borrados
  1. 6 6
      Inc/main.h
  2. 16 11
      Src/main.c
  3. 6 1
      Src/stm32g0xx_it.c

+ 6 - 6
Inc/main.h

@@ -76,8 +76,8 @@ typedef enum {
 #define LATCH_DOWN    GPIOB->BRR = 0x10
 #define LATCH_UP      GPIOB->BSRR = 0x10
 
-#define SHDN_OFF      GPIOA->BRR = 0x10
-#define SHDN_ON       GPIOA->BSRR = 0x10
+#define TUBE_PWR_ON   GPIOA->BRR = 0x10
+#define TUBE_PWR_OFF  GPIOA->BSRR = 0x10
 
 #define IN15_P        GPIOA->BSRR = 0x1
 #define IN15_Plus     GPIOA->BSRR = 0x2
@@ -85,10 +85,10 @@ typedef enum {
 #define IN15_Percent  GPIOA->BSRR = 0x8
 #define IN15_OFF      GPIOA->BRR = 0xF
 
-#define COLOR_R(x)    TIM3->CCR1 = x
-#define COLOR_B(x)    TIM3->CCR2 = x
-#define COLOR_G(x)    TIM3->CCR3 = x
-#define COLOR_RGB(r, g, b)    TIM3->CCR1 = r; TIM3->CCR3 = g; TIM3->CCR2 = b
+#define COLOR_R(x)          TIM3->CCR1 = x
+#define COLOR_B(x)          TIM3->CCR2 = x
+#define COLOR_G(x)          TIM3->CCR3 = x
+#define COLOR_RGB(r, g, b)  TIM3->CCR1 = r; TIM3->CCR3 = g; TIM3->CCR2 = b
 
 /* USER CODE END EM */
 

+ 16 - 11
Src/main.c

@@ -136,39 +136,44 @@ int main(void)
   //LL_Init1msTick(rcc_clocks.HCLK_Frequency);
   //LL_mDelay(1);
 
-  /* Start Timers */
+  /* Start RGB PWM */
   LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1);
   LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH2);
   LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH3);
   LL_TIM_EnableCounter(TIM3);
+
+  /* Start Tube PWR PWM */
   LL_TIM_CC_EnableChannel(TIM14, LL_TIM_CHANNEL_CH1);
   LL_TIM_EnableCounter(TIM14);
 
   /* Enable tube power */
-  SHDN_OFF;
+  TUBE_PWR_ON;
 
   // manual dma start sample
   /* Set DMA transfer addresses of source and destination */
-//  LL_DMA_ConfigAddresses(DMA1,
-//                         LL_DMA_CHANNEL_1,
-//                         (uint32_t)&nixieTubes,
-//                         (uint32_t)&aDST_Buffer,
-//                         LL_DMA_DIRECTION_MEMORY_TO_MEMORY);
+  LL_DMA_ConfigAddresses(DMA1,
+                         LL_DMA_CHANNEL_1,
+                         (uint32_t)&nixieTubes,
+                         (uint32_t)&(SPI1->DR),
+                         LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
 
   /* Set DMA transfer size */
   LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, SPI_BUFFER_SIZE);
 
   /* Enable DMA transfer complete/error interrupts */
-//  LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
-//  LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
+  LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
+  LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
 
   showDigit(Tube_A, 1);
   showDigit(Tube_B, 2);
   showDigit(Tube_D, 3);
   showDigit(Tube_E, 4);
 
-  /* Start the DMA transfer Flash to Memory */
+  /* Start the DMA transfer from Memory to SPI1 */
   LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
+  /* Start SPI */
+  LL_SPI_EnableDMAReq_TX(SPI1);
+  LL_SPI_Enable(SPI1);
 
 //  COLOR_R(0);
 //  COLOR_G(0);
@@ -409,7 +414,7 @@ static void MX_SPI1_Init(void)
   NVIC_EnableIRQ(SPI1_IRQn);
 
   /* USER CODE BEGIN SPI1_Init 1 */
-  LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, SPI_BUFFER_SIZE);
+
   /* USER CODE END SPI1_Init 1 */
   /* SPI1 parameter configuration*/
   SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;

+ 6 - 1
Src/stm32g0xx_it.c

@@ -181,7 +181,12 @@ void EXTI4_15_IRQHandler(void)
 void DMA1_Channel1_IRQHandler(void)
 {
   /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
-
+  if (LL_DMA_IsActiveFlag_TC1(DMA1) != 0) {
+    /* Stop SPI-DMA transfer */
+    LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
+//    LL_SPI_DisableDMAReq_TX(SPI1);
+//    LL_SPI_Disable(SPI1);
+  }
   /* USER CODE END DMA1_Channel1_IRQn 0 */
 
   /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */