Skip to content

Commit bff8bbb

Browse files
authored
Flasher update (#265)
1 parent 3463853 commit bff8bbb

File tree

12 files changed

+176
-240
lines changed

12 files changed

+176
-240
lines changed

firmware/mgmt/Core/Src/main.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ static void MX_GPIO_Init(void)
357357
__HAL_RCC_GPIOB_CLK_ENABLE();
358358

359359
/*Configure GPIO pin Output Level */
360-
HAL_GPIO_WritePin(GPIOA, NET_STAT_Pin|LEDA_R_Pin|LEDA_G_Pin|LEDA_B_Pin, GPIO_PIN_RESET);
360+
HAL_GPIO_WritePin(GPIOA, NET_STAT_Pin|LEDA_R_Pin|LEDA_G_Pin|LEDA_B_Pin
361+
|UI_BOOT0_Pin, GPIO_PIN_RESET);
361362

362363
/*Configure GPIO pin Output Level */
363364
HAL_GPIO_WritePin(GPIOB, LEDB_R_Pin|LEDB_G_Pin|LEDB_B_Pin|UI_NRST_Pin
@@ -376,8 +377,8 @@ static void MX_GPIO_Init(void)
376377
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
377378
HAL_GPIO_Init(NET_STAT_GPIO_Port, &GPIO_InitStruct);
378379

379-
/*Configure GPIO pins : LEDA_R_Pin LEDA_G_Pin LEDA_B_Pin */
380-
GPIO_InitStruct.Pin = LEDA_R_Pin|LEDA_G_Pin|LEDA_B_Pin;
380+
/*Configure GPIO pins : LEDA_R_Pin LEDA_G_Pin LEDA_B_Pin UI_BOOT0_Pin */
381+
GPIO_InitStruct.Pin = LEDA_R_Pin|LEDA_G_Pin|LEDA_B_Pin|UI_BOOT0_Pin;
381382
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
382383
GPIO_InitStruct.Pull = GPIO_NOPULL;
383384
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
@@ -406,12 +407,6 @@ static void MX_GPIO_Init(void)
406407
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
407408
HAL_GPIO_Init(MCLK_GPIO_Port, &GPIO_InitStruct);
408409

409-
/*Configure GPIO pin : UI_BOOT0_Pin */
410-
GPIO_InitStruct.Pin = UI_BOOT0_Pin;
411-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
412-
GPIO_InitStruct.Pull = GPIO_NOPULL;
413-
HAL_GPIO_Init(UI_BOOT0_GPIO_Port, &GPIO_InitStruct);
414-
415410
/* EXTI interrupt init*/
416411
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
417412
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

firmware/mgmt/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################################################################
2-
# File automatically-generated by tool: [projectgenerator] version: [4.6.0.1-B1] date: [Tue Jun 10 14:13:27 MDT 2025]
2+
# File automatically-generated by tool: [projectgenerator] version: [4.6.0.1-B1] date: [Wed Jun 11 13:40:33 MDT 2025]
33
##########################################################################################################################
44

55
# ------------------------------------------------
@@ -24,7 +24,7 @@ FIRMWARE = ${TARGET}.elf
2424
# building variables
2525
######################################
2626
# debug build?
27-
DEBUG = 1
27+
DEBUG = 0
2828
# optimization
2929

3030
OPT = -Os
@@ -36,7 +36,7 @@ endif
3636
# programming
3737
#######################################
3838
PORT =
39-
BAUD = 115000
39+
BAUD = 115200
4040
WRITE_START = 0x08000000
4141
PROGRAMMER = CUBE
4242
CUBE_PROGRAMMER_SWD_ARGS = -c port=swd freq=2400 mode=Normal ap=0 speed=Reliable -w ${BUILD_DIR}/${FIRMWARE} ${WRITE_START} -v -g

firmware/mgmt/inc/app_mgmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void NetUpload();
4848
void UIUpload();
4949
void RunningMode();
5050
void DebugMode();
51-
void NormalBoot();
51+
void NormalInit();
5252

5353
void CheckTimeout();
5454
void WaitForNetReady(const enum State* state);

firmware/mgmt/mgmt.ioc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ PA14.Signal=SYS_SWCLK
146146
PA15.GPIOParameters=GPIO_Label
147147
PA15.GPIO_Label=UI_BOOT0
148148
PA15.Locked=true
149-
PA15.Signal=GPIO_Input
149+
PA15.Signal=GPIO_Output
150150
PA2.GPIOParameters=GPIO_Label
151151
PA2.GPIO_Label=UI_RX1_MGMT
152152
PA2.Locked=true

firmware/mgmt/src/app_mgmt.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef* huart, uint16_t rx_idx)
151151

152152
// Need to have as separate if statements so we can loop back properly
153153
// Which doesn't make any sense to me, but it makes it work.
154-
155-
// HAL_GPIO_TogglePin(LEDB_G_GPIO_Port, LEDB_G_Pin);
156-
__disable_irq();
154+
HAL_GPIO_TogglePin(LEDB_G_GPIO_Port, LEDB_G_Pin);
157155
if (huart->Instance == net_stream.rx.uart->Instance)
158156
{
159157
Receive(&net_stream, rx_idx);
@@ -167,16 +165,14 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef* huart, uint16_t rx_idx)
167165
timeout_tick = HAL_GetTick();
168166
Receive(&usb_stream, rx_idx);
169167
}
170-
__enable_irq();
171168
}
172169

173170
void HAL_UART_TxCpltCallback(UART_HandleTypeDef* huart)
174171
{
175172
// Since net_stream.tx.uart is usb AND ui_stream.tx.uart is usb
176173
// then when this is called during either ui upload or net upload
177174
// then they both need to be notified that the usb is free. :shrug:
178-
// HAL_GPIO_TogglePin(LEDB_B_GPIO_Port, LEDB_B_Pin);
179-
__disable_irq();
175+
HAL_GPIO_TogglePin(LEDB_B_GPIO_Port, LEDB_B_Pin);
180176
if (!net_stream.tx.free && huart->Instance == net_stream.tx.uart->Instance)
181177
{
182178
TxISR(&net_stream, &state);
@@ -189,7 +185,6 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef* huart)
189185
{
190186
TxISR(&usb_stream, &state);
191187
}
192-
__enable_irq();
193188
}
194189

195190
int app_main(void)
@@ -198,13 +193,13 @@ int app_main(void)
198193

199194
while (1)
200195
{
196+
NetHoldInReset();
197+
UIHoldInReset();
201198
uploader = 0;
202199
next_state = Running;
203200
TurnOffLEDs();
204201
CancelAllUart();
205202

206-
NormalAndNetUploadUartInit(&usb_stream, &huart1);
207-
208203
switch (state)
209204
{
210205
case Error:
@@ -255,36 +250,36 @@ int app_main(void)
255250
}
256251
case Normal:
257252
{
253+
NormalInit();
258254
SetStreamModes(Command, Ignore, Ignore);
259-
NormalBoot();
260255
LEDA(HIGH, LOW, LOW);
261256
break;
262257
}
263258
case Debug:
264259
{
260+
NormalInit();
265261
SetStreamModes(Command, Passthrough, Passthrough);
266-
NormalBoot();
267262
LEDA(LOW, HIGH, HIGH);
268263
break;
269264
}
270265
case UI_Debug:
271266
{
267+
NormalInit();
272268
SetStreamModes(Command, Passthrough, Ignore);
273-
NormalBoot();
274269
LEDA(LOW, HIGH, LOW);
275270
break;
276271
}
277272
case Net_Debug:
278273
{
274+
NormalInit();
279275
SetStreamModes(Command, Ignore, Passthrough);
280-
NormalBoot();
281276
LEDA(LOW, LOW, HIGH);
282277
break;
283278
}
284279
case Loopback:
285280
{
281+
NormalInit();
286282
SetStreamModes(Passthrough, Ignore, Ignore);
287-
NormalBoot();
288283
LEDA(LOW, LOW, LOW);
289284
break;
290285
}
@@ -311,10 +306,11 @@ int app_main(void)
311306
return 0;
312307
}
313308

314-
void NormalBoot()
309+
void NormalInit()
315310
{
316-
UINormalMode();
317311
NetNormalMode();
312+
UINormalMode();
313+
NormalAndNetUploadUartInit(&usb_stream, &huart1);
318314
}
319315

320316
void CheckTimeout()

firmware/mgmt/src/chip_control.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
void NetBootloaderMode()
77
{
8-
ChangeToOutput(NET_BOOT_GPIO_Port, NET_BOOT_Pin);
9-
ChangeToOutput(NET_NRST_GPIO_Port, NET_NRST_Pin);
10-
8+
PowerCycle(NET_NRST_GPIO_Port, NET_NRST_Pin, 10);
119
// Bring the boot low for esp, bootloader mode (0)
1210
HAL_GPIO_WritePin(NET_BOOT_GPIO_Port, NET_BOOT_Pin, GPIO_PIN_RESET);
1311

@@ -17,30 +15,24 @@ void NetBootloaderMode()
1715

1816
void NetNormalMode()
1917
{
20-
ChangeToOutput(NET_BOOT_GPIO_Port, NET_BOOT_Pin);
21-
ChangeToOutput(NET_NRST_GPIO_Port, NET_NRST_Pin);
18+
PowerCycle(NET_NRST_GPIO_Port, NET_NRST_Pin, 10);
2219

2320
HAL_GPIO_WritePin(NET_BOOT_GPIO_Port, NET_BOOT_Pin, GPIO_PIN_SET);
2421

2522
// Power cycle
2623
PowerCycle(NET_NRST_GPIO_Port, NET_NRST_Pin, 10);
27-
28-
// ChangeToInput(NET_BOOT_GPIO_Port, NET_BOOT_Pin);
29-
// ChangeToInput(NET_NRST_GPIO_Port, NET_NRST_Pin);
3024
}
3125

3226
void NetHoldInReset()
3327
{
34-
ChangeToOutput(NET_NRST_GPIO_Port, NET_NRST_Pin);
28+
HAL_GPIO_WritePin(NET_BOOT_GPIO_Port, NET_BOOT_Pin, GPIO_PIN_SET);
29+
3530
// Reset
3631
HAL_GPIO_WritePin(NET_NRST_GPIO_Port, NET_NRST_Pin, GPIO_PIN_RESET);
3732
}
3833

3934
void UIBootloaderMode()
4035
{
41-
ChangeToOutput(UI_BOOT0_GPIO_Port, UI_BOOT0_Pin);
42-
ChangeToOutput(UI_NRST_GPIO_Port, UI_NRST_Pin);
43-
4436
// Normal boot mode (boot0 = 1 and boot1 = 0)
4537
HAL_GPIO_WritePin(UI_BOOT0_GPIO_Port, UI_BOOT0_Pin, GPIO_PIN_SET);
4638
HAL_GPIO_WritePin(UI_BOOT1_GPIO_Port, UI_BOOT1_Pin, GPIO_PIN_RESET);
@@ -51,18 +43,21 @@ void UIBootloaderMode()
5143

5244
void UINormalMode()
5345
{
54-
ChangeToOutput(UI_BOOT0_GPIO_Port, UI_BOOT0_Pin);
55-
ChangeToOutput(UI_NRST_GPIO_Port, UI_NRST_Pin);
56-
5746
// Normal boot mode (boot0 = 0 and boot1 = 1)
5847
HAL_GPIO_WritePin(UI_BOOT0_GPIO_Port, UI_BOOT0_Pin, GPIO_PIN_RESET);
5948
HAL_GPIO_WritePin(UI_BOOT1_GPIO_Port, UI_BOOT1_Pin, GPIO_PIN_SET);
6049

6150
// Power cycle
6251
PowerCycle(UI_NRST_GPIO_Port, UI_NRST_Pin, 10);
52+
}
53+
54+
void UIHoldInReset()
55+
{
56+
// Normal boot mode (boot0 = 0 and boot1 = 1)
57+
HAL_GPIO_WritePin(UI_BOOT0_GPIO_Port, UI_BOOT0_Pin, GPIO_PIN_RESET);
58+
HAL_GPIO_WritePin(UI_BOOT1_GPIO_Port, UI_BOOT1_Pin, GPIO_PIN_SET);
6359

64-
ChangeToInput(UI_BOOT0_GPIO_Port, UI_BOOT0_Pin);
65-
ChangeToInput(UI_NRST_GPIO_Port, UI_NRST_Pin);
60+
HAL_GPIO_WritePin(UI_NRST_GPIO_Port, UI_NRST_Pin, GPIO_PIN_RESET);
6661
}
6762

6863
void NormalStart()
@@ -73,13 +68,6 @@ void NormalStart()
7368
UINormalMode();
7469
}
7570

76-
void UIHoldInReset()
77-
{
78-
ChangeToOutput(UI_NRST_GPIO_Port, UI_NRST_Pin);
79-
80-
HAL_GPIO_WritePin(UI_NRST_GPIO_Port, UI_NRST_Pin, GPIO_PIN_RESET);
81-
}
82-
8371
/**
8472
* @brief Waits for the network chip to send a ready signal
8573
*

firmware/mgmt/src/io_control.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,6 @@ void PowerCycle(GPIO_TypeDef* port, uint16_t pin, uint32_t delay)
99
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
1010
}
1111

12-
void HoldInReset(GPIO_TypeDef* port, uint16_t pin)
13-
{
14-
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
15-
}
16-
17-
void ChangeToInput(GPIO_TypeDef* port, uint16_t pin)
18-
{
19-
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
20-
21-
HAL_GPIO_DeInit(port, pin);
22-
23-
GPIO_InitTypeDef GPIO_InitStruct = {0};
24-
25-
GPIO_InitStruct.Pin = pin;
26-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
27-
GPIO_InitStruct.Pull = GPIO_NOPULL;
28-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
29-
HAL_GPIO_Init(port, &GPIO_InitStruct);
30-
}
31-
32-
void ChangeToOutput(GPIO_TypeDef* port, uint16_t pin)
33-
{
34-
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET);
35-
36-
HAL_GPIO_DeInit(port, pin);
37-
38-
GPIO_InitTypeDef GPIO_InitStruct = {0};
39-
40-
GPIO_InitStruct.Pin = pin;
41-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
42-
GPIO_InitStruct.Pull = GPIO_NOPULL;
43-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
44-
HAL_GPIO_Init(port, &GPIO_InitStruct);
45-
}
46-
4712
/**
4813
* @brief TODO
4914
*

firmware/mgmt/src/uart_stream.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,7 @@ void InitUartStream(uart_stream_t* stream)
203203

204204
void StartUartReceive(uart_stream_t* stream)
205205
{
206-
uint8_t attempt = 0;
207-
while (
208-
attempt++ != 10
209-
&& HAL_OK
210-
!= HAL_UARTEx_ReceiveToIdle_DMA(stream->rx.uart, stream->rx.buff, stream->rx.size))
211-
{
212-
// Make sure the uart is cancelled, sometimes it doesn't want to cancel
213-
HAL_UART_Abort(stream->rx.uart);
214-
}
215-
216-
if (attempt >= 10)
217-
{
218-
Error_Handler();
219-
}
206+
HAL_UARTEx_ReceiveToIdle_DMA(stream->rx.uart, stream->rx.buff, stream->rx.size);
220207
}
221208

222209
// TODO function that will read from tx and do all of the processing from there?

0 commit comments

Comments
 (0)