Skip to content

Commit 8af14f5

Browse files
tridgeclaude
authored andcommitted
v203: reduce flash usage by 540 bytes
Replace HAL functions with direct register access to avoid pulling in large library functions: - TIM_TimeBaseInit/TIM_TimeBaseStructInit replaced with direct writes - GPIO_Init/GPIO_StructInit replaced with existing gpio_mode_set_input - RCC_APB2PeriphClockCmd replaced with direct register write This reduces flash usage from 99.8% to 86.6%, providing ~550 bytes of headroom for future development. 🤖 Generated with [Claude Code](https://claude.ai/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 62c82ae commit 8af14f5

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

Mcu/v203/Inc/blutil.h

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,15 @@ static inline void bl_timer_init(void)
9595
{
9696
RCC->APB1PCENR |= RCC_APB1Periph_TIM2;
9797

98-
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
99-
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
100-
TIM_TimeBaseStructure.TIM_Prescaler = 143;
101-
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
102-
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
103-
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
104-
TIM_TimeBaseInit(BL_TIMER, &TIM_TimeBaseStructure);
105-
TIM_SetCounter(BL_TIMER, 0);
106-
107-
// enable preload
108-
BL_TIMER->CTLR1 |= TIM_ARPE;
109-
110-
// enable timer
111-
BL_TIMER->CTLR1 |= TIM_CEN;
98+
// direct register access to avoid pulling in TIM_TimeBaseInit (saves ~150 bytes)
99+
BL_TIMER->PSC = 143; // prescaler for 1us at 144MHz
100+
BL_TIMER->ATRLR = 0xFFFF; // period
101+
BL_TIMER->CTLR1 = 0; // up counter, no clock division
102+
BL_TIMER->CNT = 0; // reset counter
103+
BL_TIMER->SWEVGR = TIM_PSCReloadMode_Immediate;
104+
105+
// enable preload and timer
106+
BL_TIMER->CTLR1 |= TIM_ARPE | TIM_CEN;
112107
}
113108

114109
/*
@@ -134,15 +129,11 @@ static inline void bl_clock_config(void)
134129

135130
static inline void bl_gpio_init(void)
136131
{
137-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE );
138-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE );
139-
140-
GPIO_InitTypeDef GPIO_InitStruct = {0};
141-
GPIO_StructInit(&GPIO_InitStruct);
142-
GPIO_InitStruct.GPIO_Pin = input_pin;
143-
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
144-
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
145-
GPIO_Init(input_port, &GPIO_InitStruct);
132+
// enable GPIO clocks via direct register access (avoids RCC_APB2PeriphClockCmd)
133+
RCC->APB2PCENR |= RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB;
134+
135+
// use our own gpio_mode_set_input instead of GPIO_Init (saves ~250 bytes)
136+
gpio_mode_set_input(input_pin, GPIO_PULL_NONE);
146137
}
147138

148139
/*

0 commit comments

Comments
 (0)