STM32F103C8T6 need help with drivers

Bootloader for boards that don't have the addition hardware found on the Maple mini, which resets the USB
petronel
Posts: 17
Joined: Mon Aug 22, 2016 12:21 pm

Re: STM32F103C8T6 need help with drivers

Postby petronel » Wed Nov 09, 2016 8:26 pm

Code: Select all

#define pinLED PC13

void setup() {
  Serial.begin(9600);
   Serial.println("start"); 
}

void loop() {
  digitalWrite(pinLED, HIGH);
  delay(500);
  digitalWrite(pinLED, LOW);
  Serial.println("Hello World2"); 
    delay(100);

}


This is the sketch I use.
Even that i use PC13, led doesn't blink..

When the sketch start, I can't see the msg from setup(). I have to move BOOT0 to LOW and reset.

Not sure why Led is not blinking.
I have a 1k5 resistor soldered between PA12 and 3.3 like wiki suggested, that might be a problem ?

stevestrong
Posts: 1014
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F103C8T6 need help with drivers

Postby stevestrong » Wed Nov 09, 2016 8:35 pm

Of course it doesn't blink, because you forgot to set the pin mode.

Insert to setup() the following line:

Code: Select all

pinMode(pinLED, OUTPUT);

petronel
Posts: 17
Joined: Mon Aug 22, 2016 12:21 pm

Re: STM32F103C8T6 need help with drivers

Postby petronel » Wed Nov 09, 2016 8:43 pm

:oops: forgot about that. THANKS !!!

Now i noticed that the F macro doesn't work

Code: Select all

Serial.println(F("test"));

If i remove the F() , then it works.
I'm trying to use https://github.com/miguelbalboa/rfid

Added

Code: Select all

#define F(x) x

User avatar
RogerClark
Posts: 5611
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: STM32F103C8T6 need help with drivers

Postby RogerClark » Wed Nov 09, 2016 9:01 pm

Umm

I'm not sure why the F macro doesnt work any more.

But I agree its now crashing if I try to use it


Actually, the F macro is not needed for ARM dev at all, and should be removed wherever possible

Looks like F is defined in WString.h

Code: Select all

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))


Looks like its in the Arduino SAM Wstring as well

https://github.com/arduino/Arduino/blob ... /WString.h

petronel
Posts: 17
Joined: Mon Aug 22, 2016 12:21 pm

Re: STM32F103C8T6 need help with drivers

Postby petronel » Wed Nov 09, 2016 9:19 pm

Removing all the F() from that RFID library might be a pain.

Code: Select all

#define F(x) x
seems to do the job..

but the code seems to stop at

Code: Select all

mfrc522.PCD_DumpVersionToSerial();

maybe something to do with the SPI .. ?

Code: Select all

SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));


Anyone had success using MFRC522 with the STM32?

stevestrong
Posts: 1014
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: STM32F103C8T6 need help with drivers

Postby stevestrong » Wed Nov 09, 2016 9:39 pm

And where do you set the chip select CS pin for the SPI?

Code: Select all

SPI.beginTransaction(CHIP_SEL, SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));

petronel
Posts: 17
Joined: Mon Aug 22, 2016 12:21 pm

Re: STM32F103C8T6 need help with drivers

Postby petronel » Wed Nov 09, 2016 10:09 pm

In my sketch i have

Code: Select all

#define RST_PIN         PA0          // Configurable, see typical pin layout above
#define SS_PIN         PA1          // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance


Constructor is

Code: Select all

MFRC522::MFRC522(   byte chipSelectPin,      ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low)
               byte resetPowerDownPin   ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low)
            ) {
   _chipSelectPin = chipSelectPin;
   _resetPowerDownPin = resetPowerDownPin;
} // End constructor


Init is:

Code: Select all

void MFRC522::PCD_Init() {
   // Set the chipSelectPin as digital output, do not select the slave yet
   pinMode(_chipSelectPin, OUTPUT);
   digitalWrite(_chipSelectPin, HIGH);
   
   // Set the resetPowerDownPin as digital output, do not reset or power down.
   pinMode(_resetPowerDownPin, OUTPUT);
   
   if (digitalRead(_resetPowerDownPin) == LOW) {   //The MFRC522 chip is in power down mode.
      digitalWrite(_resetPowerDownPin, HIGH);      // Exit power down mode. This triggers a hard reset.
      // Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74μs. Let us be generous: 50ms.
      delay(50);
   }
   else { // Perform a soft reset
      PCD_Reset();
   }
   
   // When communicating with a PICC we need a timeout if something goes wrong.
   // f_timer = 13.56 MHz / (2*TPreScaler+1) where TPreScaler = [TPrescaler_Hi:TPrescaler_Lo].
   // TPrescaler_Hi are the four low bits in TModeReg. TPrescaler_Lo is TPrescalerReg.
   PCD_WriteRegister(TModeReg, 0x80);         // TAuto=1; timer starts automatically at the end of the transmission in all communication modes at all speeds
   PCD_WriteRegister(TPrescalerReg, 0xA9);      // TPreScaler = TModeReg[3..0]:TPrescalerReg, ie 0x0A9 = 169 => f_timer=40kHz, ie a timer period of 25μs.
   PCD_WriteRegister(TReloadRegH, 0x03);      // Reload timer with 0x3E8 = 1000, ie 25ms before timeout.
   PCD_WriteRegister(TReloadRegL, 0xE8);
   
   PCD_WriteRegister(TxASKReg, 0x40);      // Default 0x00. Force a 100 % ASK modulation independent of the ModGsPReg register setting
   PCD_WriteRegister(ModeReg, 0x3D);      // Default 0x3F. Set the preset value for the CRC coprocessor for the CalcCRC command to 0x6363 (ISO 14443-3 part 6.2.4)
   PCD_AntennaOn();                  // Enable the antenna driver pins TX1 and TX2 (they were disabled by the reset)
} // End PCD_Init()


All code is at https://github.com/miguelbalboa/rfid/
Not sure how to tell to use SPI1 or SPI2. My RFID is connected to PA5, PA6, PA7 with CS at PA1

petronel
Posts: 17
Joined: Mon Aug 22, 2016 12:21 pm

Re: STM32F103C8T6 need help with drivers

Postby petronel » Wed Nov 09, 2016 10:57 pm

I just had a "Doh!!" moment. :oops:

Found my problem with the bootloader:
I was using Flash Loader Demonstrator, and instead of "Download to device" I was using "Upload from device" , probably didn't read to / from.
So I've overwrite the generic_boot_pc13.bin with the one that was on device :roll:

Now i see the DFU I upload my sketch and after it reset I get a Maple Serial.

User avatar
RogerClark
Posts: 5611
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: STM32F103C8T6 need help with drivers

Postby RogerClark » Wed Nov 09, 2016 11:32 pm

:lol:

I agree. The terminology used is confusing.

petronel
Posts: 17
Joined: Mon Aug 22, 2016 12:21 pm

Re: STM32F103C8T6 need help with drivers

Postby petronel » Wed Nov 09, 2016 11:52 pm

Probably I was expecting Download from and Upload to .. it makes more sense to me.

I have 2 other questions now:

1. After a sketch is uploaded and the STM32 is resetting, the Serial connection drop for a second, and I have to close/open the Serial Monitor. Is that normal ?

2. Uploading a sketch that compile ok but crash when running (like my test with RFID) make the DFU / com disappear and getting again "Unknown device". I can still reset the STM32 and upload an working sketch.


Return to “Generic bootloader”

Who is online

Users browsing this forum: No registered users and 1 guest