change some files for stm32f030x6 series on STM32GENERIC

Discussions about the STM32generic core
Post Reply
csnol
Posts: 15
Joined: Thu Aug 24, 2017 12:57 pm

change some files for stm32f030x6 series on STM32GENERIC

Post by csnol » Sun Sep 10, 2017 1:58 pm

Hi, Daniel.

I don't know why I can't Pull request on Github for STM32GENERIC.
So I've to show here.
--------------------------
For weeks test : PWM/ I2C/ ADC/ UART/ I/O/ Interrupt...
running well with NRF24L01, MPU6050, LCD5110, DHT11, ESP8266...

Some functions updated for stm32F030x6 (tested on F030F4 and F030K6)

Update 1: STM32/cores/arduino/stm32/stm32_PWM.c

No "HAL_RCC_GetPCLK2Freq()" in stm32f030x6 library. HAL_RCC_GetPCLK1Freq() used.

Code: Select all

  
  
              pwm_config[i].port = variant_pin_list[pin].port;
              pwm_config[i].pin_mask = variant_pin_list[pin].pin_mask;
 +            #if defined(STM32F030x6)   // added by CSNOL
 +            pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK1Freq() / frequency;   // added
 +            #else   // added
              pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK2Freq() / frequency;
 +            #endif   // added
              pwm_config[i].dutyCycle = (uint64_t)pwm_config[i].waveLengthCycles * dutyCycle >> 16;
 -
              if (durationMillis > 0) {
 +            #if defined(STM32F030x6)   // added by CSNOL
 +                pwm_config[i].counterCycles = HAL_RCC_GetPCLK1Freq() / 1000 * durationMillis;   // added
 +            #else   // added
                  pwm_config[i].counterCycles = HAL_RCC_GetPCLK2Freq() / 1000 * durationMillis;
 +            #endif   // added
              }
  
              break;
 @@ -135,8 +142,11 @@ void stm32ScheduleMicros(uint32_t microseconds, void (*callback)()) {
          if (pwm_config[i].port == NULL && pwm_config[i].callback == NULL) {
  
              pwm_config[i].callback = callback;
 -
 +            #if defined(STM32F030x6)								// added by CSNOL
 +            pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK1Freq() * (uint64_t)microseconds / 1000000;     // added
 +            #else   // added
              pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK2Freq() * (uint64_t)microseconds / 1000000;
 +            #endif  // added
              pwm_config[i].counterCycles = pwm_config[i].waveLengthCycles;
              break;
          }  
Update 2: STM32/libraries/stm32_dma/src/stm32_dma.c
bypass some DMAx_IRQn for STM32F030x6

Code: Select all

-
 +#if !defined(STM32F030x6)       //bypass for STM32F030x6  added by CSNOL
  // F0
  extern void DMA1_Ch1_IRQHandler() {
      HAL_DMA_IRQHandler(dmaHandles[1]);
  }
  
  // F0
 +
  extern void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler() {
      HAL_DMA_IRQHandler(dmaHandles[2]);
      HAL_DMA_IRQHandler(dmaHandles[3]);
 @@ -203,16 +204,6 @@ extern void DMA1_Channel2_3_IRQHandler() {
      HAL_DMA_IRQHandler(dmaHandles[3]);
  }
  
 -// F1, F3, L1, L4
 //-extern void DMA1_Channel2_IRQHandler() {
 //-    HAL_DMA_IRQHandler(dmaHandles[2]);
 //-}
 //-
 //- F1, F3, L1, L4
 //-extern void DMA1_Channel3_IRQHandler() {
 //-    HAL_DMA_IRQHandler(dmaHandles[3]);
 //-}
 //-
  // F0, L0
  extern void DMA1_Channel4_5_6_7_IRQHandler() {
      HAL_DMA_IRQHandler(dmaHandles[4]);
 @@ -227,6 +218,19 @@ extern void DMA1_Channel4_5_IRQHandler() {
      HAL_DMA_IRQHandler(dmaHandles[5]);
  }
  
 +#endif
 +// F1, F3, L1, L4
 +extern void DMA1_Channel2_IRQHandler() {
 +    HAL_DMA_IRQHandler(dmaHandles[2]);
 +}
 +
 +// F1, F3, L1, L4
 +extern void DMA1_Channel3_IRQHandler() {
 +    HAL_DMA_IRQHandler(dmaHandles[3]);
 +}
 +
 +
 +
  // F1, F3, L1, L4
  extern void DMA1_Channel4_IRQHandler() {
      HAL_DMA_IRQHandler(dmaHandles[4]);
      
Update 3: STM32/libraries/stm32_dma/src/stm32_dma_F0F1F3L1.h
Change DMAx_IRQn for STM32F030x6 SPI1

Code: Select all

 } dma_request_to_instance_t;
  
  const dma_request_to_instance_t dmaRequestToStream[] = {
 -
 +#if defined(STM32F030x6)    //added by CSNOL
 +    {SPI1, SPI_TX, DMA1_Channel3, 3, DMA1_Channel2_3_IRQn},
 +    {SPI1, SPI_RX, DMA1_Channel2, 2, DMA1_Channel2_3_IRQn},
 +    #else
      {SPI1, SPI_TX, DMA1_Channel3, 3, DMA1_Channel3_IRQn},
      {SPI1, SPI_RX, DMA1_Channel2, 2, DMA1_Channel2_IRQn},
 -
 +    #endif
 +#if !defined(STM32F030x6)    //bypass for STM32F030x6   added by CSNOL
  #ifdef SPI2
      {SPI2, SPI_TX, DMA1_Channel5, 5, DMA1_Channel5_IRQn},
      {SPI2, SPI_RX, DMA1_Channel4, 4, DMA1_Channel4_IRQn},
 @@ -33,7 +37,7 @@ const dma_request_to_instance_t dmaRequestToStream[] = {
  #if defined(SDIO) && defined(SD_InitTypeDef)
      {SDIO, SDIO_RXTX, DMA2_Channel4, 4 + 8, DMA2_Channel4_IRQn},
  #endif
 -
 +#endif
  };
  
  inline static void setDmaInstance(DMA_HandleTypeDef *handle, dma_request_to_instance_t dmaRequestToStream) {
Update 4: STM32/system/STM32F0/CMSIS_Inc/stm32f030x6.h
#define I2C1_EV_IRQn I2C1_IRQn for stm32f030x6 I2C function.

Code: Select all

 #define DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler DMA1_Channel2_3_IRQHandler
  #define DMA1_Channel4_5_6_7_IRQHandler   DMA1_Channel4_5_IRQHandler
  #define DMA1_Ch4_7_DMA2_Ch3_5_IRQHandler DMA1_Channel4_5_IRQHandler
 +#define I2C1_EV_IRQn					 I2C1_IRQn        // New - added by CSNOL
  #define RCC_CRS_IRQHandler               RCC_IRQHandler
Last edited by csnol on Mon Sep 11, 2017 12:00 pm, edited 1 time in total.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: change some files for stm32f030x6 serials on STM32GENERIC

Post by danieleff » Mon Sep 11, 2017 9:04 am

The #if defined(STM32F030x6) is way too narrow.
There are 600+ STM32 chips, the conditionals need to be broader, usable for whole series (STM32F0), or check by features for example: #ifdef DMA1_Channel2_3_IRQn #define DMA1_Channel2_IRQn DMA1_Channel2_3_IRQn

That way other chips can benefit too.

csnol
Posts: 15
Joined: Thu Aug 24, 2017 12:57 pm

Re: change some files for stm32f030x6 serials on STM32GENERIC

Post by csnol » Mon Sep 11, 2017 11:10 am

Oh I see. but It's difficult for me. I almost don't use other STM32 chips more than 32 pins. I can't test other STM32F0 chips.
No tested, No truth. you know.
on the other hand, I just added F030F4 as a extension of ESP8285/66 in our Arduino Interest Group. I'm still a beginner now.
So there's nothing I can do about other F0 chips. :oops:
Thanks for your reminder.

csnol
Posts: 15
Joined: Thu Aug 24, 2017 12:57 pm

Re: change some files for stm32f030x6 serials on STM32GENERIC

Post by csnol » Mon Sep 11, 2017 11:42 am

Update 1: STM32/cores/arduino/stm32/stm32_PWM.c
No "HAL_RCC_GetPCLK2Freq()" in all stm32f0 series library. HAL_RCC_GetPCLK1Freq() used.

Code: Select all


             pwm_config[i].port = variant_pin_list[pin].port;
              pwm_config[i].pin_mask = variant_pin_list[pin].pin_mask;
 +            #if defined(STM32F0)                              // added by CSNOL
 +            pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK1Freq() / frequency;   // added
 +            #else   // added
              pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK2Freq() / frequency;
 +            #endif   // added
              pwm_config[i].dutyCycle = (uint64_t)pwm_config[i].waveLengthCycles * dutyCycle >> 16;
 -
              if (durationMillis > 0) {
 +            #if defined(STM32F0)                             // added by CSNOL
 +                pwm_config[i].counterCycles = HAL_RCC_GetPCLK1Freq() / 1000 * durationMillis;   // added
 +            #else   // added
                  pwm_config[i].counterCycles = HAL_RCC_GetPCLK2Freq() / 1000 * durationMillis;
 +            #endif   // added
              }
  
              break;
 @@ -135,8 +142,11 @@ void stm32ScheduleMicros(uint32_t microseconds, void (*callback)()) {
          if (pwm_config[i].port == NULL && pwm_config[i].callback == NULL) {
  
              pwm_config[i].callback = callback;
 -
 +            #if defined(STM32F0) 								// added by CSNOL
 +            pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK1Freq() * (uint64_t)microseconds / 1000000;     // added
 +            #else   // added
              pwm_config[i].waveLengthCycles = HAL_RCC_GetPCLK2Freq() * (uint64_t)microseconds / 1000000;
 +            #endif  // added
              pwm_config[i].counterCycles = pwm_config[i].waveLengthCycles;
              break;
          }  
2 and 3
don't change anymore
Maybe can directly use STM32GENERIC/STM32/libraries/stm32_dma/src/stm32_dma_L0.h
rename stm32_dma_L0.h to stm32_dma_F0L0.h
and rename stm32_dma_F0F1F3L1.h to stm32_dma_F1F3L1.h

Update 4: STM32/system/STM32F0/CMSIS_Inc/stm32f030x6.h
I don't know why "I2C1_EV_IRQn" be used in STM32/libraries/Wire/src/Wire.cpp

Code: Select all

        __HAL_RCC_I2C1_CLK_ENABLE();
73	        HAL_NVIC_SetPriority(I2C1_EV_IRQn, 1, 0);
74	        HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
75	    }
76	    #endif
I don't have to redefine it in stm32f030x6.h if use "I2C1_IRQn"
#define I2C1_EV_IRQn I2C1_IRQn //for stm32f030x6 I2C function.

Attention: these codes I still don't test on my boards.

OK, That's all I can do.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests