Change in osmo-asf4-dfu[sysmoOCTSIM]: add specific board support, including sysmoOCTSIM

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

tsaitgaist gerrit-no-reply at lists.osmocom.org
Tue Jan 14 13:14:56 UTC 2020


tsaitgaist has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/16851 )


Change subject: add specific board support, including sysmoOCTSIM
......................................................................

add specific board support, including sysmoOCTSIM

the board specific definitions should be coded when particular
environment variable/marco is defined.
this macro name is provided by the makefile in the BOARD variable.
this allows to compile the bootloader for specific devices.
see README for more information.
the board definition for the sysmoOCTSIM is also added.

Change-Id: Ie51a3af7c77ba76ac40570b871f31fd527fb255b
---
M README.md
M atmel_start_pins.h
M config/usbd_config.h
M driver_init.c
M driver_init.h
M gcc/Makefile
M usb_dfu_main.c
M usb_start.c
8 files changed, 109 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-asf4-dfu refs/changes/51/16851/1

diff --git a/README.md b/README.md
index 031bc27..58833aa 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,22 @@
 This is an implementation of the DFU mode of the [USB DFU Device Class Specification](https://usb.org/document-library/device-firmware-upgrade-11-new-version-31-aug-2004) for the Microchip SAM D5x/E5x micro-controller.
 It is meant to be used as bootloader to allow flashing the main application over USB.
 
-The code has been developed for the Microchip [SAM E54 Xplained Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNo/ATSAME54-XPRO) development board using a [SAM E54](https://www.microchip.com/wwwproducts/en/ATSAME54P20A) micro-controller.
+The code has been developed using a [SAM E54](https://www.microchip.com/wwwproducts/en/ATSAME54P20A) micro-controller.
 It should work on any chip of the SAM D5x/E5x device family by replacing the corresponding device-specific definitions (usually including the chip name in the file name).
 
 The code uses the [Atmel START](https://start.atmel.com/) ASFv4 library.
 
+Board
+=====
+
+The code can be compiled for specific boards:
+
+- Microchip [SAM E54 Xplained Pro](https://www.microchip.com/DevelopmentTools/ProductDetails/PartNo/ATSAME54-XPRO) development board, named *SAME54_XPLAINED_PRO*
+- sysmocom sysmoOCTSIM, name *SYSMOOCTSIM*
+
+The board name can be set in 'gcc/Makefile' *BOARD* variable, or provided while compiling (e.g. `make BOARD=SAME54_XPLAINED_PRO`).
+*SAME54_XPLAINED_PRO* is the default value.
+
 USB DFU
 =======
 
@@ -26,13 +37,14 @@
 make
 ```
 
+The board name can be set in 'gcc/Makefile' *BOARD* variable, or provided while compiling (e.g. `make BOARD=SAME54_XPLAINED_PRO`).
+*SAME54_XPLAINED_PRO* is the default value.
+
 The resulting firmware binary is `AtmelStart.bin`.
 
 Flashing
 ========
 
-To flash the bootloader you can either use the [edbg tool](https://github.com/ataradov/edbg) over the EDBG interface of the SAM E54 Xplained Pro development board, or OpenICD with any SWJ adapter.
-
 The USB DFU bootloader should be flashed in a protected area of the flash memory to prevent for erasing it, as specified in data sheet section 25.6.2 Memory Organization.
 The bootloader size is configured in the NVM user configuration BOOTPROT field, as specified in data sheet section 25.6.9 NVM User Configuration.
 The bit position of the BOOTPROT field is documented in data sheet section 9.4 NVM User Page Mapping.
@@ -43,8 +55,26 @@
 EDBG
 ----
 
+To flash the bootloader using the [edbg tool](https://github.com/ataradov/edbg) over the EDBG interface of the SAM E54 Xplained Pro development board.
+
 To flash the USB DFU bootloader, perform the following actions:
 * remove reserved bootloader space so we can erase it: `edbg --target atmel_cm4v2 --fuse wv,29:26,15`
 * erase the whole flash: `edbg --target atmel_cm4v2 --fuse v,29:26,15 --erase`
 * program the bootloader: `edbg --target atmel_cm4v2 --fuse v,29:26,15 --program --verify --file AtmelStart.bin`
 * reserve bootloader space: `edbg --target atmel_cm4v2 --fuse wv,29:26,13`
+
+SWJ
+---
+
+The bootloader can also be flashed over SWJ (e.g. JTAG or SWD).
+You need to perform the following actions:
+
+* remove reserved bootloader space so we can erase it (and reset MCU for change to be effective)
+* erase the whole flash
+* program the bootloader
+* reserve bootloader space
+
+Using OpenOCD (with the [SAM E54 patch](http://openocd.zylin.com/#/c/4272/)) and a ST-LINK/V2 SWD adapter, run the following command:
+
+`openocd --file interface/stlink.cfg --command "transport select hla_swd" --command "set CHIPNAME same54" --command "set CPUTAPID 0x2ba01477" --file target/atsame5x.cfg --command "init" --command "reset halt" --command "atsame5 bootloader 0" --command "flash erase_sector 0 0 last" --command "reset halt" --command "program ./AtmelStart.bin" --command "atsame5 bootloader 16384"  --command "reset run" --command "shutdown"`
+
diff --git a/atmel_start_pins.h b/atmel_start_pins.h
index 86e1dfb..220a7b5 100644
--- a/atmel_start_pins.h
+++ b/atmel_start_pins.h
@@ -27,11 +27,19 @@
 #define GPIO_PIN_FUNCTION_M 12
 #define GPIO_PIN_FUNCTION_N 13
 
-/** LED pin to indicate system state (pull low to switch on) */
+/** LED pin to indicate system state */
+#if defined(SAME54_XPLAINED_PRO)
 #define LED_SYSTEM GPIO(GPIO_PORTC, 18)
+#elif defined(SYSMOOCTSIM)
+#define LED_SYSTEM GPIO(GPIO_PORTC, 26)
+#endif
 
-/** User button to force DFu bootloader (connected to ground when pressed) */
+/** User button to force DFU bootloader (connected to ground when pressed) */
+#if defined(SAME54_XPLAINED_PRO)
 #define BUTTON_FORCE_DFU GPIO(GPIO_PORTB, 31)
+#elif defined(SYSMOOCTSIM)
+#define BUTTON_FORCE_DFU GPIO(GPIO_PORTC, 14)
+#endif
 
 /** USB D+/D- pins */
 #define PA24 GPIO(GPIO_PORTA, 24)
diff --git a/config/usbd_config.h b/config/usbd_config.h
index c20dfb2..6133596 100644
--- a/config/usbd_config.h
+++ b/config/usbd_config.h
@@ -85,8 +85,12 @@
 // <0x6140=> osmo-ASF4-DFU
 // <id> usb_dfud_idproduct
 #ifndef CONF_USB_OSMOASF4DFU_IDPRODUCT
+#if defined(SYSMOOCTSIM)
+#define CONF_USB_OSMOASF4DFU_IDPRODUCT 0x6141
+#else
 #define CONF_USB_OSMOASF4DFU_IDPRODUCT 0x6140
 #endif
+#endif
 
 // <o> bcdDevice <0x0000-0xFFFF>
 // <id> usb_dfud_bcddevice
@@ -107,12 +111,20 @@
 // <s> Unicode string of iManufact
 // <id> usb_dfud_imanufact_str
 #ifndef CONF_USB_DFUD_IMANUFACT_STR
+#if defined(SYSMOOCTSIM)
+#define CONF_USB_DFUD_IMANUFACT_STR "sysmocom"
+#else
 #define CONF_USB_DFUD_IMANUFACT_STR "osmocom"
 #endif
+#endif
 
 #ifndef CONF_USB_DFUD_IMANUFACT_STR_DESC
+#if defined(SYSMOOCTSIM)
+#define CONF_USB_DFUD_IMANUFACT_STR_DESC 18, 0x03, 's', 0x00, 'y', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, 'c', 0x00, 'o', 0x00, 'm', 0x00,
+#else
 #define CONF_USB_DFUD_IMANUFACT_STR_DESC 16, 0x03, 'o', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, 'c', 0x00, 'o', 0x00, 'm', 0x00,
 #endif
+#endif
 
 // </e>
 
@@ -130,12 +142,20 @@
 // <s> Unicode string of iProduct
 // <id> usb_dfud_iproduct_str
 #ifndef CONF_USB_DFUD_IPRODUCT_STR
+#if defined(SYSMOOCTSIM)
+#define CONF_USB_DFUD_IPRODUCT_STR "sysmoOCTSIM (osmo-ASF4-DFU)"
+#else
 #define CONF_USB_DFUD_IPRODUCT_STR "osmo-ASF4-DFU"
 #endif
+#endif
 
 #ifndef CONF_USB_DFUD_IPRODUCT_STR_DESC
+#if defined(SYSMOOCTSIM)
+#define CONF_USB_DFUD_IPRODUCT_STR_DESC 56, 0x03, 's', 0x00, 'y', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, 'O', 0x00, 'C', 0x00, 'T', 0x00, 'S', 0x00, 'I', 0x00, 'M', 0x00, ' ', 0x00, '(', 0x00, 'o', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, '-', 0x00, 'A', 0x00, 'S', 0x00, 'F', 0x00, '4', 0x00, '-', 0x00, 'D', 0x00, 'F', 0x00, 'U', 0x00, ')', 0x00,
+#else
 #define CONF_USB_DFUD_IPRODUCT_STR_DESC 28, 0x03, 'o', 0x00, 's', 0x00, 'm', 0x00, 'o', 0x00, '-', 0x00, 'A', 0x00, 'S', 0x00, 'F', 0x00, '4', 0x00, '-', 0x00, 'D', 0x00, 'F', 0x00, 'U', 0x00,
 #endif
+#endif
 
 // </e>
 
diff --git a/driver_init.c b/driver_init.c
index a91b0eb..d873230 100644
--- a/driver_init.c
+++ b/driver_init.c
@@ -139,18 +139,38 @@
 	flash_init(&FLASH_0, NVMCTRL);
 }
 
+void LED_SYSTEM_on(void)
+{
+#if defined(SYSMOOCTSIM)
+	gpio_set_pin_level(LED_SYSTEM, true);
+#else
+	gpio_set_pin_level(LED_SYSTEM, false);
+#endif
+}
+
+void LED_SYSTEM_off(void)
+{
+#if defined(SYSMOOCTSIM)
+	gpio_set_pin_level(LED_SYSTEM, false);
+#else
+	gpio_set_pin_level(LED_SYSTEM, true);
+#endif
+}
+
 void system_init(void)
 {
 	init_mcu();
 
 	// configure system LED
-	gpio_set_pin_level(LED_SYSTEM, true); // switch off LED
+	LED_SYSTEM_off();
 	gpio_set_pin_direction(LED_SYSTEM, GPIO_DIRECTION_OUT);
 	gpio_set_pin_function(LED_SYSTEM, GPIO_PIN_FUNCTION_OFF);
 
 	// configure force DFU user button
 	gpio_set_pin_direction(BUTTON_FORCE_DFU, GPIO_DIRECTION_IN);
-	gpio_set_pin_pull_mode(BUTTON_FORCE_DFU, GPIO_PULL_UP);
+#if !defined(SYSMOOCTSIM)
+	gpio_set_pin_pull_mode(BUTTON_FORCE_DFU, GPIO_PULL_UP); // use internal pull-up resistor
+#endif
 	gpio_set_pin_function(BUTTON_FORCE_DFU, GPIO_PIN_FUNCTION_OFF);
 
 	USB_DEVICE_INSTANCE_init();
diff --git a/driver_init.h b/driver_init.h
index 0d440d4..8d8a30b 100644
--- a/driver_init.h
+++ b/driver_init.h
@@ -34,6 +34,15 @@
 void FLASH_0_CLOCK_init(void);
 
 /**
+ * \brief Switch system LED on
+ */
+void LED_SYSTEM_on(void);
+/**
+ * \brief Switch system LED off
+ */
+void LED_SYSTEM_off(void);
+
+/**
  * \brief Perform system initialization, initialize pins and clocks for
  * peripherals
  */
diff --git a/gcc/Makefile b/gcc/Makefile
index 16c7858..7ad24b1 100644
--- a/gcc/Makefile
+++ b/gcc/Makefile
@@ -1,4 +1,13 @@
 ################################################################################
+# User configuration. Can be edited
+################################################################################
+
+# Set for which board the bootloader should be compiled
+# run `make clean` for the change to be effective
+# possible values: SAME54_XPLAINED_PRO, SYSMOOCTSIM 
+BOARD ?= SAME54_XPLAINED_PRO
+
+################################################################################
 # Automatically-generated file. Do not edit!
 ################################################################################
 
@@ -202,7 +211,7 @@
 	@echo Building file: $<
 	@echo ARM/GNU C Compiler
 	$(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
--D__SAME54P20A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
+-D__SAME54P20A__ -D$(BOARD) -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
 -I"../" -I"../config" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/nvmctrl" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
 	@echo Finished building: $<
@@ -211,7 +220,7 @@
 	@echo Building file: $<
 	@echo ARM/GNU Assembler
 	$(QUOTE)arm-none-eabi-as$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
--D__SAME54P20A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
+-D__SAME54P20A__ -D$(BOARD) -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
 -I"../" -I"../config" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/nvmctrl" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
 	@echo Finished building: $<
@@ -220,7 +229,7 @@
 	@echo Building file: $<
 	@echo ARM/GNU Preprocessing Assembler
 	$(QUOTE)arm-none-eabi-gcc$(QUOTE) -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
--D__SAME54P20A__ -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
+-D__SAME54P20A__ -D$(BOARD) -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 \
 -I"../" -I"../config" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/cmcc" -I"../hpl/core" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/nvmctrl" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/ramecc" -I"../hpl/usb" -I"../hri" -I"../" -I"../config" -I"../usb" -I"../usb/class/dfu" -I"../usb/class/dfu/device" -I"../usb/device" -I"../" -I"../CMSIS/Include" -I"../include"  \
 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"  -o "$@" "$<"
 	@echo Finished building: $<
diff --git a/usb_dfu_main.c b/usb_dfu_main.c
index 449b311..96032c5 100644
--- a/usb_dfu_main.c
+++ b/usb_dfu_main.c
@@ -48,7 +48,6 @@
  */
 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
 }
 
diff --git a/usb_start.c b/usb_start.c
index ad91840..93059ad 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -80,7 +80,7 @@
 void usb_dfu(void)
 {
 	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
+	LED_SYSTEM_on(); // switch LED on to indicate USB DFU stack is ready
 
 	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
@@ -89,7 +89,7 @@
 	while (true) { // main DFU infinite loop
 		// 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
-			gpio_set_pin_level(LED_SYSTEM, true); // switch LED off to indicate we are flashing
+			LED_SYSTEM_off(); // switch LED off to indicate we are flashing
 			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
 				if (ERR_NONE == rc) {
@@ -108,7 +108,7 @@
 				// this case should not happen, but it's not a critical error
 				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
+			LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
 		}
 		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

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/16851
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: sysmoOCTSIM
Gerrit-Change-Id: Ie51a3af7c77ba76ac40570b871f31fd527fb255b
Gerrit-Change-Number: 16851
Gerrit-PatchSet: 1
Gerrit-Owner: tsaitgaist <kredon at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200114/59febbbb/attachment.htm>


More information about the gerrit-log mailing list