Need help getting started with MCF51JU32VFM microcontroller. - Page 1
Forum section: electronics / general

author: Dukov Ahzrukhal
author_rank: Regular Contributor
timestamp: October 09, 2019, 02:09:23 am
content: Hello everyone, I recently got a tiny MCF51JU32VFM microcontroller that I want to use for my future projects. Unfortunately I havent been able to figure out how to do even the most basic things with it. I have only used PIC and AVR microcontrollers before, and I always program them in assembly. This is my first time trying to use C for a microcontroller and apparently I picked the wrong chip to start with. Could anyone help me figure out how to configure and control the GPIO pins and have a delay function? right now I simply want to write a blinky program. It may sound silly but just having that as an example will get me a long way. I am already familiar with C and C++, just not for microcontrollers.Any help would be highly appreciated.

author: Jeroen3
author_rank: Super Contributor
timestamp: October 09, 2019, 05:47:11 am
content: Looks like you need an IDE for the Coldfire V1 CPU.Then you need a programmer compatible with the IDE and the Freescale part.Looks like you can work with CodeWarrior and an UMultilink. ($395.00 + $200)Unfortunately, this isn't as accessible as ST's ecosystem with free tools and cheap development boards with debugger includes.

author: mfro
author_rank: Regular Contributor
timestamp: October 09, 2019, 06:10:02 am
content: The MCF51JU32VFM is a ColdFire series chip.Although I do not have experience with this particular chip (only with ColdFire V4), I think it should be fully supported by GNU tools (binutils + gcc + gdb). Its probably not easy to find a readily compiled toolchain for this chip, but building binutils and gcc as cross compiler yourself is easy and straightforward.If you are of decent age, it will help a lot if you have experience with Atari's and Amiga's you can dig out - these chips are very similar to popular m68k chips.

author: ebclr
author_rank: Super Contributor
timestamp: October 09, 2019, 06:20:16 am
content: This may helpshttp://www.pemicro.com/support/download_processor.cfm?type=1

author: amyk
author_rank: Super Contributor
timestamp: October 09, 2019, 11:43:12 am
content: You can program any MCU in Asm. Just read through the documentation and configure the peripherals you need:http://cache.freescale.com/files/32bit/doc/ref_manual/MCF51JU128RM.pdfhttps://www.nxp.com/docs/en/data-sheet/MCF51JU128.pdf

author: Dukov Ahzrukhal
author_rank: Regular Contributor
timestamp: October 09, 2019, 04:15:27 pm
content: I have downloaded CodeWarrior and created a project already. This microcontroller has a thing called EzPort, which as far as I can tell is just an SPI interface. Since I dont want to buy an expensive programmer I was planing on using an arduino to program this MCU. What I cant figure out is how to have delay loops in C. Also for the GPIO I'm just declaring pointers and assigning them with the correct register addresses, but I'm sure there is a better way to do this.I wouldn't mind using assembly, but this is a fairly powerful microcontroller and the tasks I need to do are very simple so I dont need to worry about optimizing things. I think it makes sense to use C.

author: Jeroen3
author_rank: Super Contributor
timestamp: October 09, 2019, 05:16:22 pm
content: Using assembly and making your own programmer? So much effort... Is there anyhing specific you require that other more common parts don't suffice?

author: Dukov Ahzrukhal
author_rank: Regular Contributor
timestamp: October 09, 2019, 07:10:53 pm
content: My current project is simple, I simply need to emulate a tape drive for a TRS80. I could use any other microcontroller for that, the reason why I'm trying to use this one is simply because I already have it and I want the experience of using something other than PIC or AVR. I know using this part will make my life harder than it needs to be, but I'm just trying to learn so the harder the better.

author: Dukov Ahzrukhal
author_rank: Regular Contributor
timestamp: October 09, 2019, 09:24:04 pm
content: Ok, I think I figured out the IO part, but I still haven't been able to figure out the delays. Am I supposed to use the time for all delays?I wrote some code with what I have s far, but before I start messing around with making my own programmer for the chip can someone please read my code and tell me if it has any chance of working? At least it compiles...

author: mariush
author_rank: Super Contributor
timestamp: October 09, 2019, 09:52:26 pm
content: I know it doesn't help, but if you're in the mood to learn something new, why not try something with an ARM core, or maybe something 8051 based ... for example seeSilicon Labs Busy Bee and Gecko series(ARM Cortex M0, M4, 8051) ... STM32F0, F4, the PsoC chips?What's the point of using an obscure chip that you may not be able to source easily and you don't have a cheap IDE, is there anything really special about it to be worth investing time in it?

author: pgo
author_rank: Regular Contributor
timestamp: October 10, 2019, 12:00:37 am
content: Hi,Development for the JU32 can be done with "Codewarrior for MCUs". Aspecial editioncan be obtained from NXP (Freescale originally)https://www.nxp.com/design/software/development-software/codewarrior-development-tools/downloads:CW_DOWNLOADSA cheap debugging/programming interface is USBDMhttp://usbdm.sourceforge.net/USBDM_V4.12/html/index.htmlHardware for the latter is available cheaply on ebay.bye

author: amyk
author_rank: Super Contributor
timestamp: October 10, 2019, 02:46:36 am
content: Quote from: Dukov Ahzrukhal on October 09, 2019, 04:15:27 pmOn the contrary, the benefits of a HLL like C only show up when you need to do more computationally intensive tasks; if you're just poking at a peripheral, then Asm will work just as well and may even be shorter.

author: Jeroen3
author_rank: Super Contributor
timestamp: October 10, 2019, 05:35:12 am
content: Quote from: Dukov Ahzrukhal on October 09, 2019, 09:24:04 pmThey way arduino millis and delay is implemented is using a timer for a system tick. So I suggest using a timer.On ARM people use the systick or an timer on the AHB (from the vendor).Arduino uses Timer 0.However, if you need microsecond resolution inline delays there are other ways. Such as self-tuning soft delay loops.

author: mfro
author_rank: Regular Contributor
timestamp: October 10, 2019, 03:30:24 pm
content: Quote from: Dukov Ahzrukhal on October 09, 2019, 09:24:04 pmYour delay loop might work, but that is not the best way to do it. Your chip has multiple timers. At least one of them can be configured as free running counter (see the reference manual Ch. 36.4.4.3http://cache.freescale.com/files/32bit/doc/ref_manual/MCF51JU128RM.pdf). Program the timer to a certain frequency and then just save the current value and have your code observe the counter in a loop (busy wait). Once the difference of saved and observed value reaches the value you need as a wait time, do whatever you want to do after the delay.You could also have the FlexTimer generate an interrupt after a certain time, but that might be too much considering you are just starting.

author: Dukov Ahzrukhal
author_rank: Regular Contributor
timestamp: October 11, 2019, 06:11:06 pm
content: I ordered a programmer for the MCU, I'll test my code when it arrives. In the meantime I'd like to learn more about using C to program MCUs. Would it be easier to start with a PIC MCU? Since using the MCF51JU32VFM turned out to be harder than I anticipated I will not use it for my current project. I'll keep playing around with it but for now I'll switch to using a PIC16C74B. Since I'm familiar with all the relevant IO registers already I should have no trouble getting the IO to work in C, but I'll need some carefully timed delay loops. The first thing I'll do is measure the length of a pulse (to decode data from a TRS80 tape). What would be a good way to do this? I'm using MPLABX, I can write my code in assembly and post it here if that helps anyone figure out exactly what I'm trying to do.

author: amyk
author_rank: Super Contributor
timestamp: October 12, 2019, 01:58:08 am
content: If you want cycle-exact timing, a compiler in any HLL won't ever give you that, because it's not very predictable the exact instructions it'll generate. HLLs are meant to be more abstract.

author: coppice
author_rank: Super Contributor
timestamp: October 12, 2019, 02:10:03 am
content: Quote from: amyk on October 12, 2019, 01:58:08 amThese days most processors don't have an exact cycle timing for most code, as things like cache and pipeline behaviour make the timing fluid. However, there was a time when some HLL compilers for simpler processors output the number of cycles for particular paths through the code. For example, I used to get cycle accurate timing information from the Intel PL/M86 compiler for the original 8086.

author: westfw
author_rank: Super Contributor
timestamp: October 12, 2019, 02:13:50 am
content: QuoteYour delay code looks "ok", assuming that an "int" is 32bits (which I believe is true of 68k derivatives including Coldfire v1.) If int is only 16bits, it will never reach 65536, and it will loop forever.If you're actually running at the documented clock rate of 50MHz, and blinking an LED, the blink rate is likely to be so fast that you can't notice (100Hz+) Try something like "50e6/10" (For a one-second blink, estimating 10 cycles for a typical "increment and loop.")

author: Dukov Ahzrukhal
author_rank: Regular Contributor
timestamp: October 28, 2019, 12:17:14 am
content: I got the cable to program the chip, but unfortunately I keep getting a message that says "Connection to the target has failed" I probed the reset and BKGD lines and they do change when I try to program the thing, so the cable seems to be working. Am I missing something or did I break the chip? I have pin 7 and pin 24 tied to +3.3V pins 8, 14, 25 tied to GND, EXTAL1 and EXTAL2 tied to a 20MHz oscillator, and pins 28 and 21 connected to the programming cable. Everything else is unconnected except for pin 16 which is connected to an LED through a 470 Ohm resistor. I get no signal out of XTAL1 and XTAL2.Using this chip is getting very frustrating