Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino 2 "bare metal" startup...


Best Answer Sigma7, 26 May 2013 - 01:50 PM

ziggurat29,

 

I was trying to bootstrap myself by following the "recipe" from Geoffroy Brown's "Discovering the STM32 Microcontroller" (chapter 5) (which is written for the STM32F100.. but I compared datasheets and changed registers and values as appropriate (e.g., the RCC A[H|P]B#ENR bits are all different).  His "example" SEEMED to be complete (albeit in bits an pieces) in that it started from the STM being reset, deals with initiializing the RCC, GPIOs, and USART, and ends with characters being written to the USART.  But I'm learing that there are pieces not included in the sample code (for example, setting up the clocks in the RCC).  So I'll have, hopefully, some time this weekend to play around with the N2.. and I'll let you know (by way of a reply.. or more questions) how it's going.

 

Regards,

Tom

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 Sigma7

Sigma7

    Member

  • Members
  • PipPip
  • 15 posts

Posted 24 May 2013 - 08:13 PM

I have been working with Netduino Mini, Netduino 1 and Netduino Plus..  so I thought I'd try doing some Cortex-M3 "bare metal" programming on the Netduino 2 (N2).

 

I power-up the N2 with the pushbutton pushed, so the "STM32F2BOOTLOADER" gets invoked (and I'm able to upload/download files to flash with the STM DfuSe tool).  So far so good.

 

The GNU ARM toolchain I was using didn't support "-mcpu=cortex-m3 -mthumb."  So I grabbed the latest and greatest YAGARTO release.  Now things seem to build okay.

 

The binary file I download to flash (08000000) basically looks like:

 

0: 2000 e000

4: 0800 0021

 

20: <my program>

 

"My Program" basically does (all I'm trying to do is to print a character to the serial port (USART2)):

 

Enable USART2 in RCC_APB1ENR

Enable PIOA in RCC_AHB1ENR

 

for the USART2_TX pin (PIOA pin 2 Alternate Function 7)..

 

GPIOA_MODE(pin 2) = GPIO_MODE_AF

GPIOA_OSPEED(pin 2) = GPIO_SPEED_50MHz

GPIOA_OTYPE(pin 2) = GPIO_OTYPE_PUSHPULL

GPIOA_PUPDR(pin 2) = GPIO_PUPDR_NOPULL

GPIOA_AFRL(pin 2) = 7

 

the I setup the USART (USART2)

 

I set it up for 8-bits, no parity, 1 stop bit, no hardware flow control, and 38400 baud (which translates to DIV_Mantissa = 0x30 and DIV_Fraction = 0xd).  I enable the transmitter (CR1.TE) and receiver (CR1.RE).. then enable the USART itself (CR1.UE).

 

Then I just go into a loop, outputting a character as soon as the USART STATUS.TXE goes to 1.

 

I have one specific question, and one general one:

 

(1) When I look at the "Reset Sequence" in "The Definitive Guide to the ARM Cortex-M3" (pp. 44-46), it says that the reset vector should have its LSB set to 1 (for thumb).  Sounds reasonable, but I've seen many other reset examples that don't mention that at all.  Is "The Definative Guide" right on this?

 

(2) I know it's just pseudo-code, but does anything strike anyone as a glaring omission and/or mistake?

 

Thanks,

 

Tom

 

 



#2 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 24 May 2013 - 08:31 PM

it has to be set or it will be a quick trip to Abort land.

 

And by all means check that it is.  I was setting up building the firmware with Yagarto et al back around Dec/Jan.  Many times the linked output would NOT have this bit set.  This seemed to be particularly happen in the case of structs with function pointers to assembly functions (like interrupt vectors often are!).  I typically dealt with it my modding the source to explictly state that it was a thumb function.  If you care, you can find some deets in the wiki article I posted, or you can do as I did and wait for it to crash, and fix as you go.  At any rate, you may have a much better go of it than I did since you'll be in control of your source, and I imagine you'll mostly be doing C, and will only have a couple cases where you might be exposed.



#3 Sigma7

Sigma7

    Member

  • Members
  • PipPip
  • 15 posts

Posted 24 May 2013 - 08:49 PM

ziggurat29,

 

Thanks.  And yes, I checked that it IS set.

 

The reset vector points (ignoring the LSB) to a single C-function (within which, everthing's a branch).  I'm trying to crawl before walking.  But I'm missing somthing simple/fundamental.



#4 ziggurat29

ziggurat29

    Advanced Member

  • Members
  • PipPipPip
  • 244 posts

Posted 25 May 2013 - 01:08 PM

ziggurat29,

 

Thanks.  And yes, I checked that it IS set.

 

The reset vector points (ignoring the LSB) to a single C-function (within which, everthing's a branch).  I'm trying to crawl before walking.  But I'm missing somthing simple/fundamental.

 

Oh OK perhaps I mis-read something; are you having a problem?  I thought you were just asking about why some folks mention the bit, and others don't.  Otherwise it looks like you're well on your way to fame and fortune.



#5 Sigma7

Sigma7

    Member

  • Members
  • PipPip
  • 15 posts

Posted 26 May 2013 - 01:50 PM   Best Answer

ziggurat29,

 

I was trying to bootstrap myself by following the "recipe" from Geoffroy Brown's "Discovering the STM32 Microcontroller" (chapter 5) (which is written for the STM32F100.. but I compared datasheets and changed registers and values as appropriate (e.g., the RCC A[H|P]B#ENR bits are all different).  His "example" SEEMED to be complete (albeit in bits an pieces) in that it started from the STM being reset, deals with initiializing the RCC, GPIOs, and USART, and ends with characters being written to the USART.  But I'm learing that there are pieces not included in the sample code (for example, setting up the clocks in the RCC).  So I'll have, hopefully, some time this weekend to play around with the N2.. and I'll let you know (by way of a reply.. or more questions) how it's going.

 

Regards,

Tom






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.