Skip to content

Commit

Permalink
Release xx.26.1 (bigtreetech#653)
Browse files Browse the repository at this point in the history
* fix smt32f2xx apb1/apb2 clk
* release-xx.26.1
  • Loading branch information
bigtreetech authored May 5, 2020
1 parent cc7bc10 commit 14d7b0c
Show file tree
Hide file tree
Showing 55 changed files with 162 additions and 134 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 6 additions & 5 deletions TFT/src/Libraries/cmsis/stm32f2xx/system_stm32f2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ static void SetSysClock(void)
/******************************************************************************/
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;

RCC->CR = 0x83; // restore "Reset value", reset the value be setted in bootloader
/* Enable HSE */
RCC->CR |= ((uint32_t)RCC_CR_HSEON);

Expand All @@ -367,14 +368,14 @@ static void SetSysClock(void)

if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK / 1*/
/* HCLK = SYSCLK / 1 AHB run in 120MHz */
RCC->CFGR |= RCC_CFGR_HPRE_DIV1;

/* PCLK2 = HCLK / 2*/
RCC->CFGR |= RCC_CFGR_PPRE2_DIV1;
/* PCLK2 = HCLK / 2 APB2 max 60MHz */
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;

/* PCLK1 = HCLK / 4*/
RCC->CFGR |= RCC_CFGR_PPRE1_DIV1;
/* PCLK1 = HCLK / 4 APB1 max 30MHz */
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;

/* Configure the main PLL */
RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Hal/STM32_USB_HOST_Library/Usr/src/usb_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE * pdev)
#endif // USB_OTG_HS
#endif // USE_STM322xG_EVAL

Delay_init(F_CPUM);
Delay_init();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/Hal/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void TIM3_Config(void)
TIM3->CR1 &= ~(0x01);
TIM3->DIER |= 1<<0;
TIM3->SR = (uint16_t)~(1<<0);
TIM3->ARR = F_CPUM - 1; // 20hz to 1Mhz
TIM3->ARR = mcuClocks.PCLK1_Timer_Frequency / 1000000 - 1; // 20hz to 1Mhz
}

void Buzzer_Config(void)
Expand Down
6 changes: 4 additions & 2 deletions TFT/src/User/Hal/stm32f10x/timer_pwm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "timer_pwm.h"
#include "includes.h"

typedef struct {
TIM_TypeDef* tim;
Expand Down Expand Up @@ -35,12 +36,13 @@ void TIM_PWM_Init(uint16_t tim_ch)
uint16_t timerIndex = TIMER_GET_TIM(tim_ch);
uint16_t channel = TIMER_GET_CH(tim_ch);
const TIMER* timer = &pwmTimer[timerIndex];
uint32_t timerTmpClk = (timer->rcc_src == &RCC->APB1ENR) ? mcuClocks.PCLK1_Timer_Frequency : mcuClocks.PCLK2_Timer_Frequency;

*timer->rcc_src |= (1 << timer->rcc_bit); // Enable timer clock

// Set PWM frequency to 10kHz
// Set PWM frequency to 500Hz
timer->tim->ARR = 100 - 1;
timer->tim->PSC = F_CPUM - 1;
timer->tim->PSC = timerTmpClk / (500 * 100) - 1;

switch (channel) {
case 0: timer->tim->CCMR1 |= (6<<4) | (1<<3); break; // CH1 PWM1 mode
Expand Down
6 changes: 4 additions & 2 deletions TFT/src/User/Hal/stm32f2xx/timer_pwm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "timer_pwm.h"
#include "includes.h"

typedef struct {
TIM_TypeDef* tim;
Expand Down Expand Up @@ -41,12 +42,13 @@ void TIM_PWM_Init(uint16_t tim_ch)
uint16_t timerIndex = TIMER_GET_TIM(tim_ch);
uint16_t channel = TIMER_GET_CH(tim_ch);
const TIMER* timer = &pwmTimer[timerIndex];
uint32_t timerTmpClk = (timer->rcc_src == &RCC->APB1ENR) ? mcuClocks.PCLK1_Timer_Frequency : mcuClocks.PCLK2_Timer_Frequency;

*timer->rcc_src |= (1 << timer->rcc_bit); // Enable timer clock

// Set PWM frequency to 10kHz
// Set PWM frequency to 500Hz
timer->tim->ARR = 100 - 1;
timer->tim->PSC = F_CPUM - 1;
timer->tim->PSC = timerTmpClk / (500 * 100) - 1;

switch (channel) {
case 0: timer->tim->CCMR1 |= (6<<4) | (1<<3); break; // CH1 PWM1 mode
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/Menu/FeatureSettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ void updateFeatureSettings(uint8_t key_val)

#ifdef LED_COLOR_PIN
case SKEY_KNOB:
infoSettings.knob_led_color = (infoSettings.knob_led_color + 1 ) % LED_color_NUM;
infoSettings.knob_led_color = (infoSettings.knob_led_color + 1 ) % LED_COLOR_NUM;
settingPage[item_index].valueLabel = itemLedcolor[infoSettings.knob_led_color];
featureSettingsItems.items[key_val] = settingPage[item_index];
ws2812_send_DAT(led_color[infoSettings.knob_led_color]);
WS2812_Send_DAT(led_color[infoSettings.knob_led_color]);

menuDrawListItem(&featureSettingsItems.items[key_val], key_val);
break;
Expand Down
25 changes: 25 additions & 0 deletions TFT/src/User/Menu/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ void setupMachine(void){
// Version infomation
void menuInfo(void)
{
char buf[128];
const GUI_POINT clocks[] = {{0 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{1 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{2 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{0 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
{1 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
{2 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},};
const char* hardware = "Board : BIGTREETECH_" HARDWARE_VERSION;
const char* firmware = "Firmware: "HARDWARE_VERSION"." STRINGIFY(SOFTWARE_VERSION) " " __DATE__;

Expand All @@ -76,6 +83,24 @@ void menuInfo(void)

GUI_Clear(BACKGROUND_COLOR);

my_sprintf(buf, "SYS:%dMhz", mcuClocks.rccClocks.SYSCLK_Frequency / 1000000);
GUI_DispString(clocks[0].x, clocks[0].y, (uint8_t *)buf);

my_sprintf(buf, "APB1:%dMhz", mcuClocks.rccClocks.PCLK1_Frequency / 1000000);
GUI_DispString(clocks[1].x, clocks[1].y, (uint8_t *)buf);

my_sprintf(buf, "P1Tim:%dMhz", mcuClocks.PCLK1_Timer_Frequency / 1000000);
GUI_DispString(clocks[2].x, clocks[2].y, (uint8_t *)buf);

my_sprintf(buf, "AHB:%dMhz", mcuClocks.rccClocks.HCLK_Frequency / 1000000);
GUI_DispString(clocks[3].x, clocks[3].y, (uint8_t *)buf);

my_sprintf(buf, "APB2:%dMhz", mcuClocks.rccClocks.PCLK2_Frequency / 1000000);
GUI_DispString(clocks[4].x, clocks[4].y, (uint8_t *)buf);

my_sprintf(buf, "P2Tim:%dMhz", mcuClocks.PCLK2_Timer_Frequency / 1000000);
GUI_DispString(clocks[5].x, clocks[5].y, (uint8_t *)buf);

GUI_DispString(startX, centerY - BYTE_HEIGHT, (u8 *)hardware);
GUI_DispString(startX, centerY, (u8 *)firmware);
GUI_DispStringInRect(20, LCD_HEIGHT - (BYTE_HEIGHT*2), LCD_WIDTH-20, LCD_HEIGHT, textSelect(LABEL_TOUCH_TO_EXIT));
Expand Down
136 changes: 62 additions & 74 deletions TFT/src/User/Menu/ledcolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,80 @@
#ifdef LED_COLOR_PIN

//preset color list
const LABEL itemLedcolor[LED_color_NUM] = {
//label
LABEL_OFF,
LABEL_WHITE,
LABEL_RED,
LABEL_ORANGE,
LABEL_YELLOW,
LABEL_GREEN,
LABEL_BLUE,
LABEL_INDIGO,
LABEL_VIOLET,
};
const LABEL itemLedcolor[LED_COLOR_NUM] = {
//label
LABEL_OFF,
LABEL_WHITE,
LABEL_RED,
LABEL_ORANGE,
LABEL_YELLOW,
LABEL_GREEN,
LABEL_BLUE,
LABEL_INDIGO,
LABEL_VIOLET,
};

const uint32_t led_color[LED_color_NUM] = {
LED_OFF,
LED_WHITE,
LED_RED,
LED_ORANGE,
LED_YELLOW,
LED_GREEN,
LED_BLUE,
LED_INDIGO,
LED_VIOLET
};
const uint32_t led_color[LED_COLOR_NUM] = {
LED_OFF,
LED_WHITE,
LED_RED,
LED_ORANGE,
LED_YELLOW,
LED_GREEN,
LED_BLUE,
LED_INDIGO,
LED_VIOLET
};

void knob_LED_Init(void) // 12 11
void knob_LED_Init(void)
{
uint16_t psc = _PSC;
uint16_t arr = _ARR;
GPIO_InitSet(LED_COLOR_PIN,MGPIO_MODE_OUT_PP,0);
GPIO_SetLevel(LED_COLOR_PIN,0);
//Turn on the clock
RCC->APB1ENR|=1<<4;//TIM6Clock enable
//Reset
RCC->APB1RSTR|=1<<4;
RCC->APB1RSTR&=~(1<<4);

TIM6->CNT=0;
TIM6->PSC=psc-1;
TIM6->ARR=arr;
//TIM6->CR1|=1<<0;//Enable timer 6

ws2812_send_DAT(led_color[infoSettings.knob_led_color]); //set last saved color after initialization
GPIO_InitSet(LED_COLOR_PIN, MGPIO_MODE_OUT_PP, 0);
GPIO_SetLevel(LED_COLOR_PIN, 0);

RCC->APB1ENR |= 1<<4; // TIM6 Clock enable
TIM6->CNT = 0;
TIM6->ARR = mcuClocks.PCLK1_Timer_Frequency / 800000 / 2 - 1; // 800KHz
TIM6->PSC = 1 - 1;
TIM6->SR = (uint16_t)~(1<<0);

WS2812_Send_DAT(led_color[infoSettings.knob_led_color]); //set last saved color after initialization
}

void knob_LED_DeInit(void)
{
GPIO_InitSet(LED_COLOR_PIN,MGPIO_MODE_IPN,0);
GPIO_InitSet(LED_COLOR_PIN,MGPIO_MODE_IPN,0);
}

void set_knob_color(int color_index){
ws2812_send_DAT(led_color[color_index]);
void set_knob_color(int color_index)
{
WS2812_Send_DAT(led_color[color_index]);
}

void ws2812_send_DAT(uint32_t ws2812_dat)
void WS2812_Send_DAT(uint32_t ws2812_dat)
{
u8 CNT;
u8 now_flag=0;
u8 led_color_num=0;
uint32_t old_ws2812_dat=ws2812_dat;
TIM6->CR1|=0x01;
while(!(TIM6->SR)){};
for(led_color_num=0;led_color_num<4;led_color_num++)
{ ws2812_dat=old_ws2812_dat;
for(CNT=0;CNT<24;CNT++)
{
TIM6->CNT=0; //1
TIM6->SR=0;
if(ws2812_dat & 0x800000){
TIM6->ARR=8;
now_flag=8;
}
else{
TIM6->ARR=3;
now_flag=3;
}
GPIO_SetLevel(LED_COLOR_PIN,1);
while(!(TIM6->SR)){};
TIM6->CNT=0;
TIM6->SR=0;
TIM6->ARR=11-now_flag;
GPIO_SetLevel(LED_COLOR_PIN,0);
while(!(TIM6->SR)){};
ws2812_dat<<=1;
}
uint16_t led_num;
int8_t bit;
uint16_t code_0_tim_h_cnt = TIM6->ARR * (0.4/1.25); // Code 0, High level hold time, 0.4us / 1.25us
uint16_t code_1_tim_h_cnt = TIM6->ARR - code_0_tim_h_cnt;

TIM6->CR1 |= 0x01;
for (led_num=0; led_num < NEOPIXEL_PIXELS; led_num++)
{
for (bit = 23; bit >= 0; bit--)
{
TIM6->CNT=0;
GPIO_SetLevel(LED_COLOR_PIN,1);
if (ws2812_dat & (1 << bit)) {
while (TIM6->CNT < code_1_tim_h_cnt);
} else {
while (TIM6->CNT < code_0_tim_h_cnt);
}

GPIO_SetLevel(LED_COLOR_PIN,0);
while (!TIM6->SR);
TIM6->SR = 0;
}
TIM6->CR1&=~(1<<0);
}
TIM6->CR1 &= ~0x01;
}
#endif
13 changes: 5 additions & 8 deletions TFT/src/User/Menu/ledcolor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _LEDCOLOR_H_
#define _LEDCPLOR_H_
#define _LEDCOLOR_H_

#include "variants.h"
#include "menu.h"
Expand Down Expand Up @@ -154,18 +154,15 @@

//preset color list
#ifdef LED_COLOR_PIN
#define _PSC 6 //presacler register
#define _ARR 5 //reload value of the timer counter
#define LED_COLOR_NUM 9

#define LED_color_NUM 9
extern const LABEL itemLedcolor[LED_COLOR_NUM];

extern const LABEL itemLedcolor[LED_color_NUM];

extern const uint32_t led_color[LED_color_NUM];
extern const uint32_t led_color[LED_COLOR_NUM];

void knob_LED_Init(void);
void knob_LED_DeInit(void);
void ws2812_send_DAT(uint32_t ws2812_dat);
void WS2812_Send_DAT(uint32_t ws2812_dat);
#endif

#endif
3 changes: 3 additions & 0 deletions TFT/src/User/Variants/pin_TFT35_E3_V3_0.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#endif

#define LED_COLOR_PIN PC7
#ifndef NEOPIXEL_PIXELS
#define NEOPIXEL_PIXELS 4
#endif

#include "pin_TFT35_V3_0.h"

Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/Variants/pin_TFT35_V3_0.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
//#define SD_SDIO_SUPPORT
#ifdef SD_SPI_SUPPORT
#define SD_LOW_SPEED 7 // 2^(SPEED+1) = 256 frequency division
#define SD_HIGH_SPEED 1 // 2 frequency division
#define SD_HIGH_SPEED 0 // 2 frequency division
#define SD_SPI _SPI1
#define SD_CS_PIN PA4
#endif
Expand All @@ -70,7 +70,7 @@
#define SD_CD_PIN PC4

// W25Qxx SPI pins
#define W25Qxx_SPEED 2 // stm32f103 spi1 max 4 division
#define W25Qxx_SPEED 0
#define W25Qxx_SPI _SPI3
#define W25Qxx_CS_PIN PB6

Expand Down
3 changes: 3 additions & 0 deletions TFT/src/User/Variants/pin_Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@
#endif

//#define LED_COLOR_PIN PC7
#ifndef NEOPIXEL_PIXELS
//#define NEOPIXEL_PIXELS 4
#endif

#endif
17 changes: 5 additions & 12 deletions TFT/src/User/delay.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "variants.h"
#include "includes.h"

static u16 fac_ms=0;
static u8 fac_us=0;

void Delay_init(u8 clk)
void Delay_init(void)
{
SysTick->CTRL&=0xfffffffb; //bit2 is cleared, select external clock HCLK / 8
fac_us=clk/8; //8Frequency after frequency division Unit M is 1us times
fac_ms=(u16)fac_us*1000; // The number of times in 1ms is 1000 times of 1us
SysTick->CTRL&=0xfffffffb; // bit2 is cleared, select external clock HCLK / 8
fac_us=mcuClocks.rccClocks.HCLK_Frequency/(8*1000000); // 8 Frequency after frequency division Unit M is 1us times
fac_ms=(u16)fac_us * 1000; // The number of times in 1ms is 1000 times of 1us
}

void Delay_us(u32 us) //Delay is less than 1800 * 1000us
Expand Down Expand Up @@ -37,10 +37,3 @@ void Delay_ms(u16 ms) //Delay is less than 1800ms
SysTick->CTRL=0x00;
SysTick->VAL=0x00;
}

void Delay(int time)
{
int i;
while(time--)
for(i=0;i<120;i++);
}
Loading

0 comments on commit 14d7b0c

Please sign in to comment.