Skip to content

Commit d25c462

Browse files
authored
Merge pull request #295 from zvecr/f3_f4_align
Minor stm32f3/stm32f4 alignment
2 parents e7acace + ed7d7fa commit d25c462

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

ports/stm32f3/boards.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ bool board_app_valid(void)
138138

139139
void board_app_jump(void)
140140
{
141+
volatile uint32_t const * app_vector = (volatile uint32_t const*) BOARD_FLASH_APP_START;
142+
uint32_t sp = app_vector[0];
143+
uint32_t app_entry = app_vector[1];
144+
141145
GPIO_InitTypeDef GPIO_InitStruct;
142146
GPIO_InitStruct.Pin = GPIO_PIN_12;
143147
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@@ -185,18 +189,14 @@ void board_app_jump(void)
185189
NVIC->ICER[2] = 0xFFFFFFFF;
186190
NVIC->ICER[3] = 0xFFFFFFFF;
187191

188-
// TODO protect bootloader region
189-
190-
volatile uint32_t const * app_vector = (volatile uint32_t const*) BOARD_FLASH_APP_START;
191-
192192
/* switch exception handlers to the application */
193193
SCB->VTOR = (uint32_t) BOARD_FLASH_APP_START;
194194

195195
// Set stack pointer
196-
__set_MSP(app_vector[0]);
196+
__set_MSP(sp);
197197

198198
// Jump to Application Entry
199-
asm("bx %0" ::"r"(app_vector[1]));
199+
asm("bx %0" ::"r"(app_entry));
200200
}
201201

202202
uint8_t board_usb_get_serial(uint8_t serial_id[16])

ports/stm32f4/board_flash.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
#endif
3030

3131
//--------------------------------------------------------------------+
32-
//
32+
// MACRO TYPEDEF CONSTANT ENUM
3333
//--------------------------------------------------------------------+
3434

35-
// no caching
36-
//#define FLASH_CACHE_SIZE 4096
37-
//#define FLASH_CACHE_INVALID_ADDR 0xffffffff
38-
3935
#define FLASH_BASE_ADDR 0x08000000UL
4036

4137
// TinyUF2 resides in the first 2 flash sectors on STM32F4s, therefore these are write protected
@@ -84,9 +80,14 @@ enum
8480
static uint8_t erased_sectors[SECTOR_COUNT] = { 0 };
8581

8682
//--------------------------------------------------------------------+
87-
//
83+
// Internal Helper
8884
//--------------------------------------------------------------------+
8985

86+
static inline uint32_t flash_sector_size(uint32_t sector)
87+
{
88+
return sector_size[sector];
89+
}
90+
9091
static bool is_blank(uint32_t addr, uint32_t size)
9192
{
9293
for ( uint32_t i = 0; i < size; i += sizeof(uint32_t) )
@@ -112,7 +113,7 @@ static bool flash_erase(uint32_t addr)
112113
{
113114
TUF2_ASSERT(sector_addr < FLASH_BASE_ADDR + BOARD_FLASH_SIZE);
114115

115-
size = sector_size[i];
116+
size = flash_sector_size(i);
116117
if ( sector_addr + size > addr )
117118
{
118119
sector = i;
@@ -170,7 +171,7 @@ static void flash_write(uint32_t dst, const uint8_t *src, int len)
170171
}
171172

172173
//--------------------------------------------------------------------+
173-
//
174+
// Board API
174175
//--------------------------------------------------------------------+
175176
void board_flash_init(void)
176177
{
@@ -285,7 +286,7 @@ void board_self_update(const uint8_t * bootloader_bin, uint32_t bootloader_len)
285286

286287
for ( uint32_t i = 0; i < 4 && len > 0; i++ )
287288
{
288-
uint32_t const size = (sector_size[i] < len ? sector_size[i] : len);
289+
uint32_t const size = (flash_sector_size(i) < len ? flash_sector_size(i) : len);
289290
board_flash_write(sector_addr, data, size);
290291

291292
sector_addr += size;

ports/stm32f4/boards.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ void SysTick_Handler(void)
364364
board_timer_handler();
365365
}
366366

367-
368367
int board_uart_write(void const * buf, int len)
369368
{
370369
#if defined(UART_DEV) && CFG_TUSB_DEBUG

0 commit comments

Comments
 (0)