Skip to content

Commit 5e0dc3c

Browse files
author
Zihan XU
committed
release: version 0.1.0
- add hpm5300evk support - add hpm5301evklite support Signed-off-by: Zihan XU <zihan.xu@hpmicro.com>
1 parent 45d786d commit 5e0dc3c

File tree

567 files changed

+207768
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

567 files changed

+207768
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Arduino core for the HPMicro boards
2+
3+
The Arduino HPMicro project is an open source project to support the development of Arduino-compatible boards based on the HPMicro SoC.
4+
5+
#### Need help or have a question? [Open a new Issue or search for existing issues](https://github.com/hpmicro/arduino/issues)
6+
7+
## Supported Boards
8+
9+
Here are the boards supported by the Arduino HPMicro project:
10+
11+
| **Board** | **Soc** | **schematic diagram** | **Pin Informations** |
12+
|----------|:---------------:|:--------------:|:------------------:|
13+
| HPM5300EVK | HPM5361 | [HPM5300](http://www.hpmicro.com/down.aspx?DId=3d0cc6ad-dd0b-4ed2-a3bb-4c3b8807dd30&LId=&SkipL=T) | [HPM5300EVK Pin Infos](https://github.com/hpmicro/arduino/blob/main/variants/hpm5300evk/README_hpm5300evk_Arduino_en.md) |
14+
| HPM5301EVKLITE | HPM5301 | | [HPM5301EVKLITE Pin Infos](https://github.com/hpmicro/arduino/blob/main/variants/hpm5301evklite/README_hpm5301evklite_Arduino_en.md) |

boards.txt

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Copyright (c) 2024 HPMicro
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
#
4+
# For more info:
5+
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
6+
7+
menu.opt=Optimize
8+
menu.upload_method=Bootloader Mode
9+
menu.build_type=Build Type
10+
11+
##############################################################
12+
HPM5300EVK.name=HPM5300EVK
13+
14+
HPM5300EVK.build.board=hpm5300evk
15+
HPM5300EVK.build.arch=riscv32
16+
HPM5300EVK.build.soc_cfg=hpm5300
17+
HPM5300EVK.build.f_cpu=480000000L
18+
HPM5300EVK.build.mcu=HPM5361
19+
HPM5300EVK.build.soc_series=HPM5300
20+
HPM5300EVK.build.soc_flags="-DSOC_HAS_I2C0=1" "-DSOC_HAS_PWM=1" "-DSOC_HAS_RNG=1"
21+
HPM5300EVK.build.jlink_soc=HPM5361xCBx
22+
HPM5300EVK.vid=0x34B7
23+
HPM5300EVK.pid=0x0005
24+
HPM5300EVK.upload.vid=0x34B7
25+
HPM5300EVK.upload.pid=0x0005
26+
HPM5300EVK.build.core=hpmicro
27+
HPM5300EVK.build.cpu_flags=
28+
HPM5300EVK.build.variant=hpm5300evk
29+
HPM5300EVK.upload.tool=Serial
30+
31+
#-- Optimizations
32+
HPM5300EVK.menu.opt.osstd=Smallest (default)
33+
34+
HPM5300EVK.menu.opt.o1std=Fast (-O1)
35+
HPM5300EVK.menu.opt.o1std.build.flags.optimize=-O1
36+
HPM5300EVK.menu.opt.o1std.build.flags.ldspecs=
37+
38+
HPM5300EVK.menu.opt.o2std=Faster (-O2)
39+
HPM5300EVK.menu.opt.o2std.build.flags.optimize=-O2
40+
HPM5300EVK.menu.opt.o2std.build.flags.ldspecs=
41+
42+
HPM5300EVK.menu.opt.o3std=Fastest (-O3)
43+
HPM5300EVK.menu.opt.o3std.build.flags.optimize=-O3
44+
HPM5300EVK.menu.opt.o3std.build.flags.ldspecs=
45+
46+
HPM5300EVK.menu.opt.ogstd=Debug (-g)
47+
HPM5300EVK.menu.opt.ogstd.build.flags.optimize=-Og
48+
HPM5300EVK.menu.opt.ogstd.build.flags.ldspecs=
49+
50+
HPM5300EVK.menu.build_type.flash=FLASH
51+
HPM5300EVK.menu.build_type.flash.build.linker_file=flash_xip
52+
HPM5300EVK.menu.build_type.flash.build.build_type_flag="-DFLASH_XIP"
53+
HPM5300EVK.menu.build_type.flash.build.build_type=FLASH
54+
55+
HPM5300EVK.menu.build_type.ram=RAM
56+
HPM5300EVK.menu.build_type.ram.build.linker_file=ram
57+
HPM5300EVK.menu.build_type.ram.build.build_type_flag=
58+
HPM5300EVK.menu.build_type.ram.build.build_type=RAM
59+
60+
61+
################################################################################
62+
63+
#---------------------------- UPLOAD METHODS ---------------------------
64+
# Upload methods is designed to upload sketch to board by [BOOTROM] via USB(USB0) or Serial(UART0)
65+
#
66+
HPM5300EVK.menu.upload_method.DFUUploadMethod=USB
67+
HPM5300EVK.menu.upload_method.DFUUploadMethod.upload.protocol=gdb_bmp
68+
HPM5300EVK.menu.upload_method.DFUUploadMethod.upload.tool=bootrom_usb_upload
69+
70+
HPM5300EVK.menu.upload_method.serialMethod=Serial
71+
HPM5300EVK.menu.upload_method.serialMethod.upload.protocol=gdb_bmp
72+
HPM5300EVK.menu.upload_method.serialMethod.upload.tool=bootrom_serial_upload
73+
74+
##############################################################
75+
HPM5301EVKLITE.name=HPM5301EVKLITE
76+
77+
HPM5301EVKLITE.build.board=hpm5301evklite
78+
HPM5301EVKLITE.build.arch=riscv32
79+
HPM5301EVKLITE.build.soc_cfg=hpm5301
80+
HPM5301EVKLITE.build.f_cpu=480000000L
81+
HPM5301EVKLITE.build.mcu=HPM5301
82+
HPM5301EVKLITE.build.soc_series=HPM5300
83+
HPM5301EVKLITE.build.soc_flags="-DSOC_HAS_I2C2=1"
84+
HPM5301EVKLITE.build.jlink_soc=HPM5301xEGx
85+
HPM5301EVKLITE.vid=0x34B7
86+
HPM5301EVKLITE.pid=0x0005
87+
HPM5301EVKLITE.upload.vid=0x34B7
88+
HPM5301EVKLITE.upload.pid=0x0005
89+
HPM5301EVKLITE.build.core=hpmicro
90+
HPM5301EVKLITE.build.cpu_flags=
91+
HPM5301EVKLITE.build.variant=hpm5301evklite
92+
HPM5301EVKLITE.upload.tool=Serial
93+
94+
#-- Optimizations
95+
HPM5301EVKLITE.menu.opt.osstd=Smallest (default)
96+
97+
HPM5301EVKLITE.menu.opt.o1std=Fast (-O1)
98+
HPM5301EVKLITE.menu.opt.o1std.build.flags.optimize=-O1
99+
HPM5301EVKLITE.menu.opt.o1std.build.flags.ldspecs=
100+
101+
HPM5301EVKLITE.menu.opt.o2std=Faster (-O2)
102+
HPM5301EVKLITE.menu.opt.o2std.build.flags.optimize=-O2
103+
HPM5301EVKLITE.menu.opt.o2std.build.flags.ldspecs=
104+
105+
HPM5301EVKLITE.menu.opt.o3std=Fastest (-O3)
106+
HPM5301EVKLITE.menu.opt.o3std.build.flags.optimize=-O3
107+
HPM5301EVKLITE.menu.opt.o3std.build.flags.ldspecs=
108+
109+
HPM5301EVKLITE.menu.opt.ogstd=Debug (-g)
110+
HPM5301EVKLITE.menu.opt.ogstd.build.flags.optimize=-Og
111+
HPM5301EVKLITE.menu.opt.ogstd.build.flags.ldspecs=
112+
113+
HPM5301EVKLITE.menu.build_type.flash=FLASH
114+
HPM5301EVKLITE.menu.build_type.flash.build.linker_file=flash_xip
115+
HPM5301EVKLITE.menu.build_type.flash.build.build_type_flag="-DFLASH_XIP"
116+
HPM5301EVKLITE.menu.build_type.flash.build.build_type=FLASH
117+
118+
HPM5301EVKLITE.menu.build_type.ram=RAM
119+
HPM5301EVKLITE.menu.build_type.ram.build.linker_file=ram
120+
HPM5301EVKLITE.menu.build_type.ram.build.build_type_flag=
121+
HPM5301EVKLITE.menu.build_type.ram.build.build_type=RAM
122+
123+
################################################################################
124+
125+
#---------------------------- UPLOAD METHODS ---------------------------
126+
# Upload methods is designed to upload sketch to board by [BOOTROM] via USB(USB0) or Serial(UART0)
127+
#
128+
129+
HPM5301EVKLITE.menu.upload_method.serialMethod=Serial
130+
HPM5301EVKLITE.menu.upload_method.serialMethod.upload.protocol=gdb_bmp
131+
HPM5301EVKLITE.menu.upload_method.serialMethod.upload.tool=bootrom_serial_upload

cores/hpmicro/Arduino.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2024 HPMicro
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
8+
#ifndef Arduino_h
9+
#define Arduino_h
10+
11+
#include <stdbool.h>
12+
#include <stdint.h>
13+
#include <stdarg.h>
14+
#include <stddef.h>
15+
#include <stdio.h>
16+
#include "class/wirish_math.h"
17+
#include <string.h>
18+
#include <inttypes.h>
19+
#include "port/Common.h"
20+
#include "board.h"
21+
#include "arduino/pins_arduino.h"
22+
#include <class/HardwareSerial.h>
23+
#include <class/SPI.h>
24+
#include <class/Wire.h>
25+
#include <class/USBMouse.h>
26+
#include <class/USBKeyboard.h>
27+
#include "arduino/i2c_instance.h"
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif /* _HPMICRO_CORE_ARDUINO_H_ */
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* Copyright (c) 2024 HPMicro
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*
6+
*/
7+
#include "HardwareSerial.h"
8+
#include "arduino/pins_arduino.h"
9+
#include "hpm_soc.h"
10+
#include "hpm_gpio_drv.h"
11+
#include "hpm_uart_drv.h"
12+
#include "hpm_interrupt.h"
13+
#include "ring_buffer.h"
14+
HardwareSerial::HardwareSerial(uart_dev_t *usart_device)
15+
{
16+
this->usart_device = usart_device;
17+
}
18+
19+
void HardwareSerial::begin(uint32 baud)
20+
{
21+
begin(baud,SERIAL_8N1);
22+
}
23+
24+
void HardwareSerial::begin(uint32 baud, uint8_t config_arg)
25+
{
26+
27+
hpm_stat_t stat = status_fail;
28+
29+
this->irq_num = usart_device->irq_num;
30+
31+
rb_init(usart_device->rb, USART_RX_BUF_SIZE, usart_device->rx_buf);
32+
rb_init(usart_device->wb, USART_TX_BUF_SIZE, usart_device->tx_buf);
33+
34+
HPM_IOC->PAD[usart_device->tx_ioc_idx].FUNC_CTL = usart_device->tx_ioc_fun;
35+
HPM_IOC->PAD[usart_device->rx_ioc_idx].FUNC_CTL = usart_device->rx_ioc_fun;
36+
37+
if (usart_device->tx_pioc) {
38+
HPM_PIOC->PAD[usart_device->tx_ioc_idx].FUNC_CTL = usart_device->tx_pioc_fun;
39+
}
40+
if (usart_device->rx_pioc) {
41+
HPM_PIOC->PAD[usart_device->rx_ioc_idx].FUNC_CTL = usart_device->rx_pioc_fun;
42+
}
43+
44+
uart_config_t config = {0};
45+
uart_default_config(usart_device->base, &config);
46+
config.src_freq_in_hz = clock_get_frequency(usart_device->clock_name);
47+
config.baudrate = baud;
48+
switch (config_arg) {
49+
case SERIAL_5N1:
50+
config.word_length = word_length_5_bits;
51+
break;
52+
case SERIAL_6N1:
53+
config.word_length = word_length_6_bits;
54+
break;
55+
case SERIAL_7N1:
56+
config.word_length = word_length_7_bits;
57+
break;
58+
case SERIAL_5N2:
59+
config.word_length = word_length_5_bits;
60+
config.num_of_stop_bits = stop_bits_2;
61+
break;
62+
case SERIAL_6N2:
63+
config.word_length = word_length_6_bits;
64+
config.num_of_stop_bits = stop_bits_2;
65+
break;
66+
case SERIAL_7N2:
67+
config.word_length = word_length_7_bits;
68+
config.num_of_stop_bits = stop_bits_2;
69+
break;
70+
case SERIAL_8N2:
71+
config.num_of_stop_bits = stop_bits_2;
72+
break;
73+
case SERIAL_5E1:
74+
config.word_length = word_length_5_bits;
75+
config.parity = parity_even;
76+
break;
77+
case SERIAL_6E1:
78+
config.word_length = word_length_6_bits;
79+
config.parity = parity_even;
80+
break;
81+
case SERIAL_7E1:
82+
config.word_length = word_length_7_bits;
83+
config.parity = parity_even;
84+
break;
85+
case SERIAL_8E1:
86+
config.parity = parity_even;
87+
break;
88+
case SERIAL_5E2:
89+
config.word_length = word_length_5_bits;
90+
config.num_of_stop_bits = stop_bits_2;
91+
config.parity = parity_even;
92+
break;
93+
case SERIAL_6E2:
94+
config.word_length = word_length_6_bits;
95+
config.num_of_stop_bits = stop_bits_2;
96+
config.parity = parity_even;
97+
break;
98+
case SERIAL_7E2:
99+
config.word_length = word_length_7_bits;
100+
config.num_of_stop_bits = stop_bits_2;
101+
config.parity = parity_even;
102+
break;
103+
case SERIAL_8E2:
104+
config.num_of_stop_bits = stop_bits_2;
105+
config.parity = parity_even;
106+
break;
107+
case SERIAL_5O1:
108+
config.word_length = word_length_5_bits;
109+
config.parity = parity_odd;
110+
break;
111+
case SERIAL_6O1:
112+
config.word_length = word_length_6_bits;
113+
config.parity = parity_odd;
114+
break;
115+
case SERIAL_7O1:
116+
config.word_length = word_length_7_bits;
117+
config.parity = parity_odd;
118+
break;
119+
case SERIAL_8O1:
120+
config.parity = parity_odd;
121+
break;
122+
case SERIAL_5O2:
123+
config.word_length = word_length_5_bits;
124+
config.num_of_stop_bits = stop_bits_2;
125+
config.parity = parity_odd;
126+
break;
127+
case SERIAL_6O2:
128+
config.word_length = word_length_6_bits;
129+
config.num_of_stop_bits = stop_bits_2;
130+
config.parity = parity_odd;
131+
break;
132+
case SERIAL_7O2:
133+
config.word_length = word_length_7_bits;
134+
config.num_of_stop_bits = stop_bits_2;
135+
config.parity = parity_odd;
136+
break;
137+
case SERIAL_8O2:
138+
config.num_of_stop_bits = stop_bits_2;
139+
config.parity = parity_odd;
140+
break;
141+
default:
142+
break;
143+
}
144+
stat = uart_init(usart_device->base, &config);
145+
if (status_success != stat) {
146+
printf("Failed init HardwareSerial\n");
147+
while(1);
148+
}
149+
uart_enable_irq(usart_device->base, uart_intr_rx_data_avail_or_timeout);
150+
intc_m_enable_irq_with_priority(irq_num, 1);
151+
}
152+
153+
void HardwareSerial::end(void)
154+
{
155+
intc_m_disable_irq(irq_num);
156+
}
157+
158+
int HardwareSerial::read(void)
159+
{
160+
if(available()) {
161+
return rb_remove(usart_device->rb);
162+
} else {
163+
return -1;
164+
}
165+
}
166+
167+
int HardwareSerial::available(void) {
168+
return rb_full_count(this->usart_device->rb);
169+
}
170+
171+
int HardwareSerial::peek(void)
172+
{
173+
return rb_peek(this->usart_device->rb);
174+
}
175+
176+
int HardwareSerial::availableForWrite(void)
177+
{
178+
return this->usart_device->wb->size-rb_full_count(this->usart_device->wb);
179+
}
180+
181+
size_t HardwareSerial::write(unsigned char ch)
182+
{
183+
hpm_stat_t stat;
184+
stat = uart_send_byte(usart_device->base, ch);
185+
if (stat != status_success) {
186+
err_count++;
187+
}
188+
return 1;
189+
}
190+
191+
void HardwareSerial::flush(void)
192+
{
193+
while(!rb_is_empty(this->usart_device->wb)); // wait for TX buffer empty
194+
}

0 commit comments

Comments
 (0)