generated from hulk/gd32e23x_template_cmake_vscode
Follow the reference to port the bootloader
This commit is contained in:
45
Src/main.c
45
Src/main.c
@@ -35,11 +35,10 @@ OF SUCH DAMAGE.
|
||||
#include "gd32e23x.h"
|
||||
#include "systick.h"
|
||||
#include "uart.h"
|
||||
#include "led.h"
|
||||
#include "command.h"
|
||||
#include <stdio.h>
|
||||
#include "i2c.h"
|
||||
#include "uart_ring_buffer.h"
|
||||
#include "board_config.h"
|
||||
#include "gpio.h"
|
||||
#include "bootloader.h"
|
||||
|
||||
/*!
|
||||
\brief main function
|
||||
@@ -49,29 +48,39 @@ OF SUCH DAMAGE.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
led_init();
|
||||
mcu_detect_and_config();
|
||||
uint8_t buf[1];
|
||||
|
||||
uart_ring_buffer_init();
|
||||
|
||||
if (rcu_flag_get(RCU_FLAG_SWRST) == RESET)
|
||||
{
|
||||
check_flash_and_jump((uint8_t*)FLASH_FLAG_ADDRESS);
|
||||
}
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
systick_config();
|
||||
gpio_init();
|
||||
rs485_init();
|
||||
|
||||
printf("Flash size: %d Kbytes\n", get_flash_size());
|
||||
// gpio_bit_write(MOTOR_EN_PORT, MOTOR_EN_PIN, RESET);
|
||||
|
||||
#ifdef DEBUG_VERBOSE
|
||||
printf("Hello World!\r\n");
|
||||
#endif
|
||||
delay_ms(100);
|
||||
rs485_send_str((uint8_t*)"ok", 2);
|
||||
delay_ms(100);
|
||||
// wait rs485 send complete: DE high -> low
|
||||
|
||||
i2c_config();
|
||||
while (uart_ring_buffer_get() != 0x30);
|
||||
rs485_send_str((uint8_t*)"ok", 2);
|
||||
|
||||
#ifdef DEBUG_VERBOSE
|
||||
i2c_scan();
|
||||
while (uart_ring_buffer_get() != 0x31);
|
||||
rs485_send_str((uint8_t*)"ok", 2);
|
||||
|
||||
i2c_bus_reset();
|
||||
#endif
|
||||
ymodem_receive(buf);
|
||||
|
||||
delay_ms(100);
|
||||
|
||||
check_flash_and_jump((uint8_t*)FLASH_FLAG_ADDRESS);
|
||||
|
||||
while(1){
|
||||
command_process();
|
||||
delay_ms(10);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user