mirror of
https://github.com/cnlohr/lolra.git
synced 2026-06-15 07:19:25 +00:00
Compare commits
14 Commits
73a80f4099
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bb8c87519 | |||
| 77cfc9f3b7 | |||
| ae63b4208f | |||
| 1940782c3d | |||
| e5cd85ebf8 | |||
| 7f57e4b003 | |||
| 966076d5ed | |||
| ce7b9c05d1 | |||
| c7900d08b0 | |||
| 7f0f6ecb67 | |||
| 58aae1becd | |||
| 56ac27833b | |||
| 22c2149507 | |||
| e3ed2e9084 |
@@ -1,26 +1,74 @@
|
||||
# LoLRa
|
||||
|
||||
*Transmit 900MHz LoRa frames surprisingly far without a radio*
|
||||
Transmit 900MHz LoRa frames surprisingly far without a radio (And other radio shenanigans using ADCs, PWMs and I2S/SPI busses) including sending other RF data, as well as receiving RF signals (Though admittedly not a LoRa receiver).
|
||||
|
||||
* [Introduction](#introduction)
|
||||
* [Background](#background)
|
||||
* [LoRaWAN](#lorawan)
|
||||
* [Limitations](#limitations)
|
||||
* [Future Work](#future-work)
|
||||
* [Resources](#resources)
|
||||
* [Special Thanks](#special-thanks)
|
||||
* [Range Tests](#range-tests)
|
||||
If you are looking for the Hackaday 2024 microcontroller radio talk, you can <a href=https://cnlohr.github.io/lolra_talk>click here</a>.
|
||||
|
||||
## Introduction
|
||||
If you are looking for LoLRa Merch (Like t-shirts, etc.), <a href="https://cnlohr-shop.fourthwall.com/">click here</a>.
|
||||
|
||||
Firmware-only LoRa transmission, for a variety of processors. Send LoRa packets, without any radio, chips, external hardware or built-in radios at all on a variety of common, inexpensive processors. While not truly bit banging, this repository shows how using either a shift register (i.e. I2S or SPI port) or an APLL, you can send LoRa packets that can be decoded by commercial off the shelf LoRa gateways and other chips.
|
||||
* [Introduct and repo overview](#introduction-and-repo-overview)
|
||||
* LoRa
|
||||
* [Introduction (LoRa)](#introduction-lora)
|
||||
* [Background](#background)
|
||||
* [LoRaWAN](#lorawan)
|
||||
* [Limitations](#limitations)
|
||||
* [Future Work](#future-work)
|
||||
* [Resources](#resources)
|
||||
* [Special Thanks](#special-thanks)
|
||||
* [Range Tests](#range-tests)
|
||||
|
||||
> [!NOTE]
|
||||
> This repo is designed for use with ITU Region 2 (The Americas) targeting 902-928MHz. Code changes are needed for use in Region 1 (EU, Russia, Africa) to target 863-870MHz or Region 3 (Australia, China, India) to target 920-923MHz.
|
||||
> 1. Portions of code in this repo are under various licenses and cannot be trivially incorporated into other libraries, including some files containing a no-ai-training license for any of the RF-specific portions of the project. Be cautious when using code from this repo. See  for more information.
|
||||
> 2. The LoRa® and LoRaWAN® Mark and LoRa Logo are trademarks of Semtech Corporation.
|
||||
> 3. LoLRa is not associated with Semtech in any way whatsoever.
|
||||
> 4. This repo is designed for use with ITU Region 2 (The Americas) targeting 902-928MHz. Code changes are needed for use in Region 1 (EU, Russia, Africa) to target 863-870MHz or Region 3 (Australia, China, India) to target 920-923MHz.
|
||||
|
||||
> [!CAUTION]
|
||||
> Because we rely on harmonics and aliasing, the primary frequency components emitted by your microcontroller are going to be in portions of the RF spectrum where RF transmissions are banned. Please filter your output or perform your tests in an area where you are unlikely to leak significant RF. The overall EIRP output is genreally ≪300uW across the whole spectrum spread out over hundreds of emission frequencies, but there is virtually no way a device deliberately transmitting on these frequencies could ever pass FCC part 15 compliance, even with filtering.
|
||||
|
||||
|
||||
## Introduction and Repo Overview
|
||||
|
||||
I have always been fascinated with sending and receiving radio signals from microcontrollers that don't have dedicated radio hardware. This repo serves as a overview of many of the projects I've done to do this decoding, along with example code (Though some of it is restrictively licensed)
|
||||
|
||||
In general the repo is split up in to many projects, but categoriezed by device type.
|
||||
|
||||
* ch32v (Note, all examples require 8MHz (v203) or 24Mhz (v003) crystal oscillator)
|
||||
* General Note: All OLED displays used here are 128x128 SPI-mode OLED displays.
|
||||
* [ch32v003-adcrx](ch32v/ch32v003-adcrx) - prints quadrature values for receiving at 1/4 sample rate signals, or harmonics thereof. Specifically this is tuned to receiv CW on citizen band frequencies, specifically 27.000050 MHz
|
||||
* [ch32v003-lora](ch32v/ch32v003-lora) - Successful (but very poor) transmission of LoRa messages with a ch32v003.
|
||||
* [ch32v003-timer](ch32v/ch32v003-timer) - An attempt to use non-tabled dithering of PWM signals to send FM radio and/or 315MHz signals. *This does not work well* but it is included as a reference for dtrying to dither RF on the 003.
|
||||
* [ch32v003-txrx](ch32v/ch32v003-txrx) - Trying to send from one 003 to another 003 receiving. This does not work well - only about 1'.
|
||||
* [ch32v203-adcrx](ch32v203-adcrx) - Very basic quadrature decoding on a ch32v203.
|
||||
* [ch32v203-fft](ch32v203-fft) - Perform an FFT on a small window of samples on a ch32v203. This outputs to an OLED display. It doesn't keep up in realtime though. It also relies on <a href=https://gist.github.com/cnlohr/c4f9647a220781c005ff1a733dc9ed7f>fix_fft.h</a> (which cannot be distirbuted with this project because of a lack of license.
|
||||
* [**ch32v203-goertzel**](ch32v/ch32v203-goertzel) - Perform a full goertzel's tuning on an incoming ADC signal so that it can listen to multiple AM and NBFM radio stations from an ADC pin.
|
||||
* [lib/calculator.html](ch32v/lib/calculator.html) - webpage that can use webhid with ch32v203-goertzel.
|
||||
* [**ch32v203-lora**](ch32v/ch32v203-lora) - Proper transmission of LoRaWAN packets (from the tests outlined below).
|
||||
* [ch32v203-tx](ch32v/ch32v203-tx) - Very basic test, setup to just turn on a PWM on the ch32v203.
|
||||
* esp32-s2
|
||||
* [**loratest**](esp32-s2/loratest) - Full stack protocol for sending LoRa messages from an esp32-s2. (From range test)
|
||||
* [**narrow_fsk_test**](esp32-s2/narrow_fsk_test) - Very basic test using dithering and the PLL in the esp32-s2 to see how tight/narrow control is possible with the esp32-s2. This does not do a dithered closed loop, but would not be terribly hard to add.
|
||||
* [**videoending**](esp32-s2/videoending) - Mechanism for allowing an ESP32-S2 to FSK, hopping around to draw a picture in a spectrogram. This was used for the video ending.
|
||||
* esp8266
|
||||
* [example_125k_raw](esp8266/example_125k_raw) - Sending a raw 125kHz wide LoRa message.
|
||||
* [example_500k_raw](esp8266/example_500k_raw) - Sending a raw 500kHz wide LoRa message.
|
||||
* [**lorawan_example**](esp8266/lorawan_example) - Using the I2S bus on the ESP8266 to send a full-stack LoRaWAN message to the things network.
|
||||
* [non_lora_310_transmit](esp8266/non_lora_310_transmit) - Exmaple of how to transmit 310MHz OOK with an ESP8266.
|
||||
* lib
|
||||
* [aes-cbc-cmac.h](lib/aes-cbc-cmac.h) - Public Domain RFC4493 AES-CMAC header only library.
|
||||
* [LoRa-SDR-Code.h](lib/LoRa-SDR-Code.h) - MIT (unrestrictive) Licensed code to construct LoRa packets
|
||||
* [lorawan_simple.h](lib/lorawan_simple.h) - MIT (unrestrictive) Licensed code to construct LoRaWAN packets.
|
||||
* [rf_data_gen.h](lib/rf_data_gen.h) - Helper function for helping generate bit tables for I2S/SPI outpiut of carefully crafted signals.
|
||||
* [tiny-AES-c.h](lib/rf_data_gen.h) - Public Domain AES encryption/decryption library.
|
||||
* tools
|
||||
* [60-rtlsdr.rules](tools/60-rtlsdr.rules) - Make it so you can use your airspy from Linux as a user.
|
||||
* [complex_magsink_to_image.c](tools/complex_magsink_to_image.c) - Generate ultra high resolution (in time domain) waterfall views.
|
||||
* [testloradec.grc](tools/testloradec.grc) - Using gr_lora exmaple to decode LoRa in GNURadio
|
||||
|
||||
## Introduction (LoRa)
|
||||
|
||||
Firmware-only LoRa transmission, for a variety of processors. Send LoRa packets, without any radio, chips, external hardware or built-in radios at all on a variety of common, inexpensive processors. While not truly bit banging, this repository shows how using either a shift register (i.e. I2S or SPI port) or an APLL, you can send LoRa packets that can be decoded by commercial off the shelf LoRa gateways and other chips.
|
||||
|
||||
There are two major modes that this repository works with.
|
||||
|
||||
1. Transmission using a tunable PLL, creating a square wave, then using a harmonic (the 13th harmonic in the case of the ESP32-S2) and then transmitting the signal out a clock out pin.
|
||||
@@ -31,9 +79,6 @@ Click Below for the Youtube Video version of this page:
|
||||
|
||||
[](https://www.youtube.com/watch?v=eIdHBDSQHyw)
|
||||
|
||||
> [!NOTE]
|
||||
> Portions of code in this repo are under various licenses and cannot be trivially incorporated into other libraries without a bit of a mess, including a no-ai-training license for any of the RF-specific portions of the project. Be cautious when using code from this repo. See  for more information.
|
||||
|
||||
## Background
|
||||
|
||||
### Square waves, and images
|
||||
@@ -253,6 +298,13 @@ Low Overhead Radios Using Side-Channels](https://dl.acm.org/doi/abs/10.1145/3583
|
||||
* [Airspy Mini SDR](https://v3.airspy.us/product/a-airspy-mini/)
|
||||
* [LILYGO® T-Beam Meshtastic](https://www.lilygo.cc/products/t-beam-v1-1-esp32-lora-module)
|
||||
|
||||
### LoLRa Like Things
|
||||
* [Wirelessly control 49 MHz toy with I/O line flipping on Pi Pico](https://www.youtube.com/watch?v=K-6dos8Hvm8)
|
||||
|
||||
### Other Interesting Radio Links
|
||||
|
||||
* [Radio station snafu in Seattle bricks some Mazda infotainment systems](https://arstechnica.com/cars/2022/02/radio-station-snafu-in-seattle-bricks-some-mazda-infotainment-systems/)
|
||||
|
||||
## Special Thanks
|
||||
* @MustardTiger for a crazy amount of support work in this project
|
||||
* Willmore for the editing work
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// XXX TODO: Play with high bits of ADC control to see if there's a gain cicuit.
|
||||
|
||||
/**
|
||||
|
||||
MIT-like-non-ai-license
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
all : flash
|
||||
|
||||
TARGET:=adcrx
|
||||
TARGET_MCU:=CH32V003
|
||||
CH32V003FUN:=../ch32v003fun/ch32v003fun
|
||||
|
||||
ADDITIONAL_C_FILES+=../rv003usb/rv003usb/rv003usb.S ../rv003usb/rv003usb/rv003usb.c
|
||||
EXTRA_CFLAGS:=-I../rv003usb/lib -I../rv003usb/rv003usb -mstrict-align -Wno-unused-function
|
||||
|
||||
include ../ch32v003fun/ch32v003fun/ch32v003fun.mk
|
||||
|
||||
programmerclock :
|
||||
$(MINICHLINK)/minichlink -X ECLK 1:0:0:8:3
|
||||
|
||||
flash : cv_flash
|
||||
clean : cv_clean
|
||||
rm -rf rf_data_gen chirpbuff.dat chirpbuff.h chirpbuffinfo.h
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
THIS DOES NOT WORK DO NOT USE IT YET
|
||||
@@ -0,0 +1,378 @@
|
||||
/**
|
||||
|
||||
MIT-like-non-ai-license
|
||||
|
||||
Copyright (c) 2024 Charles Lohr "CNLohr"
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the two following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
In addition the following restrictions apply:
|
||||
|
||||
1. The Software and any modifications made to it may not be used for the
|
||||
purpose of training or improving machine learning algorithms, including but not
|
||||
limited to artificial intelligence, natural language processing, or data
|
||||
mining. This condition applies to any derivatives, modifications, or updates
|
||||
based on the Software code. Any usage of the Software in an AI-training dataset
|
||||
is considered a breach of this License.
|
||||
|
||||
2. The Software may not be included in any dataset used for training or
|
||||
improving machine learning algorithms, including but not limited to artificial
|
||||
intelligence, natural language processing, or data mining.
|
||||
|
||||
|
||||
3. Any person or organization found to be in violation of these restrictions
|
||||
will be subject to legal action and may be held liable for any damages
|
||||
resulting from such use.
|
||||
|
||||
If any term is unenforcable, other terms remain in-force.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
**/
|
||||
|
||||
// NOT LORA!!! -- but experimenting with the possibility of rx.
|
||||
|
||||
|
||||
#include "ch32v003fun.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "rv003usb.h"
|
||||
|
||||
uint8_t scratchout[15];
|
||||
volatile int outready = 0;
|
||||
uint8_t scratchin[255];
|
||||
volatile int inready = 0;
|
||||
|
||||
|
||||
#define PWM_PERIOD (28-1) //For 27.000500MHz
|
||||
#define QUADRATURE
|
||||
|
||||
uint32_t TQ = 128;
|
||||
|
||||
#define ADC_BUFFSIZE 256
|
||||
volatile uint16_t adc_buffer[ADC_BUFFSIZE];
|
||||
|
||||
void SetupADC()
|
||||
{
|
||||
// Reset the ADC to init all regs
|
||||
RCC->APB2PRSTR |= RCC_APB2Periph_ADC1;
|
||||
RCC->APB2PRSTR &= ~RCC_APB2Periph_ADC1;
|
||||
|
||||
// ADCCLK = 12 MHz => RCC_ADCPRE divide by 4
|
||||
RCC->CFGR0 &= ~RCC_ADCPRE; // Clear out the bis in case they were set
|
||||
RCC->CFGR0 |= RCC_ADCPRE_DIV2; // Fastest possible (divide-by-2) NOTE: This is OUTSIDE the specified value in the datasheet.
|
||||
|
||||
// Set up single conversion on chl 7
|
||||
ADC1->RSQR1 = 0;
|
||||
ADC1->RSQR2 = 0;
|
||||
ADC1->RSQR3 = 6; // 0-9 for 8 ext inputs and two internals /// 7 or 6 means one of the ADC inputs.
|
||||
|
||||
// Not using injection group.
|
||||
|
||||
// PD4 is analog input chl 7 + 6
|
||||
GPIOD->CFGLR &= ~(0xf<<(4*4)); // CNF = 00: Analog, MODE = 00: Input
|
||||
GPIOD->CFGLR &= ~(0xf<<(4*6)); // CNF = 00: Analog, MODE = 00: Input
|
||||
|
||||
// Sampling time for channels. Careful: This has PID tuning implications.
|
||||
// Note that with 3 and 3,the full loop (and injection) runs at 138kHz.
|
||||
ADC1->SAMPTR2 = (0<<(3*7));
|
||||
|
||||
// Turn on ADC and set rule group to sw trig
|
||||
// 0 = Use TRGO event for Timer 1 to fire ADC rule.
|
||||
ADC1->CTLR2 = ADC_ADON | ADC_EXTTRIG | ADC_DMA;
|
||||
|
||||
// Reset calibration
|
||||
ADC1->CTLR2 |= ADC_RSTCAL;
|
||||
while(ADC1->CTLR2 & ADC_RSTCAL);
|
||||
|
||||
// Calibrate ADC
|
||||
ADC1->CTLR2 |= ADC_CAL;
|
||||
while(ADC1->CTLR2 & ADC_CAL);
|
||||
|
||||
// ADC_SCAN: Allow scanning.
|
||||
ADC1->CTLR1 = ADC_SCAN;
|
||||
|
||||
// Turn on DMA
|
||||
RCC->AHBPCENR |= RCC_AHBPeriph_DMA1;
|
||||
|
||||
//DMA1_Channel1 is for ADC
|
||||
DMA1_Channel1->PADDR = (uint32_t)&ADC1->RDATAR;
|
||||
DMA1_Channel1->MADDR = (uint32_t)adc_buffer;
|
||||
DMA1_Channel1->CNTR = ADC_BUFFSIZE;
|
||||
DMA1_Channel1->CFGR =
|
||||
DMA_M2M_Disable |
|
||||
DMA_Priority_VeryHigh |
|
||||
DMA_MemoryDataSize_HalfWord |
|
||||
DMA_PeripheralDataSize_HalfWord |
|
||||
DMA_MemoryInc_Enable |
|
||||
DMA_Mode_Circular |
|
||||
DMA_DIR_PeripheralSRC;
|
||||
|
||||
// Turn on DMA channel 1
|
||||
DMA1_Channel1->CFGR |= DMA_CFGR1_EN;
|
||||
|
||||
// Enable continuous conversion and DMA
|
||||
//ADC1->CTLR2 |= ADC_DMA | ADC_EXTSEL; //ADC_CONT
|
||||
|
||||
// start conversion
|
||||
ADC1->CTLR2 |= ADC_SWSTART;
|
||||
|
||||
}
|
||||
|
||||
static void SetupTimer1()
|
||||
{
|
||||
// Enable Timer 1
|
||||
RCC->APB2PRSTR |= RCC_APB2Periph_TIM1;
|
||||
RCC->APB2PRSTR &= ~RCC_APB2Periph_TIM1;
|
||||
|
||||
TIM1->PSC = 0x0000; // Prescalar to 0x0000 (so, 48MHz base clock)
|
||||
TIM1->ATRLR = PWM_PERIOD;
|
||||
|
||||
#ifdef PWM_OUTPUT
|
||||
GPIOC->CFGLR &= ~(0xf<<(4*4));
|
||||
GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP_AF)<<(4*4);
|
||||
|
||||
TIM1->CCER = TIM_CC4E | TIM_CC4P;
|
||||
TIM1->CHCTLR2 = TIM_OC4M_2 | TIM_OC4M_1;
|
||||
TIM1->CH4CVR = 5; // Actual duty cycle (Off to begin with)
|
||||
#endif
|
||||
|
||||
// Setup TRGO for ADC. This makes is to the ADC will trigger on timer
|
||||
// reset, so we trigger at the same position every time relative to the
|
||||
// FET turning on.
|
||||
TIM1->CTLR2 = TIM_MMS_1;
|
||||
|
||||
// Enable TIM1 outputs
|
||||
TIM1->BDTR = TIM_MOE;
|
||||
TIM1->CTLR1 = TIM_CEN;
|
||||
}
|
||||
|
||||
|
||||
void InnerLoop() __attribute__((noreturn));
|
||||
|
||||
|
||||
void InnerLoop()
|
||||
{
|
||||
int i = 0;
|
||||
int q = 0;
|
||||
int tpl = 0;
|
||||
int Q = TQ;
|
||||
|
||||
// Timer goes backwards when we are moving forwards.
|
||||
volatile uint16_t * adc_buffer_end = 0;
|
||||
volatile uint16_t * adc_buffer_top = adc_buffer + ADC_BUFFSIZE;
|
||||
volatile uint16_t * adc = adc_buffer;
|
||||
|
||||
int frcnt = 0;
|
||||
|
||||
int tstart = 0;
|
||||
|
||||
#ifdef DUMPBUFF
|
||||
uint16_t shadowbuff[Q+16];
|
||||
int shadowplace = 0;
|
||||
#define SHADOWSTORE(X) shadowbuff[frcnt+X] = t;
|
||||
#else
|
||||
#define SHADOWSTORE(X)
|
||||
#endif
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
tpl = ADC_BUFFSIZE - DMA1_Channel1->CNTR; // Warning, sometimes this is == to the base, or == 0 (i.e. might be 256, if top is 255)
|
||||
if( tpl == ADC_BUFFSIZE ) tpl = 0;
|
||||
|
||||
adc_buffer_end = adc_buffer + ( ( tpl / 4) * 4 );
|
||||
//printf( "%3d %4d %d %04x\n", DMA1_Channel1->CNTR, TIM1->CNT, ADC1->RDATAR, ADC1->STATR );
|
||||
while( adc != adc_buffer_end )
|
||||
{
|
||||
int32_t t = adc[0]; SHADOWSTORE(0);
|
||||
i += t; q += t;
|
||||
t = adc[1]; SHADOWSTORE(1);
|
||||
i -= t; q += t;
|
||||
t = adc[2]; SHADOWSTORE(2);
|
||||
i -= t; q -= t;
|
||||
t = adc[3]; SHADOWSTORE(3);
|
||||
i += t; q -= t;
|
||||
adc += 4;
|
||||
frcnt += 4;
|
||||
|
||||
if( adc == adc_buffer_top ) adc = adc_buffer;
|
||||
if( frcnt >= Q ) break;
|
||||
}
|
||||
|
||||
|
||||
if( frcnt >= Q )
|
||||
{
|
||||
|
||||
int ti = i>>3;
|
||||
int tq = q>>3;
|
||||
int is = (ti*ti + tq*tq)>>8;
|
||||
|
||||
int s = 1<<( ( 32 - __builtin_clz(is) )/2);
|
||||
s = (s + is/s)/2;
|
||||
|
||||
//int tv = (i>>PWM_OUTPUT) + (PWM_PERIOD/2);
|
||||
//if( tv < 0 ) tv = 0;
|
||||
//if( tv >= PWM_PERIOD ) tv = PWM_PERIOD-1;
|
||||
//TIM1->CH4CVR = tv;
|
||||
|
||||
//printf( "%d\n", s );
|
||||
frcnt = 0;
|
||||
i = 0;
|
||||
q = 0;
|
||||
tpl = ADC_BUFFSIZE - DMA1_Channel1->CNTR;
|
||||
adc = adc_buffer + ( ( tpl / 4) * 4 );
|
||||
tstart = SysTick->CNT;
|
||||
}
|
||||
/*
|
||||
Delay_Us( 100 );
|
||||
int end = DMA1_Channel1->CNTR;
|
||||
int v0 = adc_buffer[0];
|
||||
int v1 = adc_buffer[1];
|
||||
int v2 = adc_buffer[2];
|
||||
int v3 = adc_buffer[3];
|
||||
printf( "%d %d %d %d %d\n", (uint8_t)(start-end), v0, v1, v2, v3 );
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// REQUIRES External 24MHz oscillator
|
||||
printf( "Initializing\n" );
|
||||
|
||||
SystemInit();
|
||||
|
||||
Delay_Ms(10);
|
||||
|
||||
printf( "System On\n" );
|
||||
|
||||
// Enable Peripherals
|
||||
RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC |
|
||||
RCC_APB2Periph_GPIOA | RCC_APB2Periph_TIM1 | RCC_APB2Periph_ADC1 |
|
||||
RCC_APB2Periph_AFIO;
|
||||
|
||||
RCC->APB1PCENR = RCC_APB1Periph_TIM2;
|
||||
|
||||
// Disable HSI
|
||||
RCC->CTLR &= ~(RCC_HSION);
|
||||
|
||||
printf( "CTLR: %08lx CFGR0: %08lx\n", RCC->CTLR, RCC->CFGR0 );
|
||||
|
||||
SetupADC();
|
||||
|
||||
while(1)
|
||||
printf( "ADC Setup\n" );
|
||||
|
||||
#if 0
|
||||
EXTEN->EXTEN_CTR |= EXTEN_OPA_EN; // turn on the op-amp
|
||||
EXTEN->EXTEN_CTR |= EXTEN_OPA_PSEL; // select op-amp pos pin: 0 = PA2, 1 = PD7
|
||||
EXTEN->EXTEN_CTR |= EXTEN_OPA_NSEL; // select op-amp neg pin: 0 = PA1, 1 = PD0
|
||||
#endif
|
||||
|
||||
// SetupTimer1();
|
||||
printf( "Timer 1 setup\n" );
|
||||
InnerLoop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void usb_handle_user_in_request( struct usb_endpoint * e, uint8_t * scratchpad, int endp, uint32_t sendtok, struct rv003usb_internal * ist )
|
||||
{
|
||||
// Make sure we only deal with control messages. Like get/set feature reports.
|
||||
if( endp )
|
||||
{
|
||||
usb_send_empty( sendtok );
|
||||
}
|
||||
}
|
||||
|
||||
void usb_handle_user_data( struct usb_endpoint * e, int current_endpoint, uint8_t * data, int len, struct rv003usb_internal * ist )
|
||||
{
|
||||
if( outready )
|
||||
{
|
||||
// Send NACK (can't accept any more data right now)
|
||||
usb_send_data( 0, 0, 2, 0x5A );
|
||||
return;
|
||||
}
|
||||
|
||||
usb_send_data( 0, 0, 2, 0xD2 ); // Send ACK
|
||||
int offset = e->count<<3;
|
||||
int torx = e->max_len - offset;
|
||||
if( torx > len ) torx = len;
|
||||
if( torx > 0 )
|
||||
{
|
||||
memcpy( scratchout + offset, data, torx );
|
||||
e->count++;
|
||||
if( ( e->count << 3 ) >= e->max_len )
|
||||
{
|
||||
outready = e->max_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void usb_handle_hid_get_report_start( struct usb_endpoint * e, int reqLen, uint32_t lValueLSBIndexMSB )
|
||||
{
|
||||
if( reqLen > sizeof( scratchin ) ) reqLen = sizeof( scratchin );
|
||||
|
||||
// You can check the lValueLSBIndexMSB word to decide what you want to do here
|
||||
// But, whatever you point this at will be returned back to the host PC where
|
||||
// it calls hid_get_feature_report.
|
||||
//
|
||||
// Please note, that on some systems, for this to work, your return length must
|
||||
// match the length defined in HID_REPORT_COUNT, in your HID report, in usb_config.h
|
||||
|
||||
if( reqLen > inready ) inready = inready;
|
||||
e->opaque = scratchin;
|
||||
e->max_len = reqLen;
|
||||
}
|
||||
|
||||
void usb_handle_hid_set_report_start( struct usb_endpoint * e, int reqLen, uint32_t lValueLSBIndexMSB )
|
||||
{
|
||||
// Here is where you get an alert when the host PC calls hid_send_feature_report.
|
||||
//
|
||||
// You can handle the appropriate message here. Please note that in this
|
||||
// example, the data is chunked into groups-of-8-bytes.
|
||||
//
|
||||
// Note that you may need to make this match HID_REPORT_COUNT, in your HID
|
||||
// report, in usb_config.h
|
||||
|
||||
if( outready ) reqLen = 0;
|
||||
if( reqLen > sizeof( scratchout ) ) reqLen = sizeof( scratchout );
|
||||
e->opaque = scratchout;
|
||||
e->max_len = reqLen;
|
||||
}
|
||||
|
||||
|
||||
void usb_handle_other_control_message( struct usb_endpoint * e, struct usb_urb * s, struct rv003usb_internal * ist )
|
||||
{
|
||||
LogUEvent( SysTick->CNT, s->wRequestTypeLSBRequestMSB, s->lValueLSBIndexMSB, s->wLength );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _FUNCONFIG_H
|
||||
#define _FUNCONFIG_H
|
||||
|
||||
#define FUNCONF_USE_DEBUGPRINTF 1
|
||||
#define FUNCONF_USE_UARTPRINTF 0
|
||||
#define FUNCONF_USE_HSE 1
|
||||
#define FUNCONF_SYSTICK_USE_HCLK 1
|
||||
|
||||
#endif
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,155 @@
|
||||
#ifndef _USB_CONFIG_H
|
||||
#define _USB_CONFIG_H
|
||||
|
||||
//Defines the number of endpoints for this device. (Always add one for EP0). For two EPs, this should be 3.
|
||||
#define ENDPOINTS 2
|
||||
|
||||
#define USB_PORT D // [A,C,D] GPIO Port to use with D+, D- and DPU
|
||||
#define USB_PIN_DP 3 // [0-4] GPIO Number for USB D+ Pin
|
||||
#define USB_PIN_DM 4 // [0-4] GPIO Number for USB D- Pin
|
||||
#define USB_PIN_DPU 5 // [0-7] GPIO for feeding the 1.5k Pull-Up on USB D- Pin; Comment out if not used / tied to 3V3!
|
||||
|
||||
#define RV003USB_DEBUG_TIMING 0
|
||||
#define RV003USB_OPTIMIZE_FLASH 1
|
||||
#define RV003USB_EVENT_DEBUGGING 0
|
||||
#define RV003USB_HANDLE_IN_REQUEST 1
|
||||
#define RV003USB_OTHER_CONTROL 0
|
||||
#define RV003USB_HANDLE_USER_DATA 1
|
||||
#define RV003USB_HID_FEATURES 1
|
||||
#define RV003USB_USER_DATA_HANDLES_TOKEN 1
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
#include <tinyusb_hid.h>
|
||||
|
||||
#ifdef INSTANCE_DESCRIPTORS
|
||||
|
||||
//Taken from http://www.usbmadesimple.co.uk/ums_ms_desc_dev.htm
|
||||
static const uint8_t device_descriptor[] = {
|
||||
18, //Length
|
||||
1, //Type (Device)
|
||||
0x10, 0x01, //Spec
|
||||
0x0, //Device Class
|
||||
0x0, //Device Subclass
|
||||
0x0, //Device Protocol (000 = use config descriptor)
|
||||
0x08, //Max packet size for EP0 (This has to be 8 because of the USB Low-Speed Standard)
|
||||
0xcd, 0xab, //ID Vendor
|
||||
0x11, 0x11, //ID Product
|
||||
0x02, 0x00, //ID Rev
|
||||
1, //Manufacturer string
|
||||
2, //Product string
|
||||
3, //Serial string
|
||||
1, //Max number of configurations
|
||||
};
|
||||
|
||||
static const uint8_t special_hid_desc[] = {
|
||||
HID_USAGE_PAGE ( 0xff ), // Vendor-defined page.
|
||||
HID_USAGE ( 0x00 ),
|
||||
HID_REPORT_SIZE ( 8 ),
|
||||
HID_COLLECTION ( HID_COLLECTION_LOGICAL ),
|
||||
HID_REPORT_COUNT ( 255 ), // IN
|
||||
HID_REPORT_ID ( 0xa4 )
|
||||
HID_USAGE ( 0x01 ),
|
||||
HID_FEATURE ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,
|
||||
HID_REPORT_COUNT_N ( 256, 2 ), // OUT
|
||||
HID_REPORT_ID ( 0xad )
|
||||
HID_USAGE ( 0x01 ),
|
||||
HID_COLLECTION_END,
|
||||
};
|
||||
|
||||
static const uint8_t config_descriptor[] = {
|
||||
// configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
|
||||
9, // bLength;
|
||||
2, // bDescriptorType;
|
||||
0x22, 0x00, // wTotalLength
|
||||
|
||||
//34, 0x00, //for just the one descriptor
|
||||
|
||||
0x01, // bNumInterfaces (Normally 1)
|
||||
0x01, // bConfigurationValue
|
||||
0x00, // iConfiguration
|
||||
0x80, // bmAttributes (was 0xa0)
|
||||
0x64, // bMaxPower (200mA)
|
||||
|
||||
//Class FF device.
|
||||
9, // bLength
|
||||
4, // bDescriptorType
|
||||
0, // bInterfaceNumber = 1 instead of 0 -- well make it second.
|
||||
0, // bAlternateSetting
|
||||
1, // bNumEndpoints
|
||||
0x03, // bInterfaceClass (0x03 = HID)
|
||||
0x00, // bInterfaceSubClass
|
||||
0xff, // bInterfaceProtocol (1 = Keyboard, 2 = Mouse)
|
||||
0, // iInterface
|
||||
|
||||
9, // bLength
|
||||
0x21, // bDescriptorType (HID)
|
||||
0x10,0x01, // bcd 1.1
|
||||
0x00, //country code
|
||||
0x01, // Num descriptors
|
||||
0x22, // DescriptorType[0] (HID)
|
||||
sizeof(special_hid_desc), 0x00,
|
||||
|
||||
7, // endpoint descriptor (For endpoint 1)
|
||||
0x05, // Endpoint Descriptor (Must be 5)
|
||||
0x81, // Endpoint Address
|
||||
0x03, // Attributes
|
||||
0x01, 0x00, // Size (We aren't using it)
|
||||
100, // Interval (We don't use it.)
|
||||
};
|
||||
|
||||
#define STR_MANUFACTURER u"CNLohr"
|
||||
#define STR_PRODUCT u"RV003 RVSWDIO Programmer"
|
||||
#define STR_SERIAL u"RVSWDIO003-01"
|
||||
|
||||
struct usb_string_descriptor_struct {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wString[];
|
||||
};
|
||||
const static struct usb_string_descriptor_struct string0 __attribute__((section(".rodata"))) = {
|
||||
4,
|
||||
3,
|
||||
{0x0409}
|
||||
};
|
||||
const static struct usb_string_descriptor_struct string1 __attribute__((section(".rodata"))) = {
|
||||
sizeof(STR_MANUFACTURER),
|
||||
3,
|
||||
STR_MANUFACTURER
|
||||
};
|
||||
const static struct usb_string_descriptor_struct string2 __attribute__((section(".rodata"))) = {
|
||||
sizeof(STR_PRODUCT),
|
||||
3,
|
||||
STR_PRODUCT
|
||||
};
|
||||
const static struct usb_string_descriptor_struct string3 __attribute__((section(".rodata"))) = {
|
||||
sizeof(STR_SERIAL),
|
||||
3,
|
||||
STR_SERIAL
|
||||
};
|
||||
|
||||
// This table defines which descriptor data is sent for each specific
|
||||
// request from the host (in wValue and wIndex).
|
||||
const static struct descriptor_list_struct {
|
||||
uint32_t lIndexValue;
|
||||
const uint8_t *addr;
|
||||
uint8_t length;
|
||||
} descriptor_list[] = {
|
||||
{0x00000100, device_descriptor, sizeof(device_descriptor)},
|
||||
{0x00000200, config_descriptor, sizeof(config_descriptor)},
|
||||
// interface number // 2200 for hid descriptors.
|
||||
{0x00002200, special_hid_desc, sizeof(special_hid_desc)},
|
||||
{0x00002100, config_descriptor + 18, 9 }, // Not sure why, this seems to be useful for Windows + Android.
|
||||
|
||||
{0x00000300, (const uint8_t *)&string0, 4},
|
||||
{0x04090301, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
|
||||
{0x04090302, (const uint8_t *)&string2, sizeof(STR_PRODUCT)},
|
||||
{0x04090303, (const uint8_t *)&string3, sizeof(STR_SERIAL)}
|
||||
};
|
||||
#define DESCRIPTOR_LIST_ENTRIES ((sizeof(descriptor_list))/(sizeof(struct descriptor_list_struct)) )
|
||||
|
||||
#endif // INSTANCE_DESCRIPTORS
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+1
-1
Submodule ch32v/ch32v003fun updated: ad9e5744d9...f41db0dc30
@@ -2,6 +2,7 @@ all : flash
|
||||
|
||||
TARGET:=loratest
|
||||
TARGET_MCU:=CH32V203
|
||||
TARGET_MCU_PACKAGE:=C8
|
||||
CH32V003FUN:=../ch32v003fun/ch32v003fun
|
||||
|
||||
EXTRA_ELF_DEPENDENCIES:=chirpbuff.h
|
||||
@@ -1,48 +1,6 @@
|
||||
/**
|
||||
|
||||
MIT-like-non-ai-license
|
||||
|
||||
Copyright (c) 2024 Charles Lohr "CNLohr"
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the two following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
In addition the following restrictions apply:
|
||||
|
||||
1. The Software and any modifications made to it may not be used for the
|
||||
purpose of training or improving machine learning algorithms, including but not
|
||||
limited to artificial intelligence, natural language processing, or data
|
||||
mining. This condition applies to any derivatives, modifications, or updates
|
||||
based on the Software code. Any usage of the Software in an AI-training dataset
|
||||
is considered a breach of this License.
|
||||
|
||||
2. The Software may not be included in any dataset used for training or
|
||||
improving machine learning algorithms, including but not limited to artificial
|
||||
intelligence, natural language processing, or data mining.
|
||||
|
||||
|
||||
3. Any person or organization found to be in violation of these restrictions
|
||||
will be subject to legal action and may be held liable for any damages
|
||||
resulting from such use.
|
||||
|
||||
If any term is unenforcable, other terms remain in-force.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
**/
|
||||
// This file is under the standard MIT license, CC0 or Public domain. you choose.
|
||||
// CNLohr <>< 2024
|
||||
// It just does a normal PWM output from a ch32v203
|
||||
|
||||
#include "ch32v003fun.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# The "calculator" tools
|
||||
|
||||
Including the host side code for the ch32v203 goertzel tuner.
|
||||
|
||||
The font used, AudioLink is from https://audiolink.dev/ by Llealloo and are "(PUBLIC DOMAIN / free to use)" (as of 6/22/2024)
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<!-- This file is under the regular MIT license.
|
||||
|
||||
Copyright 2024 Charles Lohr (cnlohr)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<LINK rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
/* This file is under the regular MIT license.
|
||||
|
||||
Copyright 2024 Charles Lohr (cnlohr)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
const expectedProductName = "CNLohr lolra ch32v203 goertzel test";
|
||||
const filter = { vendorId : 0x1209, productId : 0xd035 };
|
||||
let dev = null;
|
||||
|
||||
Reference in New Issue
Block a user