-
Notifications
You must be signed in to change notification settings - Fork 3
Bootloader #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ParthivS20
wants to merge
14
commits into
main
Choose a base branch
from
bootloader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Bootloader #271
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e7ddd3
stable flash no uart callback
ParthivS20 24149ac
uart command to go back to boot works
ParthivS20 8d78dfa
parent project support
ParthivS20 05f93e4
VCU testing
ParthivS20 a7ef3a9
standardization across target and hosts
ParthivS20 f7b6ff6
psom lsom verified
ParthivS20 1f96f2f
gemini fixes untested
ParthivS20 4189add
fix big shah build
Lakshay983 86680ac
gemini fixes working
ParthivS20 29c1462
Merge origin/bootloader: fix big shah build (CI/testing)
ParthivS20 1b072c1
blinky_bootloader_test: drop dead if(0) in heartbeat_clock_init
ParthivS20 b07439a
Merge branch 'main' into bootloader
ParthivS20 f8f8e3e
enter bootlaoder when flash
ParthivS20 b76d545
enter bootlaoder pt 2
ParthivS20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #ifndef BOOTLOADER_CONFIG_H_ | ||
| #define BOOTLOADER_CONFIG_H_ | ||
|
|
||
| #include "bootloader_hal.h" | ||
|
|
||
| #ifndef BOOTLOADER_APP_BASE | ||
| #define BOOTLOADER_APP_BASE (0x08010000UL) | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_APP_MAX_SIZE | ||
| #define BOOTLOADER_APP_MAX_SIZE (448UL * 1024UL) | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_UART_BAUD | ||
| #define BOOTLOADER_UART_BAUD (115200U) | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_UART_INSTANCE | ||
| #if defined(USART3) | ||
| #define BOOTLOADER_UART_INSTANCE USART3 | ||
| #elif defined(USART2) | ||
| #define BOOTLOADER_UART_INSTANCE USART2 | ||
| #elif defined(USART1) | ||
| #define BOOTLOADER_UART_INSTANCE USART1 | ||
| #else | ||
| #error "No supported UART instance available for bootloader." | ||
| #endif | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_WRITE_CHUNK_MAX | ||
| #define BOOTLOADER_WRITE_CHUNK_MAX (128U) | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_HANDSHAKE_TIMEOUT_MS | ||
| #define BOOTLOADER_HANDSHAKE_TIMEOUT_MS (0U) | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_APP_STARTUP_WAIT_MS | ||
| #define BOOTLOADER_APP_STARTUP_WAIT_MS (3000U) | ||
| #endif | ||
|
|
||
| #ifndef BOOTLOADER_POST_FLASH_BOOT_DELAY_MS | ||
| #define BOOTLOADER_POST_FLASH_BOOT_DELAY_MS (2000U) | ||
| #endif | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #ifndef BOOTLOADER_HAL_H_ | ||
| #define BOOTLOADER_HAL_H_ | ||
|
|
||
| #if defined(STM32F4xx) | ||
| #include "stm32f4xx_hal.h" | ||
| #elif defined(STM32L4xx) | ||
| #include "stm32l4xx_hal.h" | ||
| #elif defined(STM32G4xx) | ||
| #include "stm32g4xx_hal.h" | ||
| #else | ||
| #error "Unsupported STM32 series for bootloader." | ||
| #endif | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef BOOTLOADER_INDICATOR_H_ | ||
| #define BOOTLOADER_INDICATOR_H_ | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| typedef enum { | ||
| BOOTLOADER_INDICATOR_NO_APP = 0, | ||
| BOOTLOADER_INDICATOR_APP_PRESENT, | ||
| BOOTLOADER_INDICATOR_CONNECTED, | ||
| BOOTLOADER_INDICATOR_FLASHING, | ||
| BOOTLOADER_INDICATOR_ERROR, | ||
| } bootloader_indicator_mode_t; | ||
|
|
||
| void bootloader_indicator_init(void); | ||
| void bootloader_indicator_set_mode(bootloader_indicator_mode_t mode); | ||
| void bootloader_indicator_update(uint32_t tick_ms); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef BOOTLOADER_RUNTIME_H_ | ||
| #define BOOTLOADER_RUNTIME_H_ | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| void bootloader_runtime_init(void); | ||
| bool bootloader_runtime_wait_for_handshake(uint32_t timeout_ms); | ||
| bool bootloader_runtime_poll_sync(uint32_t timeout_ms); | ||
| bool bootloader_runtime_send_bytes(const uint8_t *data, uint16_t len); | ||
| bool bootloader_runtime_read_bytes(uint8_t *data, uint16_t len, uint32_t timeout_ms); | ||
| bool bootloader_runtime_erase_app(void); | ||
| bool bootloader_runtime_write_app(uint32_t app_offset, const uint8_t *data, size_t len); | ||
| bool bootloader_runtime_is_app_valid(void); | ||
| void bootloader_runtime_jump_to_app(void); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #include "bootloader_indicator.h" | ||
|
|
||
| #include "bootloader_hal.h" | ||
|
|
||
| #include <stdbool.h> | ||
|
|
||
| #if defined(STM32L432xx) | ||
| #define LED_PIN GPIO_PIN_3 | ||
| #define LED_PORT GPIOB | ||
| #elif defined(STM32L431xx) | ||
| #define LED_PIN GPIO_PIN_11 | ||
| #define LED_PORT GPIOB | ||
| #elif defined(STM32G473xx) | ||
| #define LED_PIN GPIO_PIN_3 | ||
| #define LED_PORT GPIOC | ||
| #else | ||
| #define LED_PIN GPIO_PIN_5 | ||
| #define LED_PORT GPIOA | ||
| #endif | ||
|
|
||
| static bootloader_indicator_mode_t s_mode = BOOTLOADER_INDICATOR_NO_APP; | ||
|
|
||
| static void bootloader_indicator_enable_port_clock(void) { | ||
| if (LED_PORT == GPIOA) { | ||
| __HAL_RCC_GPIOA_CLK_ENABLE(); | ||
| } else if (LED_PORT == GPIOB) { | ||
| __HAL_RCC_GPIOB_CLK_ENABLE(); | ||
| } else if (LED_PORT == GPIOC) { | ||
| __HAL_RCC_GPIOC_CLK_ENABLE(); | ||
| } else if (LED_PORT == GPIOD) { | ||
| __HAL_RCC_GPIOD_CLK_ENABLE(); | ||
| } | ||
| } | ||
|
|
||
| void bootloader_indicator_init(void) { | ||
| GPIO_InitTypeDef init = {0}; | ||
| bootloader_indicator_enable_port_clock(); | ||
|
|
||
| init.Pin = LED_PIN; | ||
| init.Mode = GPIO_MODE_OUTPUT_PP; | ||
| init.Pull = GPIO_NOPULL; | ||
| init.Speed = GPIO_SPEED_FREQ_LOW; | ||
| HAL_GPIO_Init(LED_PORT, &init); | ||
| HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_RESET); | ||
| } | ||
|
|
||
| void bootloader_indicator_set_mode(bootloader_indicator_mode_t mode) { | ||
| s_mode = mode; | ||
| if (s_mode == BOOTLOADER_INDICATOR_CONNECTED) { | ||
| HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET); | ||
| } else { | ||
| HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_RESET); | ||
| } | ||
| } | ||
|
|
||
| void bootloader_indicator_update(uint32_t tick_ms) { | ||
| bool led_on = false; | ||
|
|
||
| if (s_mode == BOOTLOADER_INDICATOR_CONNECTED) { | ||
| led_on = true; | ||
| } else if (s_mode == BOOTLOADER_INDICATOR_FLASHING) { | ||
| led_on = (tick_ms % 600U) < 300U; | ||
| } else if (s_mode == BOOTLOADER_INDICATOR_APP_PRESENT) { | ||
| uint32_t phase = tick_ms % 1000U; | ||
| led_on = (phase < 100U) || ((phase >= 200U) && (phase < 300U)); | ||
| } else if (s_mode == BOOTLOADER_INDICATOR_NO_APP) { | ||
| /* | ||
| * Software PWM fade. The update loop runs often while polling UART, so | ||
| * a 20 ms PWM frame is enough for a visible breathe without a timer. | ||
| */ | ||
| uint32_t breath = tick_ms % 2000U; | ||
| uint32_t level = (breath < 1000U) ? breath : (1999U - breath); | ||
| uint32_t pwm = tick_ms % 20U; | ||
| led_on = pwm < (level / 50U); | ||
| } else if (s_mode == BOOTLOADER_INDICATOR_ERROR) { | ||
| led_on = (tick_ms % 500U) < 250U; | ||
| } | ||
|
|
||
| HAL_GPIO_WritePin(LED_PORT, LED_PIN, led_on ? GPIO_PIN_SET : GPIO_PIN_RESET); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.