Skip to content

Commit

Permalink
引导加载程序
Browse files Browse the repository at this point in the history
  • Loading branch information
losehu committed Jun 28, 2024
1 parent 5ca8dfb commit dae0121
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ENABLE_TX1750 ?= 0
ENABLE_PWRON_PASSWORD ?= 0
ENABLE_DTMF_CALLING ?= 1
ENABLE_FLASHLIGHT ?= 1

ENABLE_BOOTLOADER ?= 1
# ---- CUSTOM MODS ----
ENABLE_BIG_FREQ ?= 1
ENABLE_KEEP_MEM_NAME ?= 1
Expand Down Expand Up @@ -366,6 +366,10 @@ endif
ifeq ($(ENABLE_MDC1200),1)
CFLAGS += -DENABLE_MDC1200
endif
ifeq ($(ENABLE_BOOTLOADER),1)
CFLAGS += -DENABLE_BOOTLOADER
endif

ifeq ($(ENABLE_WARNING),1)
CFLAGS += -DENABLE_WARNING
endif
Expand Down
24 changes: 23 additions & 1 deletion board.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
#include "bsp/dp32g030/syscon.h"
#include "driver/adc.h"
#include "driver/backlight.h"

#include "ARMCM0.h"
#include "bsp/dp32g030/pmu.h"
#include "bsp/dp32g030/saradc.h"
#include "bsp/dp32g030/syscon.h"
#include "sram-overlay.h"
#include "driver/eeprom.h"
#ifdef ENABLE_FMRADIO
#include "driver/bk1080.h"
#endif
Expand Down Expand Up @@ -470,3 +475,20 @@ void BOARD_Init(void) {
#endif

}

void write_to_memory(uint32_t address, uint32_t data) {
// 将地址数值转换为指针
uint32_t *target_address = (uint32_t *) address;
// 向目标地址写入数据
*target_address = data;
// 为了避免优化,确保代码不会被优化掉
volatile uint32_t read_back = *target_address;
}
//JUMP_TO_FLASH(0xa10A,0x20003ff0);
void JUMP_TO_FLASH(uint32_t flash_add,uint32_t stack_add)
{
__disable_irq();
ClearStack();
__set_MSP(stack_add);
__set_PC(flash_add);
}
2 changes: 2 additions & 0 deletions board.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void BOARD_PORTCON_Init(void);
void BOARD_ADC_Init(void);
void BOARD_ADC_GetBatteryInfo(uint16_t *pVoltage, uint16_t *pCurrent);
void BOARD_Init(void);
void JUMP_TO_FLASH(uint32_t flash_add,uint32_t stack_add);
void write_to_memory(uint32_t address, uint32_t data) ;


#endif
Expand Down
22 changes: 15 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#ifdef ENABLE_4732



#endif

#include "audio.h"
Expand Down Expand Up @@ -131,23 +130,18 @@ void Main(void) {
BOARD_Init();


boot_counter_10ms = 250; // 2.5 sec

#ifdef ENABLE_UART
UART_Init();
#endif

SETTINGS_InitEEPROM();


memset(gDTMF_String, '-', sizeof(gDTMF_String));
gDTMF_String[sizeof(gDTMF_String) - 1] = 0;

BK4819_Init();





BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent);


Expand Down Expand Up @@ -227,6 +221,20 @@ void Main(void) {
#endif
UI_DisplayWelcome();

#ifdef ENABLE_BOOTLOADER


if(KEYBOARD_Poll() == KEY_MENU)
{
for (int i = 0; i < 10*1024; i += 4) {
uint32_t c;
EEPROM_ReadBuffer(0x41000 + i, (uint8_t *) &c, 4);
write_to_memory(0x20001000 + i, c);
}
JUMP_TO_FLASH(0x2000110a, 0x20003ff0);
}
#endif


boot_counter_10ms = 250;

Expand Down
8 changes: 0 additions & 8 deletions sram-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,3 @@ void CP_EEPROM_TO_FLASH(uint32_t eeprom_add,uint32_t flash_add,uint32_t size)
ProgramWords(i*4+flash_add, c);
}
}
//JUMP_TO_FLASH(0xa10A,0x20003ff0);
void JUMP_TO_FLASH(uint32_t flash_add,uint32_t stack_add)
{
__disable_irq();
ClearStack();
__set_MSP(stack_add);
__set_PC(flash_add);
}

0 comments on commit dae0121

Please sign in to comment.