Skip to content

Commit 7e1c87f

Browse files
facchinmpillo79
authored andcommitted
UNO Q: initial import
1 parent 7b01324 commit 7e1c87f

File tree

8 files changed

+591
-0
lines changed

8 files changed

+591
-0
lines changed

boards.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,55 @@ opta.debug.cortex-debug.custom.request=attach
521521
opta.debug.svd_file={runtime.platform.path}/svd/STM32H747_CM7.svd
522522

523523
##############################################################################################################
524+
525+
unoq.name=Arduino UNO Q
526+
unoq.build.core=arduino
527+
unoq.build.crossprefix=arm-zephyr-eabi-
528+
unoq.build.compiler_path={runtime.tools.arm-zephyr-eabi-0.16.8.path}/bin/
529+
530+
unoq.menu.link_mode.dynamic=Dynamic
531+
unoq.menu.link_mode.static=Static
532+
unoq.menu.link_mode.static.build.link_mode=static
533+
unoq.menu.link_mode.static.upload.extension=bin-zsk.bin
534+
535+
unoq.build.zephyr_target=arduino_uno_q
536+
unoq.build.zephyr_args=
537+
unoq.build.variant=arduino_uno_q_stm32u585xx
538+
unoq.build.mcu=cortex-m33
539+
unoq.build.fpu=-mfpu=fpv5-sp-d16
540+
unoq.build.architecture=cortex-m33
541+
unoq.compiler.zephyr.arch.define=
542+
543+
unoq.build.float-abi=-mfloat-abi=hard
544+
unoq.build.extra_flags=
545+
unoq.build.postbuild.cmd="{tools.imgtool.path}/{tools.imgtool.cmd}" exit
546+
unoq.build.board=UNO_Q
547+
unoq.build.zephyr_hals=hal_stm32
548+
unoq.compiler.zephyr.arch.define=
549+
unoq.compiler.zephyr=
550+
unoq.vid.0=0x2341
551+
unoq.pid.0=0x0078
552+
unoq.upload_port.0.vid=0x2341
553+
unoq.upload_port.0.pid=0x0078
554+
unoq.upload.address=0x80F0000
555+
unoq.upload.target=stm32u585zitxq
556+
557+
unoq.upload.tool=remoteocd
558+
unoq.upload.tool.default=remoteocd
559+
unoq.upload.protocol=
560+
unoq.upload.transport=
561+
unoq.upload.vid=0x2341
562+
unoq.upload.pid=0x0078
563+
unoq.upload.interface=0
564+
unoq.upload.use_1200bps_touch=false
565+
unoq.upload.wait_for_upload_port=false
566+
unoq.upload.native_usb=true
567+
unoq.upload.maximum_size=1966080
568+
unoq.upload.maximum_data_size=523624
569+
570+
unoq.bootloader.tool=remoteocd
571+
unoq.bootloader.tool.default=remoteocd
572+
unoq.bootloader.file=zephyr-{build.variant}.elf
573+
unoq.bootloader.target=stm32u585zitxq
574+
575+
##########################################################################################

loader/fixups.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,31 @@ int maybe_flash_bootloader(void) {
178178
SYS_INIT(maybe_flash_bootloader, POST_KERNEL, CONFIG_FILE_SYSTEM_INIT_PRIORITY);
179179

180180
#endif
181+
182+
#if defined(CONFIG_BOARD_ARDUINO_UNO_Q)
183+
#include "matrix.inc"
184+
185+
#include "../variants/arduino_uno_q_stm32u585xx/variant.h"
186+
#include <stm32_ll_adc.h>
187+
#include <zephyr/devicetree.h>
188+
189+
static int enable_adc_reference(void) {
190+
uint8_t init_status;
191+
/* VREF+ is not connected to VDDA by default */
192+
/* Use 2.5V as reference (instead of 3.3V) for internal channels
193+
* calculation
194+
*/
195+
__HAL_RCC_SYSCFG_CLK_ENABLE();
196+
197+
/* VREF_OUT2 = 2.5 V */
198+
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(SYSCFG_VREFBUF_VOLTAGE_SCALE1);
199+
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE);
200+
201+
init_status = HAL_SYSCFG_EnableVREFBUF();
202+
__ASSERT(init_status == HAL_OK, "ADC Conversion value may be incorrect");
203+
204+
return init_status;
205+
}
206+
207+
SYS_INIT(enable_adc_reference, POST_KERNEL, 0);
208+
#endif

loader/llext_exports.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,19 @@ FORCE_EXPORT_SYM(__aeabi_dcmpge);
255255
#if defined (CONFIG_CPP)
256256
FORCE_EXPORT_SYM(__cxa_pure_virtual);
257257
#endif
258+
259+
#if defined(CONFIG_BOARD_ARDUINO_UNO_Q)
260+
FORCE_EXPORT_SYM(matrixBegin);
261+
FORCE_EXPORT_SYM(matrixWrite);
262+
FORCE_EXPORT_SYM(matrixPlay);
263+
FORCE_EXPORT_SYM(matrixGrayscaleWrite);
264+
FORCE_EXPORT_SYM(matrixSetGrayscaleBits);
265+
FORCE_EXPORT_SYM(matrixEnd);
266+
#endif
267+
268+
#if defined(CONFIG_FLASH)
269+
FORCE_EXPORT_SYM(flash_area_open);
270+
FORCE_EXPORT_SYM(flash_area_read);
271+
FORCE_EXPORT_SYM(flash_area_write);
272+
FORCE_EXPORT_SYM(flash_area_erase);
273+
#endif

loader/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ static int loader(const struct shell *sh) {
108108
return rc;
109109
}
110110

111+
#if defined(CONFIG_BOARD_ARDUINO_UNO_Q)
112+
void matrixBegin(void);
113+
matrixBegin();
114+
#endif
115+
111116
struct sketch_header_v1 *sketch_hdr = (struct sketch_header_v1 *)(header + 7);
112117
if (sketch_hdr->ver != 0x1 || sketch_hdr->magic != 0x2341) {
113118
printk("Invalid sketch header\n");

loader/matrix.inc

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
#include <zephyr/kernel.h>
2+
#include <zephyr/drivers/gpio.h>
3+
#include <zephyr/device.h>
4+
#include <zephyr/drivers/counter.h>
5+
#include <string.h>
6+
7+
static const uint8_t pins[][2] = {
8+
{ 0, 1 }, // 0
9+
{ 1, 0 },
10+
{ 0, 2 },
11+
{ 2, 0 },
12+
{ 1, 2 },
13+
{ 2, 1 },
14+
{ 0, 3 },
15+
{ 3, 0 },
16+
{ 1, 3 },
17+
{ 3, 1 },
18+
{ 2, 3 }, // 10
19+
{ 3, 2 },
20+
{ 0, 4 },
21+
{ 4, 0 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0, 10 }, // 90
99+
{ 10, 0 },
100+
{ 1, 10 },
101+
{ 10, 1 },
102+
{ 2, 10 },
103+
{ 10, 2 },
104+
{ 3, 10 },
105+
{ 10, 3 },
106+
{ 4, 10 },
107+
{ 10, 4 },
108+
{ 5, 10 }, // 100
109+
{ 10, 5 },
110+
{ 6, 10 },
111+
{ 10, 6 },
112+
};
113+
114+
115+
const int idxToPin(int idx) {
116+
return idx;
117+
}
118+
119+
#define NUM_MATRIX_LEDS 104
120+
static uint8_t __attribute__((aligned)) framebuffer[NUM_MATRIX_LEDS / 8];
121+
static uint8_t __attribute__((aligned)) framebuffer_color[NUM_MATRIX_LEDS];
122+
123+
static void turnLed(int idx, bool on) {
124+
GPIOF->MODER &= ~(0xFFFFFF);
125+
126+
if (on) {
127+
GPIOF->BSRR |= (1 << (idxToPin(pins[idx][0])) | 1 << (idxToPin(pins[idx][1]) + 16));
128+
GPIOF->MODER |= (1 << (idxToPin(pins[idx][0]) * 2) | 1 << (idxToPin(pins[idx][1]) * 2));
129+
}
130+
}
131+
132+
static uint32_t reverse(uint32_t x)
133+
{
134+
x = ((x >> 1) & 0x55555555u) | ((x & 0x55555555u) << 1);
135+
x = ((x >> 2) & 0x33333333u) | ((x & 0x33333333u) << 2);
136+
x = ((x >> 4) & 0x0f0f0f0fu) | ((x & 0x0f0f0f0fu) << 4);
137+
x = ((x >> 8) & 0x00ff00ffu) | ((x & 0x00ff00ffu) << 8);
138+
x = ((x >> 16) & 0xffffu) | ((x & 0xffffu) << 16);
139+
return x;
140+
}
141+
142+
static bool color = false;
143+
static uint8_t _max_grayscale_bits = 3;
144+
145+
static void timer_irq_handler_fn(const struct device *counter_dev, void *user_data)
146+
{
147+
static volatile int i_isr = 0;
148+
if (color) {
149+
static volatile int counter = 0;
150+
switch ((framebuffer_color[i_isr] * 8 / (1 << _max_grayscale_bits))) {
151+
case 0:
152+
turnLed(i_isr, false);
153+
break;
154+
case 1:
155+
turnLed(i_isr, counter % 31 == 0);
156+
break;
157+
case 2:
158+
turnLed(i_isr, counter % 23 == 0);
159+
break;
160+
case 3:
161+
turnLed(i_isr, counter % 15 == 0);
162+
break;
163+
case 4:
164+
turnLed(i_isr, counter % 9 == 0);
165+
break;
166+
case 5:
167+
turnLed(i_isr, counter % 5 == 0);
168+
break;
169+
case 6:
170+
turnLed(i_isr, counter % 3 == 0);
171+
break;
172+
case 7:
173+
turnLed(i_isr, true);
174+
break;
175+
}
176+
counter++;
177+
} else {
178+
turnLed(i_isr, ((framebuffer[i_isr >> 3] & (1 << (i_isr % 8))) != 0));
179+
}
180+
i_isr = (i_isr + 1) % NUM_MATRIX_LEDS;
181+
}
182+
183+
void matrixWrite(uint32_t* buf) {
184+
memcpy(framebuffer, buf, NUM_MATRIX_LEDS/8);
185+
color = false;
186+
}
187+
188+
void matrixGrayscaleWrite(uint8_t* buf) {
189+
memcpy(framebuffer_color, buf, NUM_MATRIX_LEDS);
190+
color = true;
191+
}
192+
193+
void matrixSetGrayscaleBits(uint8_t _max) {
194+
_max_grayscale_bits = _max;
195+
}
196+
197+
#define TIMER DT_NODELABEL(counter_matrix)
198+
199+
void matrixBegin() {
200+
const struct device *const counter_dev = DEVICE_DT_GET(TIMER);
201+
counter_start(counter_dev);
202+
203+
struct counter_top_cfg top_cfg;
204+
top_cfg.ticks = counter_us_to_ticks(counter_dev, 10);
205+
top_cfg.callback = timer_irq_handler_fn;
206+
top_cfg.user_data = &top_cfg;
207+
top_cfg.flags = 0;
208+
209+
int err = counter_set_top_value(counter_dev, &top_cfg);
210+
if (err) {
211+
printk("Failed to set counter_set_top_value");
212+
}
213+
214+
//uint32_t buf[4] = {0x38E22, 0x8A09375D, 0x824A288E, 0x38000000};
215+
/*
216+
uint32_t buf[4] = {
217+
0b00000000000000011100011100010001,
218+
0b01000101000001001001101110101110,
219+
0b11000001001001010001010001000111,
220+
0b00011100000000000000000000000000};
221+
*/
222+
uint32_t buf[4] = {
223+
0b01111111000000100000100000010000,
224+
0b01000000100000100000010001010000,
225+
0b00100001100000011111111000000000,
226+
0b00110000000000000000000000000000};
227+
for (int i = 0; i < 4 ; i++) {
228+
buf[i] = reverse(buf[i]);
229+
}
230+
//matrixWrite(buf);
231+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
CONFIG_LLEXT_STORAGE_WRITABLE=n
2+
CONFIG_HEAP_MEM_POOL_SIZE=32768
3+
CONFIG_SHELL_STACK_SIZE=32768
4+
CONFIG_MAIN_STACK_SIZE=32768
5+
CONFIG_LLEXT_HEAP_SIZE=128
6+
7+
CONFIG_FPU=y
8+
9+
CONFIG_ADC=y
10+
CONFIG_DAC=y
11+
CONFIG_PWM=y
12+
13+
CONFIG_ICACHE=y
14+
CONFIG_DCACHE=y
15+
CONFIG_CACHE_MANAGEMENT=y
16+
17+
CONFIG_DMA=y
18+
CONFIG_MEMC=y
19+
CONFIG_SPI_ASYNC=y
20+
CONFIG_SPI_STM32_INTERRUPT=y
21+
CONFIG_SPI_SLAVE=y
22+
23+
CONFIG_ARM_MPU=n
24+
25+
CONFIG_ENTROPY_GENERATOR=y
26+
CONFIG_TEST_RANDOM_GENERATOR=y
27+
28+
CONFIG_LOG_MODE_IMMEDIATE=n
29+
30+
CONFIG_COUNTER=y
31+
CONFIG_COUNTER_SHELL=y
32+
33+
CONFIG_DEBUG_THREAD_INFO=y
34+
35+
CONFIG_MAX_THREAD_BYTES=6
36+
CONFIG_DYNAMIC_THREAD=y
37+
CONFIG_DYNAMIC_THREAD_POOL_SIZE=2
38+
CONFIG_DYNAMIC_THREAD_ALLOC=y
39+
40+
#CONFIG_VIDEO=y
41+
#CONFIG_VIDEO_LOG_LEVEL_DBG=y
42+
#CONFIG_VIDEO_STM32_DCMI=y
43+
#CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=2
44+
#CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=200000
45+
#CONFIG_VIDEO_BUFFER_POOL_ALIGN=32
46+
#CONFIG_VIDEO_GC2145=y

0 commit comments

Comments
 (0)