Jelajahi Sumber

Fixes, improvements... Work.

Vladimir N. Shilov 3 tahun lalu
induk
melakukan
a9a1afeefb
9 mengubah file dengan 51 tambahan dan 239 penghapusan
  1. 0 105
      MNC-IN12x5.emProject
  2. 0 51
      MNC-IN12x5.emSession
  3. 6 1
      ReadMe.txt
  4. 13 49
      Src/board.c
  5. 1 1
      Src/clock.c
  6. 11 3
      Src/event-system.c
  7. 2 2
      Src/i2c.c
  8. 11 3
      Src/rtos.c
  9. 7 24
      Src/stm32g0xx_it.c

+ 0 - 105
MNC-IN12x5.emProject

@@ -1,105 +0,0 @@
-<!DOCTYPE CrossStudio_Project_File>
-<solution Name="MNC-IN12x5" target="8" version="2">
-  <configuration Name="Internal" hidden="Yes" />
-  <configuration Name="MNC-IN12x5" hidden="Yes" />
-  <configuration
-    Name="Debug"
-    inherited_configurations="Internal;MNC-IN12x5" />
-  <project Name="MNC-IN12x5">
-    <configuration
-      Name="Common"
-      arm_architecture="v6M"
-      arm_compiler_variant="SEGGER"
-      arm_core_type="Cortex-M0"
-      arm_endian="Little"
-      arm_fpu_type=""
-      arm_linker_variant="SEGGER"
-      arm_rtl_variant="SEGGER"
-      arm_simulator_memory_simulation_parameter="RX 08000000,00010000,FFFFFFFF;RWX 20000000,00002000,CDCDCDCD"
-      arm_target_device_name="STM32G030K8"
-      arm_target_interface_type="SWD"
-      debug_start_from_entry_point_symbol="No"
-      debug_target_connection="J-Link"
-      file_codec="UTF-8"
-      link_linker_script_file="$(StudioDir)/samples/SEGGER_Flash.icf"
-      linker_section_placements_segments="FLASH1 RX 0x08000000 0x00010000;RAM1 RWX 0x20000000 0x00002000"
-      project_directory=""
-      project_type="Executable" />
-    <configuration
-      Name="External Keil ARMCLANG"
-      asm_additional_options="--cpu=Cortex-M0+"
-      c_additional_options="-mcpu=Cortex-M0+;-O2;-g"
-      linker_additional_options="--cpu=Cortex-M0+" />
-    <configuration
-      LIBRARY_IO_TYPE="SEMIHOST (host-formatted)"
-      Name="Internal" />
-    <configuration
-      CMSIS_CORE="Yes"
-      Name="MNC-IN12x5"
-      arm_architecture="v6M"
-      arm_core_type="Cortex-M0"
-      arm_endian="Little"
-      arm_fpu_type=""
-      arm_simulator_memory_simulation_parameter="RX 08000000,00010000,FFFFFFFF;RWX 20000000,00002000,CDCDCDCD"
-      arm_target_device_name="STM32G030K8"
-      c_preprocessor_definitions="USE_FULL_LL_DRIVER;HSE_VALUE=8000000;HSE_STARTUP_TIMEOUT=100;LSE_STARTUP_TIMEOUT=5000;LSE_VALUE=32768;EXTERNAL_CLOCK_VALUE=12288000;HSI_VALUE=16000000;LSI_VALUE=32000;VDD_VALUE=3300;PREFETCH_ENABLE=0;INSTRUCTION_CACHE_ENABLE=1;DATA_CACHE_ENABLE=1;STM32G030xx"
-      c_user_include_directories="Inc;Drivers/STM32G0xx_HAL_Driver/Inc;Drivers/CMSIS/Device/ST/STM32G0xx/Include;Drivers/CMSIS/Include"
-      linker_section_placements_segments="FLASH1 RX 0x08000000 0x00010000;RAM1 RWX 0x20000000 0x00002000" />
-    <folder Name="::CMSIS" />
-    <folder Name="Application/MDK-ARM">
-      <file file_name="startup_stm32g030xx.s">
-        <configuration Name="Internal" build_exclude_from_build="Yes" />
-      </file>
-    </folder>
-    <folder Name="Application/User">
-      <file file_name="Src/bme280.c" />
-      <file file_name="Inc/bme280.h" />
-      <file file_name="Inc/bme280_defs.h" />
-      <file file_name="Src/board.c" />
-      <file file_name="Inc/board.h" />
-      <file file_name="Src/clock.c" />
-      <file file_name="Inc/clock.h" />
-      <file file_name="Src/ds3231.c" />
-      <file file_name="Inc/ds3231.h" />
-      <file file_name="Src/event-system.c" />
-      <file file_name="Inc/event-system.h" />
-      <file file_name="Inc/gpio.h" />
-      <file file_name="Src/i2c.c" />
-      <file file_name="Inc/i2c.h" />
-      <file file_name="Inc/list_event.h" />
-      <file file_name="Src/main.c" />
-      <file file_name="Inc/main.h" />
-      <file file_name="Src/rtos.c" />
-      <file file_name="Inc/rtos.h" />
-      <file file_name="Src/sensor.c" />
-      <file file_name="Inc/sensor.h" />
-      <file file_name="Inc/stm32_assert.h" />
-      <file file_name="Src/stm32g0xx_it.c" />
-      <file file_name="Inc/stm32g0xx_it.h" />
-    </folder>
-    <folder Name="Drivers/CMSIS">
-      <file file_name="Src/system_stm32g0xx.c" />
-    </folder>
-    <folder Name="Internal Files">
-      <file file_name="$(StudioDir)/samples/Cortex_M_Startup.s" />
-      <file file_name="$(StudioDir)/samples/SEGGER_THUMB_Startup.s" />
-    </folder>
-    <configuration
-      Name="Debug"
-      analyze_after_compile="Yes"
-      arm_architecture="v6M"
-      arm_assembler_variant="clang"
-      arm_compiler_variant="SEGGER-NG"
-      arm_core_type="Cortex-M0+"
-      arm_keep_assembly="No"
-      build_intermediate_directory="build/$(Configuration)/Obj/$(ProjectName)"
-      build_output_directory="build/$(Configuration)/Exe"
-      gcc_c_language_standard="gnu11"
-      gcc_cplusplus_language_standard="gnu++11"
-      gcc_enable_all_warnings="Yes"
-      gcc_optimization_level="Level 1"
-      link_time_optimization="Yes"
-      linker_output_format="hex" />
-  </project>
-  <configuration Name="Release" />
-</solution>

+ 0 - 51
MNC-IN12x5.emSession

@@ -1,51 +0,0 @@
-<!DOCTYPE CrossStudio_Session_File>
-<session>
- <Bookmarks/>
- <Breakpoints groups="Breakpoints" active_group="Breakpoints"/>
- <ExecutionProfileWindow/>
- <FrameBufferWindow>
-  <FrameBufferWindow bufferHeight="-1" addressSpace="" addressText="" bufferWidth="-1"/>
- </FrameBufferWindow>
- <Memory1/>
- <Memory2/>
- <Memory3/>
- <Memory4/>
- <Project>
-  <ProjectSessionItem path="MNC-IN12x5"/>
-  <ProjectSessionItem path="MNC-IN12x5;MNC-IN12x5"/>
-  <ProjectSessionItem path="MNC-IN12x5;MNC-IN12x5;Application/MDK-ARM"/>
-  <ProjectSessionItem path="MNC-IN12x5;MNC-IN12x5;Application/User"/>
-  <ProjectSessionItem path="MNC-IN12x5;MNC-IN12x5;Drivers/CMSIS"/>
-  <ProjectSessionItem path="MNC-IN12x5;MNC-IN12x5;Internal Files"/>
- </Project>
- <Register1/>
- <Register2/>
- <Register3/>
- <Register4/>
- <Threads>
-  <ThreadsWindow showLists=""/>
- </Threads>
- <TraceWindow>
-  <Trace enabled="Yes"/>
- </TraceWindow>
- <Watch1>
-  <Watches active="1" update="Never"/>
- </Watch1>
- <Watch2>
-  <Watches active="0" update="Never"/>
- </Watch2>
- <Watch3>
-  <Watches active="0" update="Never"/>
- </Watch3>
- <Watch4>
-  <Watches active="0" update="Never"/>
- </Watch4>
- <Files>
-  <SessionOpenFile windowGroup="DockEditLeft" x="0" y="22" useTextEdit="1" openedFrom="" useBinaryEdit="0" left="0" path="Src/sensor.c" selected="0" top="0" codecName="UTF-8"/>
-  <SessionOpenFile windowGroup="DockEditLeft" x="0" y="64" useTextEdit="1" openedFrom="" useBinaryEdit="0" left="0" path="Src/main.c" selected="0" top="54" codecName="UTF-8"/>
-  <SessionOpenFile windowGroup="DockEditLeft" x="16" y="163" useTextEdit="1" openedFrom="" useBinaryEdit="0" left="0" path="Inc/board.h" selected="0" top="125" codecName="UTF-8"/>
-  <SessionOpenFile windowGroup="DockEditLeft" x="0" y="127" useTextEdit="1" openedFrom="" useBinaryEdit="0" left="0" path="Src/board.c" selected="1" top="92" codecName="UTF-8"/>
-  <SessionOpenFile windowGroup="DockEditLeft" x="0" y="130" useTextEdit="1" openedFrom="" useBinaryEdit="0" left="0" path="Src/clock.c" selected="0" top="98" codecName="UTF-8"/>
- </Files>
- <ARMCrossStudioWindow activeProject="MNC-IN12x5" fileDialogDefaultFilter="*.c" autoConnectTarget="J-Link" buildConfiguration="Debug" sessionSettings="" debugSearchFileMap="" fileDialogInitialDirectory="" debugSearchPath="" autoConnectCapabilities="3199"/>
-</session>

+ 6 - 1
ReadMe.txt

@@ -86,4 +86,9 @@ C::B скорее всего придётся хоронить - "плюсов"
 
 Из пока не реализованного - "бликование" разрядами.
 Ничего не делал с ком-портом.
-Не придумалн ичего внятного по управлению/настройкам.
+Не придумал ничего внятного по управлению/настройкам.
+
+... бред... пришёл домой - всё работает.
+ан нет - работает только с уровнем оптимизации "s", 2 и 3 - нет.
+Ждём отладчик...
+Segger убрал, в хардфаулт падает только он.

+ 13 - 49
Src/board.c

@@ -113,7 +113,7 @@ void showDigits(tube4_t dig)
   if (old_dig == dig.u32) {
     _show_digits(dig);
   } else {
-    while (ov < 10) {
+    while (ov < 15) {
       if (st == 0) {
         // new tube value
         st = 1;
@@ -124,7 +124,7 @@ void showDigits(tube4_t dig)
         // old tube value
         st = 0;
         _show_digits((tube4_t)old_dig);
-        tdelay_ms(10 - ov);
+        tdelay_ms(15 - ov);
       }
     } // End of while
     old_dig = dig.u32;
@@ -151,7 +151,7 @@ static void _show_digits(tube4_t dig)
   }
 
   /* Wait for SPI */
-  while (Flag.SPI_TX_End == 0) {};
+  while (Flag.SPI_TX_End == 0);
   Flag.SPI_TX_End = 0;
 
   /* Feel buffer */
@@ -172,28 +172,6 @@ static void _show_digits(tube4_t dig)
       tube_PowerOn((tube_pos_t)i);
     }
   }
-/*
-  if (dig.s8.tA == 0xf) {
-    TUBE_A_OFF;
-  } else {
-    TUBE_A_ON;
-  }
-  if (dig.s8.tB == 0xf) {
-    TUBE_B_OFF;
-  } else {
-    TUBE_B_ON;
-  }
-  if (dig.s8.tD == 0xf) {
-    TUBE_D_OFF;
-    } else {
-    TUBE_D_ON;
-  }
-  if (dig.s8.tE == 0xf) {
-    TUBE_E_OFF;
-  } else {
-    TUBE_E_ON;
-  }
-*/
 }
 
 /**
@@ -302,33 +280,19 @@ void SystemClock_Config(void)
 {
   /* HSI configuration and activation */
   RCC->CR |= RCC_CR_HSION; // Enable HSI
-  while((RCC->CR & RCC_CR_HSIRDY) == 0)
-  {
-  }
+  while((RCC->CR & RCC_CR_HSIRDY) == 0);
 
   /* Main PLL configuration and activation */
   //RCC->PLLCFGR &= ~(RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM | RCC_PLLCFGR_PLLN | RCC_PLLCFGR_PLLR);
   RCC->PLLCFGR = (RCC_PLLCFGR_PLLSRC_HSI | RCC_PLLCFGR_PLLM_0 | (9 << RCC_PLLCFGR_PLLN_Pos) | RCC_PLLCFGR_PLLR_1);
   RCC->PLLCFGR |= RCC_PLLCFGR_PLLREN; // RCC_PLL_EnableDomain_SYS
   RCC->CR |= RCC_CR_PLLON; // RCC_PLL_Enable
-  while((RCC->CR & RCC_CR_PLLRDY) == 0)
-  {
-  }
-
-  /* Set AHB prescaler*/
-  //RCC->CFGR &= ~(RCC_CFGR_HPRE);
-  //RCC->CFGR |= 0x00000000U;
+  while((RCC->CR & RCC_CR_PLLRDY) == 0);
 
   /* Sysclk activation on the main PLL */
   RCC->CFGR &= RCC_CFGR_SW;
   RCC->CFGR |= RCC_CFGR_SW_1;
-  while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1)
-  {
-  }
-
-  /* Set APB1 prescaler !!! uncorrect !!! */
-  //RCC->CFGR &= RCC_CFGR_PPRE;
-  //RCC->CFGR |= 0x00000000U;
+  while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_1);
 
   /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
   SystemCoreClock = 24000000;
@@ -534,10 +498,10 @@ static void TIM1_Init(void)
 
 
   /** TIM1 GPIO Configuration
-		PA8 ------> TIM1_CH1
-		PA9 ------> TIM1_CH2
-		PA10 ------> TIM1_CH3
-		PA11 [PA9] ------> TIM1_CH4
+    PA8 ------> TIM1_CH1
+    PA9 ------> TIM1_CH2
+    PA10 ------> TIM1_CH3
+    PA11 [PA9] ------> TIM1_CH4
   */
   GPIO_SetPinMode(PWM_1_GPIO_Port, PWM_1_Pin, GPIO_MODE_AFF);
   GPIO_SetPinSpeed(PWM_1_GPIO_Port, PWM_1_Pin, GPIO_OSPEED_HI);
@@ -654,10 +618,10 @@ static void TIM14_Init(void)
  */
 void Blink_Start(void)
 {
-	/* enable all channels */
-	TUBE_ALL_ON;
+  /* enable all channels */
+  TUBE_ALL_ON;
 
-	/* clear IRQ flag */
+  /* clear IRQ flag */
   TIM14->SR |= TIM_SR_CC1IF;
 
   /* clear counter value */

+ 1 - 1
Src/clock.c

@@ -277,7 +277,7 @@ void showPressure(void) {
 void showSensorData(void) {
   ES_SetState(stShowSensorData);
   RTOS_DeleteTask(MinusFadeOut);
-  HSV2LED(4, 255, cie[Lvl_Mdl]); // Nixie color
+  HSV2LED(1, 255, cie[Lvl_Mdl]); // Nixie color
 
   showTemperature();
   tdelay_ms(3000);

+ 11 - 3
Src/event-system.c

@@ -152,9 +152,17 @@ void ES_PlaceEvent(es_event_t event)
     countBuf ++;
     /* сигнализация переполнения буфера событий */
   } else {
-      TIM1->CCR2 = 0x0;
-      TIM1->CCR3 = 0x0;
-      TIM1->CCR4 = 0xff;
+      // tube power off
+      TIM1->CCER &= ~(TIM_CCER_CC1E);
+      TIM3->CCER &= ~(TIM_CCER_CC4E);
+      TIM3->CCER &= ~(TIM_CCER_CC3E);
+      TIM3->CCER &= ~(TIM_CCER_CC2E);
+      TIM3->CCER &= ~(TIM_CCER_CC1E);
+      GPIOA->BSRR = 0x10;
+      // color - pink
+      TIM1->CCR2 = 0xff;
+      TIM1->CCR3 = 0x14;
+      TIM1->CCR4 = 0x93;
       while(1);
   }
 }

+ 2 - 2
Src/i2c.c

@@ -18,7 +18,7 @@ int8_t i2c_check_err(void) {
   if (r != I2C_RET_OK) {
   /* restart I2C and clear flags */
     I2C1->CR1 &= ~I2C_CR1_PE;
-    while ((I2C1->CR1 & I2C_CR1_PE) != 0) {};
+    while ((I2C1->CR1 & I2C_CR1_PE) != 0);
     I2C1->CR1 |= I2C_CR1_PE;
   }
 
@@ -100,7 +100,7 @@ int8_t user_i2c_write(const uint8_t id, const uint8_t reg_addr, uint8_t *data, c
   DMA1_Channel3->CPAR = (uint32_t)&(I2C1->TXDR);
   DMA1_Channel3->CNDTR = len;
 
-  while ( I2C1->ISR & I2C_ISR_BUSY ) {};
+  while ( I2C1->ISR & I2C_ISR_BUSY );
 
   I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
   I2C1->CR2 |= ( id | (len + 1) << I2C_CR2_NBYTES_Pos );

+ 11 - 3
Src/rtos.c

@@ -66,9 +66,17 @@ void RTOS_SetTask (void (*taskFunc)(void), uint32_t taskDelay, uint32_t taskPeri
       __enable_irq();
    } else {
      //!!! no left space for new task :-(
-    TIM1->CCR2 = 0xff;
-    TIM1->CCR3 = 0x0;
-    TIM1->CCR4 = 0x0;
+     // tube power off
+     TIM1->CCER &= ~(TIM_CCER_CC1E);
+     TIM3->CCER &= ~(TIM_CCER_CC4E);
+     TIM3->CCER &= ~(TIM_CCER_CC3E);
+     TIM3->CCER &= ~(TIM_CCER_CC2E);
+     TIM3->CCER &= ~(TIM_CCER_CC1E);
+     GPIOA->BSRR = 0x10;
+     // color - orange
+     TIM1->CCR2 = 0xff;
+     TIM1->CCR3 = 0x7f;
+     TIM1->CCR4 = 0x0;
      while (1);
    }
 }

+ 7 - 24
Src/stm32g0xx_it.c

@@ -48,31 +48,14 @@ void NMI_Handler(void)
 void HardFault_Handler(void)
 {
   // tube power off
+  TIM1->CCER &= ~(TIM_CCER_CC1E);
+  TIM3->CCER &= ~(TIM_CCER_CC4E);
+  TIM3->CCER &= ~(TIM_CCER_CC3E);
+  TIM3->CCER &= ~(TIM_CCER_CC2E);
+  TIM3->CCER &= ~(TIM_CCER_CC1E);
   GPIOA->BSRR = 0x10;
   // red led
   TIM1->CCR2 = 0xff; TIM1->CCR3 = 0; TIM1->CCR4 = 0;
-
-  /* https://habr.com/ru/post/511924/ */
-  struct 
-  {
-    uint32_t r0;
-    uint32_t r1;
-    uint32_t r2;
-    uint32_t r3;
-    uint32_t r12;
-    uint32_t lr;
-    uint32_t pc;
-    uint32_t psr;
-  } * stack_ptr; //Указатель на текущее значение стека(SP)
-
-  asm (
-      "TST lr, #4 \n" //Тестируем 3-й бит указателя стека (побитовое И)
-      "ITE EQ \n"   //Значение указателя стека имеет бит 3?
-      "MRSEQ %[ptr], MSP  \n"  //Да, сохраняем основной указатель стека
-      "MRSNE %[ptr], PSP  \n"  //Нет, сохраняем указатель стека процесса
-      : [ptr] "=r" (stack_ptr)
-  );
-  // there plase break-point...
   while (1)
   {
   }
@@ -128,8 +111,8 @@ void DMA1_Channel1_IRQHandler(void)
 
     /* Wait for end SPI transmit */
     LATCH_DOWN;
-    while ((SPI1->SR & SPI_SR_FTLVL) != 0) {};
-    while ((SPI1->SR & SPI_SR_BSY) != 0) {};
+    while ((SPI1->SR & SPI_SR_FTLVL) != 0);
+    while ((SPI1->SR & SPI_SR_BSY) != 0);
     LATCH_UP;
   }
 }