change LED and switch to sysmoOCTSIM board

Change-Id: I481d96a284240310b634f6dc0806d4a1972cd3b9
This commit is contained in:
Kevin Redon 2019-02-03 13:52:00 +01:00
parent 26037ab23b
commit da201623c1
4 changed files with 8 additions and 10 deletions

View File

@ -27,11 +27,11 @@
#define GPIO_PIN_FUNCTION_M 12 #define GPIO_PIN_FUNCTION_M 12
#define GPIO_PIN_FUNCTION_N 13 #define GPIO_PIN_FUNCTION_N 13
/** LED pin to indicate system state (pull low to switch on) */ /** LED pin to indicate system state (pull high to switch on) */
#define LED_SYSTEM GPIO(GPIO_PORTC, 18) #define LED_SYSTEM GPIO(GPIO_PORTC, 26)
/** User button to force DFu bootloader (connected to ground when pressed) */ /** User button to force DFu bootloader (connected to ground when pressed) */
#define BUTTON_FORCE_DFU GPIO(GPIO_PORTB, 31) #define BUTTON_FORCE_DFU GPIO(GPIO_PORTC, 14)
/** USB D+/D- pins */ /** USB D+/D- pins */
#define PA24 GPIO(GPIO_PORTA, 24) #define PA24 GPIO(GPIO_PORTA, 24)

View File

@ -144,13 +144,12 @@ void system_init(void)
init_mcu(); init_mcu();
// configure system LED // configure system LED
gpio_set_pin_level(LED_SYSTEM, true); // switch off LED gpio_set_pin_level(LED_SYSTEM, false); // switch off LED
gpio_set_pin_direction(LED_SYSTEM, GPIO_DIRECTION_OUT); gpio_set_pin_direction(LED_SYSTEM, GPIO_DIRECTION_OUT);
gpio_set_pin_function(LED_SYSTEM, GPIO_PIN_FUNCTION_OFF); gpio_set_pin_function(LED_SYSTEM, GPIO_PIN_FUNCTION_OFF);
// configure force DFU user button // configure force DFU user button
gpio_set_pin_direction(BUTTON_FORCE_DFU, GPIO_DIRECTION_IN); gpio_set_pin_direction(BUTTON_FORCE_DFU, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(BUTTON_FORCE_DFU, GPIO_PULL_UP);
gpio_set_pin_function(BUTTON_FORCE_DFU, GPIO_PIN_FUNCTION_OFF); gpio_set_pin_function(BUTTON_FORCE_DFU, GPIO_PIN_FUNCTION_OFF);
USB_DEVICE_INSTANCE_init(); USB_DEVICE_INSTANCE_init();

View File

@ -48,8 +48,7 @@ static bool check_bootloader(void)
*/ */
static bool check_force_dfu(void) static bool check_force_dfu(void)
{ {
gpio_set_pin_pull_mode(BUTTON_FORCE_DFU, GPIO_PULL_UP); // pull button high return (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)); // signal is low when button is pressed (pulled high externally)
return (0 == gpio_get_pin_level(BUTTON_FORCE_DFU)); // signal is low when button is pressed
} }
/** Check if the application is valid /** Check if the application is valid

View File

@ -80,7 +80,7 @@ static void usb_dfu_reset(const enum usb_event ev, const uint32_t param)
void usb_dfu(void) void usb_dfu(void)
{ {
while (!dfudf_is_enabled()); // wait for DFU to be installed while (!dfudf_is_enabled()); // wait for DFU to be installed
gpio_set_pin_level(LED_SYSTEM, false); // switch LED on to indicate USB DFU stack is ready gpio_set_pin_level(LED_SYSTEM, true); // switch LED on to indicate USB DFU stack is ready
ASSERT(hri_nvmctrl_read_STATUS_BOOTPROT_bf(FLASH_0.dev.hw) <= 15); ASSERT(hri_nvmctrl_read_STATUS_BOOTPROT_bf(FLASH_0.dev.hw) <= 15);
uint32_t application_start_address = (15 - hri_nvmctrl_read_STATUS_BOOTPROT_bf(FLASH_0.dev.hw)) * 8192; // calculate bootloader size to know where we should write the application firmware uint32_t application_start_address = (15 - hri_nvmctrl_read_STATUS_BOOTPROT_bf(FLASH_0.dev.hw)) * 8192; // calculate bootloader size to know where we should write the application firmware
@ -89,7 +89,7 @@ void usb_dfu(void)
while (true) { // main DFU infinite loop while (true) { // main DFU infinite loop
// run the second part of the USB DFU state machine handling non-USB aspects // run the second part of the USB DFU state machine handling non-USB aspects
if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state || USB_DFU_STATE_DFU_DNBUSY == dfu_state) { // there is some data to be flashed if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state || USB_DFU_STATE_DFU_DNBUSY == dfu_state) { // there is some data to be flashed
gpio_set_pin_level(LED_SYSTEM, true); // switch LED off to indicate we are flashing gpio_set_pin_level(LED_SYSTEM, false); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed if (dfu_download_length > 0) { // there is some data to be flashed
int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
if (ERR_NONE == rc) { if (ERR_NONE == rc) {
@ -108,7 +108,7 @@ void usb_dfu(void)
// this case should not happen, but it's not a critical error // this case should not happen, but it's not a critical error
dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue
} }
gpio_set_pin_level(LED_SYSTEM, false); // switch LED on to indicate USB DFU can resume gpio_set_pin_level(LED_SYSTEM, true); // switch LED on to indicate USB DFU can resume
} }
if (USB_DFU_STATE_DFU_MANIFEST == dfu_state) { // we can start manifestation (finish flashing) if (USB_DFU_STATE_DFU_MANIFEST == dfu_state) { // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data // in theory every DFU files should have a suffix to with a CRC to check the data