ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Cores are the underlying magic that make the Arduino API possible
dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by dannyf » Mon Jun 26, 2017 12:14 am

now interrupts() no longer generates the error
I got SDCC installed and used it to compile stm8sduino.c. didn't get any error, especially the critical error that you got. Just three warnings.

I used the latest SDCC for windows. 3.6.0 I think.

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by Kenjutsu » Mon Jun 26, 2017 12:57 pm

Thank you for the feedback.

Here is what I am using: I am using your simple blink.c example:

Code: Select all

#include "stm8sduino.h" //include stm8suduino defs

#define LED PB5 //LED attached to pin 13 (=PB5 on STM8Sblue)
#define LED_DLY 500 //waste some time, in ms

//user setup
void setup(void) {
 pinMode(LED, OUTPUT); //set LED as output
}

//user loop
void loop(void) {
 digitalWrite(LED, !digitalRead(LED)); //flip LED
 delay(LED_DLY); //waste some time
}
I also created the following simple Makefile:

Code: Select all

CC := sdcc
VERBOSE := --verbose
CFLAGS := -Ddouble=float -mstm8 -DSTM8S103 -DSDCC
INCLUDES := -I. -I/opt/sdcc/share/sdcc/include/ 
OBJS := blink.rel stm8sduino.rel

main: stm8sduino.rel blink.rel 
	$(CC) $(CFLAGS) $(INCLUDES) $(VERBOSE) -o main.ihx stm8sduino.rel blink.rel 
	
blink.rel: blink.c stm8sduino.h
	$(CC) $(CFLAGS) $(INCLUDES) -c blink.c
	
stm8sduino.rel: stm8sduino.c stm8sduino.h stm8s.h
	$(CC) $(CFLAGS) $(INCLUDES) -c stm8sduino.c

clean:
	rm -f *.asm *.ihx *.cdb *.lst *.map *.lk *.rel *.rst *.sym

flash:
	stm8flash -c stlinkv2 -p stm8s103f3 -w main.ihx
The first time I run make, without changing any of the STM8sduino files,I get the following error:

Code: Select all

stm8sduino.c:593: syntax error: token -> 'uint16_t' ; column 9
I then move the line to the beginning of serial1Begin() to fix the compile error.

Run make again, and get the "stm8sduino.c:249: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG" and "stm8sduino.c:249: warning 126: unreachable code" at function inline void digitalWrite(). I remove the inline keyword, and the next make gives the "stm8sduino.c:898: warning 116: left shifting more than size of object changed to zero" error in void mcu_init(void) at "TIM1->ARRL = (PWM_PR);" and "TIM2->ARRL = (PWM_PR);"

These warnings can be fixed with explicit casting, but then still "stm8sduino.c:1093: error 9: FATAL Compiler Internal Error in file '/Users/sdcc-builder/build/sdcc-build/orig/sdcc/src/SDCCicode.c' line number '1150' : isOperandLiteral (op)" remains. This error occurs in void mcu_init(void) at whatever the last line of code is.

In stm8sduino.h, the USE_XXX defines are as follows:

Code: Select all

//STM8Sduino module configuration
//comment out the follow macros to disable a hardware functionality
//default: use all
//Peripherals always used: GPIO, TIM4
#define USE_PWM1							//comment out if not used - pwm using tim1
#define USE_PWM2							//comment out if not used - pwm using tim2
#define USE_PWM3							//comment out if not used - pwm using tim3
#define USE_EXTI							//comment out if not used
#define USE_ADC1							//comment out if not used
//#define USE_ADC2							//comment out if not used - not present on all chips
#define USE_DAC								//comment out if not used
#define USE_SPI								//comment out if not used
#define USE_SPI								//comment out if not used
#define USE_I2C								//comment out if not used
#define USE_UART1							//comment out if not used - present on 003, 103, 207, 208
#define USE_UART2							//comment out if not used - present on 005, 105
//end STM8Sduino module configuration

//STM8Sduino hardware configuration
#define PWMOUT_BITs		12					//in bits. PWM output / analogWrite() resolution. 8-14 suggested -> default = 12bits
#define PWMOUT_PS		1					//3-bit PMWOUT prescaler. 0x00->1:1, ..., 0x07->128:1, for timer1/2/3
#define ADC1_PS			2					//3-bit ADC prescaler. 0x00->2:1, ...0x07 = 18:1
#define TIM4_PS			7					//tim4 (time base for micros() and millis()) 3-bit prescaler, valid values: [0..7]. 2^TIM4_PS, 128x max
#define SPI_PS			7					//3-bit SPI prescaler. [0..7]: 0->2:1, 7->256:1
//#define I2C_FASTMODE						//uncomment for standard mode (100Khz).
#define F_TONE			1000				//beep frequency, in Hz. 500 - 8000. 
//end STM8Sduino hardware configuration
I started commenting out each one, until the FATAL error went await. It seems the culprit is #define USE_I2C. Now, it does compile, but after flashing the firmware, the LED does not blink. It is, however, very dimly lit. Literally a needle point.
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by dannyf » Mon Jun 26, 2017 2:48 pm

Pb4 and pb5 are od pins and unable to source current. You can either sink current on those pins or move to a different pin.

User avatar
Kenjutsu
Posts: 134
Joined: Fri May 29, 2015 8:26 am

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by Kenjutsu » Tue Jun 27, 2017 7:41 am

dannyf wrote:
Mon Jun 26, 2017 2:48 pm
Pb4 and pb5 are od pins and unable to source current. You can either sink current on those pins or move to a different pin.
Using your initial release (version: v0.10) and IAR EMSTM8, everything compiles and the LED on PB5 is blinking. However, with the latest release and IAR EMSTM8, the LED on PB5 does not blink. I will connect a LED to another pin and try again ;)
Pieter

OSX: 10.12.6
Arduino IDE: 1.6.12
Blue pill STM32F103C8T6 Dev Board
Maple Mini Clones

dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by dannyf » Fri Jul 07, 2017 10:59 am

I just started porting the ARMduino to STM32F0xx - testing on a STM32F030F now. So far, the generics and GPIO are working and will fill in the rest later. Code is here: https://github.com/dannyf00/ARMduino/tr ... er/STM32F0

your comments / feedback are most welcome.

edit: I added analogRead(), attachInterrupts(), detachInterrupts() and uart-related routines. PWM coming up next.
Last edited by dannyf on Fri Jul 07, 2017 1:58 pm, edited 1 time in total.

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by ChrisMicro » Fri Jul 07, 2017 1:18 pm

That's a very short framework.
Probably an interval timer would be a good idea. With this many peripherals could be implemented in software ( as long there is no hardware driver ).

DanielEff did it here with PWM, Tone, analogWrite

dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by dannyf » Fri Jul 07, 2017 2:28 pm

that's fairly easy to do. i already have a set of routines that do that.

So now I have 17 "virtual timers" that you can set their periods independently and install handlers independently. I can add a few more but I guess that's more than one would need for 99% of the applications.

dannyf
Posts: 167
Joined: Wed May 11, 2016 4:29 pm

Re: ARMduino - a generic implementation of Arduino on ARM Cortex-M chips

Post by dannyf » Sat Jul 08, 2017 1:38 pm

I just came up to an interesting feature of the STM32F0: it has caliberated values for its temperature sensor (at 30C and 110C) and its internal voltage reference. Those values are measured at factory and stored in those devices.

They can obviously be used to more accurately measure analog values, including temperature or Vdda; and they can also be used as another form of UID - which STM32F0 has "undocumentedly", :)

Post Reply