diff --git a/.gitignore b/.gitignore
index e0e9abe9..0f022cad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,7 @@ node_modules
scripts/clean-ifaces/*.plist
.vscode/c_cpp_properties.json
TAGS
+
+**/.DS_STORE
+**/*.iml
+**/.idea
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 295b1d81..79740235 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -1,9 +1,16 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
- "version": "0.1.0",
+ "version": "2.0.0",
"command": "make",
- "isShellCommand": true,
"args": [],
- "showOutput": "always"
+ "tasks": [
+ {
+ "label": "make",
+ "type": "shell",
+ "command": "make",
+ "problemMatcher": [],
+ "group": "build"
+ }
+ ]
}
\ No newline at end of file
diff --git a/README.md b/README.md
index ef956dac..f09a975a 100644
--- a/README.md
+++ b/README.md
@@ -115,7 +115,7 @@ to temporarily turn off the protection. In gdb the command is:
### Requirements
-* `make` and an Unix environment
+* GNU `make` and a Unix environment
* `node`.js in path (optional)
* `arm-none-eabi-gcc` in the path (the one coming with Yotta will do just fine). You can get the latest version from ARM: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
* `openocd` - you can use the one coming with Arduino (after your install the M0 board support)
@@ -188,6 +188,30 @@ Thus, it's best to set the USB ID to one for which there are no drivers.
The bootloader sits at 0x00000000, and the application starts at 0x00002000 (SAMD21) or 0x00004000 (SAMD51).
+#### Bootloader Hold Switch
+
+A Board can be configured to sense the state of a GPIO and to hold the bootloader from running an application if it is in the appropriate state. To enable this, add the following to your board configuration header file.
+
+```C
+// The Pin that will tell us to stay in the bootloader or not.
+#define HOLD_PIN PIN_PA02
+
+// Optional, define if a Pull up or pulldown is needed.
+#define HOLD_PIN_PULLUP
+//#define HOLD_PIN_PULLDOWN
+
+// What is the Hold state of the GPIO, 0 or 1.
+#define HOLD_STATE 1
+```
+
+Set `HOLD_PIN` to the appropriate GPIO and `HOLD_STATE` to the logic level which will hold the bootloader from running the application.
+
+The definition of _BOTH_ `HOLD_PIN` and `HOLD_STATE` triggers the inclusion of this feature. If either of these is undefined, this feature is not enabled.
+
+If an internal pullup/pulldown is required for the IO, it can be enabled with the _OPTIONAL_ `HOLD_PIN_PULLUP` or `HOLD_PIN_PULLDOWN` macros. If neither are defined, then no pullup/pulldown will be enabled for the io pin.
+
+This switch is NOT dynamic. Once the bootloader has sensed this pin and decided not to run the application, then a change in this IO will not, itself, then cause the Application to run, without also resetting the board.
+
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..869fdfe2
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,41 @@
+
+
+## Security
+
+Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
+
+If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
+
+## Reporting Security Issues
+
+**Please do not report security vulnerabilities through public GitHub issues.**
+
+Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
+
+If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
+
+You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
+
+Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
+
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
+ * Full paths of source file(s) related to the manifestation of the issue
+ * The location of the affected source code (tag/branch/commit or direct URL)
+ * Any special configuration required to reproduce the issue
+ * Step-by-step instructions to reproduce the issue
+ * Proof-of-concept or exploit code (if possible)
+ * Impact of the issue, including how an attacker might exploit the issue
+
+This information will help us triage your report more quickly.
+
+If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
+
+## Preferred Languages
+
+We prefer all communications to be in English.
+
+## Policy
+
+Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
+
+
diff --git a/boards/arcade_itsybitsy_m4/ili9341.cf2 b/boards/arcade_itsybitsy_m4/ili9341.cf2
new file mode 100644
index 00000000..13c82a58
--- /dev/null
+++ b/boards/arcade_itsybitsy_m4/ili9341.cf2
@@ -0,0 +1,6 @@
+DISPLAY_CFG0 = 0xc8
+DISPLAY_CFG1 = 0x0018ff
+DISPLAY_CFG2 = 50
+DISPLAY_WIDTH = 320
+DISPLAY_HEIGHT = 240
+DISPLAY_TYPE = 9341
diff --git a/boards/pewpew_m4/board_config.h b/boards/pewpew_m4/board_config.h
index da0652b7..9a98bd55 100644
--- a/boards/pewpew_m4/board_config.h
+++ b/boards/pewpew_m4/board_config.h
@@ -45,7 +45,8 @@ const uint32_t config_data[] = {
36, 0x10, // PIN_DISPLAY_DC = PA16
37, 0xa0, // DISPLAY_WIDTH = 160
38, 0x80, // DISPLAY_HEIGHT = 128
- 39, 0x20180, // DISPLAY_CFG0 = 0x20180
+ //39, 0x80, // DISPLAY_CFG0 = 0x80 (prototype)
+ 39, 0x20180, // DISPLAY_CFG0 = 0x20180 (sold version)
40, 0x12c2d, // DISPLAY_CFG1 = 0x12c2d
41, 0x18, // DISPLAY_CFG2 = 0x18
43, 0x11, // PIN_DISPLAY_RST = PA17
diff --git a/boards/robohatmm1_m0/board.mk b/boards/robohatmm1_m0/board.mk
deleted file mode 100644
index 0a90fdf6..00000000
--- a/boards/robohatmm1_m0/board.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-CHIP_FAMILY = samd21
-CHIP_VARIANT = SAMD21G18A
diff --git a/boards/robohatmm1_m0/board_config.h b/boards/robohatmm1_m0/board_config.h
deleted file mode 100644
index 0268a6f3..00000000
--- a/boards/robohatmm1_m0/board_config.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef BOARD_CONFIG_H
-#define BOARD_CONFIG_H
-
-#define CRYSTALLESS 1
-
-#define VENDOR_NAME "Robotics Masters"
-#define PRODUCT_NAME "Robo HAT MM1"
-#define VOLUME_LABEL "ROBOM0BOOT"
-#define INDEX_URL "https://roboticsmasters.co"
-#define BOARD_ID "SAMD21G18A-robohat-v8"
-
-#define USB_VID 0x1209
-#define USB_PID 0x4D44
-
-#define LED_PIN PIN_PB22
-
-#endif
diff --git a/inc/uf2.h b/inc/uf2.h
index 6d13c786..6f195bf4 100644
--- a/inc/uf2.h
+++ b/inc/uf2.h
@@ -267,6 +267,9 @@ void system_init(void);
#define LED_TICK led_tick
#define PINOP(pin, OP) (PORT->Group[(pin) / 32].OP.reg = (1 << ((pin) % 32)))
+#define PINIP(pin) (((PORT->Group[(pin) / 32].IN.reg) >> ((pin) % 32)) & 0x1)
+#define PINCFG(pin) (PORT->Group[(pin) / 32].PINCFG[(pin) % 32].reg)
+#define PINMUX(pin) (PORT->Group[(pin) / 32].PMUX[((pin) % 32)/2].reg)
void led_tick(void);
void led_signal(void);
diff --git a/lib/cmsis/CMSIS/Include/core_cmFunc.h b/lib/cmsis/CMSIS/Include/core_cmFunc.h
index 85e36d48..bdd4aa38 100644
--- a/lib/cmsis/CMSIS/Include/core_cmFunc.h
+++ b/lib/cmsis/CMSIS/Include/core_cmFunc.h
@@ -426,7 +426,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
- __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
+ __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : );
}
@@ -454,7 +454,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
// : "sp" removed from clobber list to avoid gcc 9 warning.
- __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack));
+ __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : );
}
diff --git a/lib/same54/svd/ATSAME54P20A.svd b/lib/same54/svd/ATSAME54P20A.svd
index 353460e1..f76e985e 100644
--- a/lib/same54/svd/ATSAME54P20A.svd
+++ b/lib/same54/svd/ATSAME54P20A.svd
@@ -12723,7 +12723,7 @@
GENCTRL0
Generic Clock Generator Control 0 Synchronization Busy bits
2
- 1
+ 12
read-only
GENCTRL0Select
@@ -12793,7 +12793,7 @@
GENCTRL1
Generic Clock Generator Control 1 Synchronization Busy bits
3
- 1
+ 12
read-only
GENCTRL1Select
@@ -12863,7 +12863,7 @@
GENCTRL2
Generic Clock Generator Control 2 Synchronization Busy bits
4
- 1
+ 12
read-only
GENCTRL2Select
@@ -12933,7 +12933,7 @@
GENCTRL3
Generic Clock Generator Control 3 Synchronization Busy bits
5
- 1
+ 12
read-only
GENCTRL3Select
@@ -13003,7 +13003,7 @@
GENCTRL4
Generic Clock Generator Control 4 Synchronization Busy bits
6
- 1
+ 12
read-only
GENCTRL4Select
@@ -13073,7 +13073,7 @@
GENCTRL5
Generic Clock Generator Control 5 Synchronization Busy bits
7
- 1
+ 12
read-only
GENCTRL5Select
@@ -13143,7 +13143,7 @@
GENCTRL6
Generic Clock Generator Control 6 Synchronization Busy bits
8
- 1
+ 12
read-only
GENCTRL6Select
@@ -13213,7 +13213,7 @@
GENCTRL7
Generic Clock Generator Control 7 Synchronization Busy bits
9
- 1
+ 12
read-only
GENCTRL7Select
@@ -13283,7 +13283,7 @@
GENCTRL8
Generic Clock Generator Control 8 Synchronization Busy bits
10
- 1
+ 12
read-only
GENCTRL8Select
@@ -13353,7 +13353,7 @@
GENCTRL9
Generic Clock Generator Control 9 Synchronization Busy bits
11
- 1
+ 12
read-only
GENCTRL9Select
@@ -13423,7 +13423,7 @@
GENCTRL10
Generic Clock Generator Control 10 Synchronization Busy bits
12
- 1
+ 12
read-only
GENCTRL10Select
@@ -13493,7 +13493,7 @@
GENCTRL11
Generic Clock Generator Control 11 Synchronization Busy bits
13
- 1
+ 12
read-only
GENCTRL11Select
@@ -23319,12 +23319,159 @@
Peripheral Multiplexing for Even-Numbered Pin
0
4
+
+ PMUXESelect
+
+ A
+ Peripheral function A selected
+ 0x0
+
+
+ B
+ Peripheral function B selected
+ 0x1
+
+
+ C
+ Peripheral function C selected
+ 0x2
+
+
+ D
+ Peripheral function D selected
+ 0x3
+
+
+ E
+ Peripheral function E selected
+ 0x4
+
+
+ F
+ Peripheral function F selected
+ 0x5
+
+
+ G
+ Peripheral function G selected
+ 0x6
+
+
+ H
+ Peripheral function H selected
+ 0x7
+
+
+ I
+ Peripheral function I selected
+ 0x8
+
+
+ J
+ Peripheral function J selected
+ 0x9
+
+
+ K
+ Peripheral function K selected
+ 0xA
+
+
+ L
+ Peripheral function L selected
+ 0xB
+
+
+ M
+ Peripheral function M selected
+ 0xC
+
+
+ N
+ Peripheral function N selected
+ 0xD
+
+
PMUXO
Peripheral Multiplexing for Odd-Numbered Pin
4
4
+
+ PMUXOSelect
+
+ A
+ Peripheral function A selected
+ 0x0
+
+
+ B
+ Peripheral function B selected
+ 0x1
+
+
+ C
+ Peripheral function C selected
+ 0x2
+
+
+ D
+ Peripheral function D selected
+ 0x3
+
+
+ E
+ Peripheral function E selected
+ 0x4
+
+
+ F
+ Peripheral function F selected
+ 0x5
+
+
+ G
+ Peripheral function G selected
+ 0x6
+
+
+ H
+ Peripheral function H selected
+ 0x7
+
+
+ I
+ Peripheral function I selected
+ 0x8
+
+
+ J
+ Peripheral function J selected
+ 0x9
+
+
+ K
+ Peripheral function K selected
+ 0xA
+
+
+ L
+ Peripheral function L selected
+ 0xB
+
+
+ M
+ Peripheral function M selected
+ 0xC
+
+
+ N
+ Peripheral function N selected
+ 0xD
+
+
+
@@ -28457,7 +28604,7 @@
Host Control 1
0x028
8
- 0xE00
+ 0x00
LEDCTRL
@@ -28581,7 +28728,7 @@
HC1R
0x028
8
- 0xE00
+ 0x00
DW
@@ -33068,6 +33215,39 @@
Operating Mode
2
3
+
+ MODESelect
+
+ USART_EXT_CLK
+ USART mode with external clock
+ 0x0
+
+
+ USART_INT_CLK
+ USART mode with internal clock
+ 0x1
+
+
+ SPI_SLAVE
+ SPI mode with external clock
+ 0x2
+
+
+ SPI_MASTER
+ SPI mode with internal clock
+ 0x3
+
+
+ I2C_SLAVE
+ I2C mode with external clock
+ 0x4
+
+
+ I2C_MASTER
+ I2C mode with internal clock
+ 0x5
+
+
RUNSTDBY
@@ -33883,6 +34063,39 @@
Operating Mode
2
3
+
+ MODESelect
+
+ USART_EXT_CLK
+ USART mode with external clock
+ 0x0
+
+
+ USART_INT_CLK
+ USART mode with internal clock
+ 0x1
+
+
+ SPI_SLAVE
+ SPI mode with external clock
+ 0x2
+
+
+ SPI_MASTER
+ SPI mode with internal clock
+ 0x3
+
+
+ I2C_SLAVE
+ I2C mode with external clock
+ 0x4
+
+
+ I2C_MASTER
+ I2C mode with internal clock
+ 0x5
+
+
RUNSTDBY
@@ -34283,6 +34496,39 @@
Operating Mode
2
3
+
+ MODESelect
+
+ USART_EXT_CLK
+ USART mode with external clock
+ 0x0
+
+
+ USART_INT_CLK
+ USART mode with internal clock
+ 0x1
+
+
+ SPI_SLAVE
+ SPI mode with external clock
+ 0x2
+
+
+ SPI_MASTER
+ SPI mode with internal clock
+ 0x3
+
+
+ I2C_SLAVE
+ I2C mode with external clock
+ 0x4
+
+
+ I2C_MASTER
+ I2C mode with internal clock
+ 0x5
+
+
RUNSTDBY
diff --git a/scripts/bin2uf2.js b/scripts/bin2uf2.js
index 69acc840..c4e9b141 100644
--- a/scripts/bin2uf2.js
+++ b/scripts/bin2uf2.js
@@ -13,7 +13,7 @@ const UF2_MAGIC_END = 0x0AB16F30 // Ditto
let numBlocks = (buf.length + 255) >> 8
let outp = []
for (let pos = 0; pos < buf.length; pos += 256) {
- let bl = new Buffer(512)
+ let bl = Buffer.alloc(512)
for (let i = 0; i < 512; ++i)
bl[i] = 0 // just in case
bl.writeUInt32LE(UF2_MAGIC_START0, 0)
@@ -34,4 +34,4 @@ if (numBlocks != outp.length) throw "oops";
let outn = process.argv[3] || "flash.uf2"
fs.writeFileSync(outn, Buffer.concat(outp))
-console.log(`Wrote ${numBlocks} blocks to ${outn}`)
\ No newline at end of file
+console.log(`Wrote ${numBlocks} blocks to ${outn}`)
diff --git a/scripts/dbgtool.js b/scripts/dbgtool.js
index f0c25130..416ec394 100755
--- a/scripts/dbgtool.js
+++ b/scripts/dbgtool.js
@@ -103,7 +103,7 @@ function main() {
if (err) {
fatal("error: " + err.message)
}
- let buf = new Buffer(logSize)
+ let buf = Buffer.alloc(logSize)
for (let l of stdout.split(/\r?\n/)) {
let m = /^M\((\d+)\)\s*=\s*(\d+)/.exec(l)
if (m) {
diff --git a/scripts/gendata.js b/scripts/gendata.js
index b814b787..50ab18bd 100644
--- a/scripts/gendata.js
+++ b/scripts/gendata.js
@@ -3,7 +3,7 @@ let fs = require("fs")
let buildPath = process.argv[2]
let binName = buildPath + "/" + process.argv[3]
let buf = fs.readFileSync(binName)
-let tail = new Buffer(8192 - buf.length)
+let tail = Buffer.alloc(8192 - buf.length)
if (buf.length > 8192) {
console.error("Bootloader too big!")
process.exit(1)
diff --git a/src/cdc_enumerate.c b/src/cdc_enumerate.c
index 2626c89f..e04ba228 100644
--- a/src/cdc_enumerate.c
+++ b/src/cdc_enumerate.c
@@ -721,7 +721,7 @@ uint32_t USB_WriteCore(const void *pData, uint32_t length, uint8_t ep_num, bool
//* \brief Send zero length packet through the control endpoint
//*----------------------------------------------------------------------------
void AT91F_USB_SendZlp(void) {
- uint8_t c;
+ uint8_t c = 0;
USB_Write(&c, 0, 0);
}
diff --git a/src/fat.c b/src/fat.c
index 70da28fb..eb47666c 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -115,11 +115,11 @@ static const FAT_BootBlock BootBlock = {
.FATCopies = 2,
.RootDirectoryEntries = (ROOT_DIR_SECTORS * DIRENTRIES_PER_SECTOR),
.TotalSectors16 = NUM_FAT_BLOCKS - 2,
- .MediaDescriptor = 0xF8,
+ .MediaDescriptor = 0xf0, // typical for unpartitioned disks
.SectorsPerFAT = SECTORS_PER_FAT,
.SectorsPerTrack = 1,
.Heads = 1,
- .PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8
+ .PhysicalDriveNum = 0x00, // to match MediaDescriptor of 0xf0
.ExtendedBootSig = 0x29,
.VolumeSerialNumber = 0x00420042,
.VolumeLabel = VOLUME_LABEL,
@@ -152,7 +152,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
sectionIdx -= SECTORS_PER_FAT; // second FAT is same as the first...
#if USE_FAT
if (sectionIdx == 0) {
- data[0] = 0xf0;
+ data[0] = 0xf0; // must match MediaDescriptor
// WARNING -- code presumes only one NULL .content for .UF2 file
// and all non-NULL .content fit in one sector
// and requires it be the last element of the array
diff --git a/src/init_samd51.c b/src/init_samd51.c
index a4525ffc..8a145823 100644
--- a/src/init_samd51.c
+++ b/src/init_samd51.c
@@ -8,8 +8,8 @@ void system_init(void) {
NVMCTRL->CTRLA.bit.AUTOWS = 1;
// Output GCLK0 to Metro M4 D5. This way we can see if/when we mess it up.
- // PORT->Group[1].PINCFG[14].bit.PMUXEN = true;
- // PORT->Group[1].PMUX[7].bit.PMUXE = 12;
+ //PORT->Group[1].PINCFG[14].bit.PMUXEN = true;
+ //PORT->Group[1].PMUX[7].bit.PMUXE = 12;
/* Software reset the module to ensure it is re-initialized correctly */
/* Note: Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete.
diff --git a/src/main.c b/src/main.c
index 095fa0a0..03378ab6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -98,6 +98,30 @@ extern int8_t led_tick_step;
static void check_start_application(void) {
uint32_t app_start_address;
+// Check if there is an IO which will hold us inside the bootloader.
+#if defined(HOLD_PIN) && defined(HOLD_STATE)
+ PORT_PINCFG_Type pincfg = {0};
+ pincfg.bit.PMUXEN = false;
+ pincfg.bit.INEN = true;
+ pincfg.bit.DRVSTR = true;
+
+ PINOP(HOLD_PIN, DIRCLR); // Pin is an input
+
+ #if defined(HOLD_PIN_PULLUP)
+ pincfg.bit.PULLEN = true;
+ PINOP(HOLD_PIN, OUTSET); // Pin is pulled up.
+ #elif defined(HOLD_PIN_PULLDOWN)
+ pincfg.bit.PULLEN = true;
+ PINOP(HOLD_PIN, OUTCLR); // Pin is pulled up.
+ #endif
+ PINCFG(HOLD_PIN) = pincfg.reg;
+
+ if (PINIP(HOLD_PIN) == HOLD_STATE) {
+ /* Stay in bootloader */
+ return;
+ }
+#endif
+
/* Load the Reset Handler address of the application */
app_start_address = *(uint32_t *)(APP_START_ADDRESS + 4);
diff --git a/src/msc.c b/src/msc.c
index fe1cb9cf..02d04148 100644
--- a/src/msc.c
+++ b/src/msc.c
@@ -84,7 +84,7 @@ void msc_reset(void) {
//! Structure to receive a CBW packet
static struct usb_msc_cbw udi_msc_cbw;
//! Structure to send a CSW packet
-static struct usb_msc_csw udi_msc_csw = {.dCSWSignature = CPU_TO_BE32(USB_CSW_SIGNATURE)};
+static struct usb_msc_csw udi_msc_csw = {.dCSWSignature = cpu_to_le32(USB_CSW_SIGNATURE)};
//! Structure with current SCSI sense data
static struct scsi_request_sense_data udi_msc_sense;
@@ -281,7 +281,7 @@ bool try_read_cbw(struct usb_msc_cbw *cbw, uint8_t ep, PacketBuffer *handoverCac
#if USE_MSC_CHECKS
// Check CBW integrity:
// transfer status/CBW length/CBW signature
- if ((sizeof(*cbw) != nb_received) || (cbw->dCBWSignature != CPU_TO_BE32(USB_CBW_SIGNATURE))) {
+ if ((sizeof(*cbw) != nb_received) || (cbw->dCBWSignature != cpu_to_le32(USB_CBW_SIGNATURE))) {
if (handoverCache)
resetIntoBootloader();
// (5.2.1) Devices receiving a CBW with an invalid signature should
@@ -783,7 +783,7 @@ static void handover_flash(UF2_HandoverArgs *handover, PacketBuffer *handoverCac
static void process_handover_initial(UF2_HandoverArgs *handover, PacketBuffer *handoverCache,
WriteState *state) {
struct usb_msc_csw csw = {.dCSWTag = handover->cbw_tag,
- .dCSWSignature = CPU_TO_BE32(USB_CSW_SIGNATURE),
+ .dCSWSignature = cpu_to_le32(USB_CSW_SIGNATURE),
.bCSWStatus = USB_CSW_STATUS_PASS,
.dCSWDataResidue = 0};
// write out the block passed from user space
@@ -807,7 +807,7 @@ static void process_handover(UF2_HandoverArgs *handover, PacketBuffer *handoverC
}
struct usb_msc_csw csw = {.dCSWTag = cbw.dCBWTag,
- .dCSWSignature = CPU_TO_BE32(USB_CSW_SIGNATURE),
+ .dCSWSignature = cpu_to_le32(USB_CSW_SIGNATURE),
.bCSWStatus = USB_CSW_STATUS_PASS,
.dCSWDataResidue = le32_to_cpu(cbw.dCBWDataTransferLength)};
diff --git a/src/screen.c b/src/screen.c
index 13806d2e..3e644bd4 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -206,8 +206,10 @@ static void sendCmdSeq(const uint8_t *buf) {
static uint32_t palXOR;
static void setAddrWindow(int x, int y, int w, int h) {
- uint8_t cmd0[] = {ST7735_RASET, 0, (uint8_t)x, 0, (uint8_t)(x + w - 1)};
- uint8_t cmd1[] = {ST7735_CASET, 0, (uint8_t)y, 0, (uint8_t)(y + h - 1)};
+ w += x - 1;
+ h += y - 1;
+ uint8_t cmd0[] = {ST7735_RASET, 0, (uint8_t)x, (uint8_t)(w >> 8), (uint8_t)w};
+ uint8_t cmd1[] = {ST7735_CASET, 0, (uint8_t)y, (uint8_t)(h >> 8), (uint8_t)h};
sendCmd(cmd1, sizeof(cmd1));
sendCmd(cmd0, sizeof(cmd0));
}
@@ -457,9 +459,12 @@ void screen_init() {
uint32_t offY = (cfg0 >> 16) & 0xff;
//uint32_t freq = (cfg2 & 0xff);
+ offX += (CFG(DISPLAY_WIDTH) - DISPLAY_WIDTH) / 2;
+ offY += (CFG(DISPLAY_HEIGHT) - DISPLAY_HEIGHT) / 2;
+
// DMESG("configure screen: FRMCTR1=%p MADCTL=%p SPI at %dMHz", frmctr1, madctl, freq);
configure(madctl, frmctr1);
- setAddrWindow(offX, offY, CFG(DISPLAY_WIDTH), CFG(DISPLAY_HEIGHT));
+ setAddrWindow(offX, offY, DISPLAY_WIDTH, DISPLAY_HEIGHT);
memset(fb, 0, sizeof(fb));
}