Skip to content

Commit c97c6b8

Browse files
committed
fixed: make tinyUSB work well.
1 parent b18b585 commit c97c6b8

File tree

3 files changed

+67
-29
lines changed

3 files changed

+67
-29
lines changed

cores/arduino/main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,14 @@ int main( void )
7070
_wrap_body();
7171
return 0;
7272
}
73+
74+
#if defined(USE_TINYUSB)
75+
76+
// run TinyUSB background task when yield()
77+
extern "C" void yield(void)
78+
{
79+
tud_task();
80+
tud_cdc_write_flush();
81+
}
82+
83+
#endif

platform.txt

+55-28
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,29 @@ version=1.7.2
2828
compiler.warning_flags=-w
2929
compiler.warning_flags.none=-w
3030
compiler.warning_flags.default=
31-
compiler.warning_flags.more=-Wall
32-
compiler.warning_flags.all=-Wall -Wextra
31+
compiler.warning_flags.more=-Wall -Wno-expansion-to-defined
32+
compiler.warning_flags.all=-Wall -Wextra -Wno-expansion-to-defined
3333

34-
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
34+
compiler.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
3535
compiler.c.cmd=arm-none-eabi-gcc
36-
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}"""
37-
compiler.c.elf.cmd=arm-none-eabi-gcc
36+
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}"""
37+
compiler.c.elf.cmd=arm-none-eabi-g++
3838
compiler.c.elf.flags=-Os -Wl,--gc-sections -save-temps
3939
compiler.S.cmd=arm-none-eabi-gcc
4040
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
4141
compiler.cpp.cmd=arm-none-eabi-g++
42-
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}"""
42+
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}"""
4343
compiler.ar.cmd=arm-none-eabi-ar
4444
compiler.ar.flags=rcs
4545
compiler.objcopy.cmd=arm-none-eabi-objcopy
4646
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
47-
compiler.elf2hex.flags=-O binary
47+
compiler.elf2hex.bin.flags=-O binary
48+
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
4849
compiler.elf2hex.cmd=arm-none-eabi-objcopy
4950
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
5051
compiler.size.cmd=arm-none-eabi-size
5152
compiler.define=-DARDUINO=
53+
compiler.readelf.cmd=arm-none-eabi-readelf
5254

5355
# this can be overriden in boards.txt
5456
build.extra_flags=
@@ -69,7 +71,9 @@ compiler.ar.extra_flags=
6971
compiler.elf2hex.extra_flags=
7072

7173
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.0.path}/CMSIS/Device/ATMEL/"
72-
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
74+
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
75+
76+
compiler.libraries.ldflags=
7377

7478
# USB Flags
7579
# ---------
@@ -90,38 +94,41 @@ build.usb_manufacturer="Unknown"
9094
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
9195

9296
## Compile c++ files
93-
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
97+
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.cache_flags} {build.flags.debug} {build.flags.optimize} {build.flags.maxspi} {build.flags.maxqspi} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
9498

9599
## Compile S files
96100
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.cache_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
97101

98102
## Create archives
103+
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
104+
archive_file_path={build.path}/{archive_file}
99105
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
100106

101107
## Combine gc-sections, archives, and objects
102-
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" "-L{build.variant.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" --specs=nano.specs --specs=nosys.specs -Wl,--start-group {compiler.ldflags} {compiler.arm.cmsis.ldflags} {object_files} -lc_s -lm "{build.path}/{archive_file}" -Wl,--wrap,_write -Wl,--end-group
108+
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} "-L{build.variant.path}" -lm "{build.path}/{archive_file}" -Wl,--end-group
103109

104110
## Create output (bin file)
105-
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
111+
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
112+
113+
## Create output (hex file)
114+
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
115+
116+
build.preferred_out_format=bin
106117

107118
## Save hex
108-
recipe.output.tmp_file={build.project_name}.bin
109-
recipe.output.save_file={build.project_name}.{build.variant}.bin
119+
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
120+
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
110121

111122
## Compute size
112123
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
113124
recipe.size.regex=\.text\s+([0-9]+).*
114125

115-
116-
# Uploader tools
117-
# --------------
118-
119126
#
120127
# BOSSA
121128
#
122-
123-
tools.bossac.path={runtime.tools.bossac-1.7.0.path}
129+
tools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
124130
tools.bossac.cmd=bossac
131+
tools.bossac.cmd.windows=bossac.exe
125132

126133
tools.bossac.upload.params.verbose=-i -d
127134
tools.bossac.upload.params.quiet=
@@ -144,53 +151,73 @@ tools.bossac18.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.por
144151
tools.bossac18.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
145152
tools.bossac18.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
146153

154+
#
155+
# BOSSA (ignore binary size)
156+
#
157+
tools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
158+
tools.bossacI.cmd=bossac
159+
tools.bossacI.cmd.windows=bossac.exe
160+
161+
tools.bossacI.upload.params.verbose=-i -d
162+
tools.bossacI.upload.params.quiet=
163+
tools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
164+
165+
tools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
166+
167+
tools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
168+
tools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
169+
147170

148171
#
149172
# OpenOCD sketch upload
150173
#
151174

152-
tools.openocd.path={runtime.tools.openocd.path}
175+
tools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
153176
tools.openocd.cmd=bin/openocd
154177
tools.openocd.cmd.windows=bin/openocd.exe
155178

156179
tools.openocd.upload.params.verbose=-d2
157180
tools.openocd.upload.params.quiet=-d0
158-
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{{build.path}/{build.project_name}.bin}} verify reset 0x00002000; shutdown"
181+
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
182+
183+
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
184+
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
159185

186+
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
160187
tools.openocd.program.params.verbose=-d2
161188
tools.openocd.program.params.quiet=-d0
162-
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{{build.path}/{build.project_name}.elf}} verify reset; shutdown"
189+
tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
163190

164191
tools.openocd.erase.params.verbose=-d3
165192
tools.openocd.erase.params.quiet=-d0
166193
tools.openocd.erase.pattern=
167194

168-
tools.openocd.bootloader.params.verbose=-d3
195+
tools.openocd.bootloader.params.verbose=-d2
169196
tools.openocd.bootloader.params.quiet=-d0
170-
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f interface/{program.protocol}.cfg -c "{program.setup_command}" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{{runtime.platform.path}/bootloaders/{bootloader.file}}} verify reset; shutdown"
197+
tools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
171198

172199
#
173200
# OpenOCD sketch upload - version with configurable bootloader size
174201
# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
175202
#
176203

177-
tools.openocd-withbootsize.path={runtime.tools.openocd-0.9.0-arduino.path}
204+
tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
178205
tools.openocd-withbootsize.cmd=bin/openocd
179206
tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
180207

181208
tools.openocd-withbootsize.upload.params.verbose=-d2
182209
tools.openocd-withbootsize.upload.params.quiet=-d0
183-
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{{build.path}/{build.project_name}.bin}} verify reset {bootloader.size}; shutdown"
210+
tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
184211

185212
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
186213
tools.openocd-withbootsize.program.params.verbose=-d2
187214
tools.openocd-withbootsize.program.params.quiet=-d0
188-
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{{build.path}/{build.project_name}.elf}} verify reset; shutdown"
215+
tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
189216

190217
tools.openocd-withbootsize.erase.params.verbose=-d3
191218
tools.openocd-withbootsize.erase.params.quiet=-d0
192219
tools.openocd-withbootsize.erase.pattern=
193220

194221
tools.openocd-withbootsize.bootloader.params.verbose=-d2
195222
tools.openocd-withbootsize.bootloader.params.quiet=-d0
196-
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{{runtime.platform.path}/bootloaders/{bootloader.file}}} verify reset; shutdown"
223+
tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"

variants/XIAO_m0/variant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const PinDescription g_APinDescription[]=
4747

4848
// 14..16 - USB
4949
// --------------------
50-
{ PORTA, 22, PIO_SERCOM, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // GPIO 29 - Host USB (not used)
50+
{ PORTA, 28, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB Host enable
5151
{ PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM
5252
{ PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE } // USB/DP
5353

0 commit comments

Comments
 (0)